Welcome Guest, Not a member yet? Register   Sign In
Random URL
#1

Hello,
I found that one of the best way to secure Website pages from unknown people is random URL.
For example:
http://domain.com/controller/page/1
to sth like:
http://domain.com/6456r43462344/2342345424

and change URL after each login.

How can I do this
Reply
#2

You can create the page content from a random query parameter. A very basci example could be a controller like

PHP Code:
<?php defined('BASEPATH') OR exit('No direct script access allowed');

class 
Random extends My_Controller
{

    public function 
__construct()
    {
        
parent::__construct();
    }

    public function 
index($page)
    {
        echo 
$page;
        
/* Here you have to write your code ... */
    
}



And this route

PHP Code:
$route['random/(:any)'] = 'random/index/$1'

Reply
#3

I can not understand how to do it!!
Reply
#4

Ok, again a very simple example. First you need the random link like the one in the following welcome controller

PHP Code:
<?php
defined
('BASEPATH') OR exit('No direct script access allowed');

class 
Welcome extends MY_Controller {

    function 
__construct()
    {
        
parent::__construct();
    }

    public function 
index()
    {
        
$this->load->helper('string');
        echo 
anchor('/random/'.random_string('numeric'16).'/'.random_string('numeric'16), 'MyRandomLink');
    }


Normaly you would echo this link inside your view but it should be only a simple e.g.

This link redirects you to a page called "random" with two paremeters that are random numeric strings, produced by the ci string helper (for details look inside the documentation). To handle this random links you have to make a route in your /application/config/routes.php

PHP Code:
$route['random/(:any)/(:any)'] = 'random/index/$1/$2'

Now you can catch this two random parameters and call the method for the random controller

PHP Code:
<?php
defined
('BASEPATH') OR exit('No direct script access allowed');

class 
Random extends MY_Controller {

    function 
__construct()
    {
        
parent::__construct();
    }

    public function 
index($param1$param2)
    {
        echo 
$param1." - ".$param2;
    }


With this kind of logic you can handle you're random stuff and your following logic.

Reply




Theme © iAndrew 2016 - Forum software by © MyBB