Jump to content

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. :-)

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.