Jump to content

How to prevent direct accessing a particular page?


don11

Recommended Posts

Hello,

I  want to prevent this page from being directly accessed by all via just putting its address in the address bar:

http://www.mysite.com/page1/page2/signup.php

 

I want to allow to be accessed this page only via clicking on a link in a particular page like:

http://www.mysite.com/activate/index.php

 

Please help me.

 

 

 

You can either use the rather simple way, of redirecting the user from the page.

// Places after sessions, but before all the other code.
header("Location: ../index.php");
exit; // stop page execution

 

Else you can use .htaccess, to redirect user ;)

 

http://httpd.apache.org/docs/2.0/mod/mod_rewrite.html

If you want users just to click on a link on index page to access the sign up page you can simply do this:

 

Add a link to the index page. The link should be:  http://www.mysite.com/page1/page2/signup.php?do=activate

Then add this to the top of the sign up page:

if(!isset($_GET['do']))

{

//Redirect to index page

}

else

{

//show contents of page

 

}

header("Location: ../index.php");exit; 

Above code is redirecting even from index page.

 

Add a link to the index page. The link should be:  http://www.mysite.com/page1/page2/signup.php?do=activate


Then add this to the top of the sign up page: 
if(!isset($_GET['do']))
{
header("Location: ../index.php");
}
else
{
//show contents of page

}

This code is also redirecting even from index page.

 

just an idea...

 

index page

start sessions

create var1 random number 1

store var1 in sessions

create link using ?myvar=var1

 

2nd page

start sessioins

check to see if session var AND get var (1) are both set (2) both integers (3) equal each other -

if not redirect

else display page

header("Location: ../index.php");exit; 

Above code is redirecting even from index page.

 

Add a link to the index page. The link should be:  http://www.mysite.com/page1/page2/signup.php?do=activate



Then add this to the top of the sign up page: 
if(!isset($_GET['do']))
{
header("Location: ../index.php");
}
else
{
//show contents of page

}

This code is also redirecting even from index page.

 

The code should work. It is pretty simple and clear. May be there is any typo while you wrote the code. Just check it once again. :-)

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.