ochi Posted January 27, 2010 Share Posted January 27, 2010 hi! I want to forbide people write in the browser: www.mydomain.com/wathever.php The wathever.php is what I want be impossible, because in index.php I have a login/password system. I tried with $_SESSION['auth'] but, it's not possible, because it's just cleaned with "logout" bottom or closing the browser. Could you help me? thank you! Regards Quote Link to comment Share on other sites More sharing options...
jl5501 Posted January 27, 2010 Share Posted January 27, 2010 Can you explain your requirement a little Are you wanting to redirect people to a page if they are not logged in? Quote Link to comment Share on other sites More sharing options...
manwhoeatsrats Posted January 27, 2010 Share Posted January 27, 2010 Need a bit more detail.... just a guess... if someone is not logged in and they try to go directly to a page, then they would not have a session started. so possibly something like this at the top of your page <?php if (!isset($_SESSION['auth'])) { header("Location: notallowed.php"); } ?> Quote Link to comment Share on other sites More sharing options...
ochi Posted January 27, 2010 Author Share Posted January 27, 2010 Hi, what I want to do is follow the links in the site, starts in index.php and continue with the links, so, if index.php have a link to second.php I can't write www.localhost/second.php, it should redirect to index.php I tried, when the user login in index.php put a variable: $_SESSION['auth'] = true, and in every php file: <?php session_start(); if (!$_SESSION['auth'] == true){ header("Location:/index.php"); } ?> But it doesnt work fine, because I cant remove this variable if I would do it I wont be able to use the "go to the previous page" for example, I also tried different variables, but the problem stil appears. Another thing is as I never delete it, when I close the browser and open a new one, it's still there. Thank you! Regars Quote Link to comment Share on other sites More sharing options...
manwhoeatsrats Posted January 27, 2010 Share Posted January 27, 2010 I still don't quite understand what you are trying to do; however, looking at the code you provided. try changing the if (!$_SESSION['auth'] == true){ to if ($_SESSION['auth'] != true){ Quote Link to comment Share on other sites More sharing options...
taquitosensei Posted January 27, 2010 Share Posted January 27, 2010 or if(!$_SESSION['auth']) Quote Link to comment Share on other sites More sharing options...
ochi Posted January 27, 2010 Author Share Posted January 27, 2010 Hi! the problem isn't how to call this, it works also with: if(!isset($_SESSION['auth'])) the problem is: once I active this variable I had the problem with the page it allows! for example in index.php I put: if (autorized){ $_SESSION['auth'] } else { the page } and it have a link to: page2.php wich starts: if(!isset$_SESSION['auth']){ header("Location:/index.php"); } else { the page } If I close the mozilla and I forgot put logout button I can write : http://www.localhost/page2.php and I want it are not allowed. If page2.php starts: if(!isset$_SESSION['auth']){ unset($_SESSION['auth']); header("Location:/index.php"); } The previous problem is solved, but, now I cant refresh or use the "go to the previous page" in mozilla, because, I'll start again in index.php Do you understand me? thanks! regards Quote Link to comment Share on other sites More sharing options...
ochi Posted January 27, 2010 Author Share Posted January 27, 2010 Ok... I'm looking in the internet, and I think that I cant do what I want with an Apache option, I'm still looking at this, but I think there is a simplier way.. Thank you,! 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.