don11 Posted January 10, 2011 Share Posted January 10, 2011 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. Quote Link to comment Share on other sites More sharing options...
GrooN Posted January 10, 2011 Share Posted January 10, 2011 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 Quote Link to comment Share on other sites More sharing options...
don11 Posted January 10, 2011 Author Share Posted January 10, 2011 Thank you for quick reply. I have to put this <php>// Places after sessions, but before all the other code.header("Location: ../index.php");exit; // stop page execution</php> in http://www.mysite.com/page1/page2/signup.php ? Quote Link to comment Share on other sites More sharing options...
GrooN Posted January 10, 2011 Share Posted January 10, 2011 Yes, it'll redirect the user to index.php ^^ Quote Link to comment Share on other sites More sharing options...
Sandeepsmarty Posted January 10, 2011 Share Posted January 10, 2011 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 } Quote Link to comment Share on other sites More sharing options...
don11 Posted January 10, 2011 Author Share Posted January 10, 2011 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. Quote Link to comment Share on other sites More sharing options...
litebearer Posted January 10, 2011 Share Posted January 10, 2011 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 Quote Link to comment Share on other sites More sharing options...
Sandeepsmarty Posted January 10, 2011 Share Posted January 10, 2011 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. :-) Quote Link to comment Share on other sites More sharing options...
don11 Posted January 10, 2011 Author Share Posted January 10, 2011 ^Actually link of page that i want to prevent being open directly through address bar already have ? command like this: http://www.mysite.com/page1/page2/signup.php?fn=register So, what will be the code for above ? Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.