March 14, 201016 yr Hi, I have a couple of pages that i do not want to be accessible unless the php directs them there, for example failed login, if the user enters an incorrect login detail it takes them to Scripts/fail.php however i dont want the user to be able to get Scripts/fail.php by simply typing it into the address bar. if they type www.example.com/Scripts/fail.php i want it to display a message that reads something like "this page is not available on the server" Is there a way to do this Cheers Craig
March 14, 201016 yr Hi Craig, You could do something like this in the top of your fail.php file: <?php if (empty($_SERVER['HTTP_REFERER'])) { header("HTTP/1.0 403 Forbidden"); exit; } ?> However, that will only check to make sure the user hasn't come directly to the script. If they link to it from elsewhere they can still access it, which you could get around by adding a strpos or something to the if() above. Hope that helps
March 14, 201016 yr Author Cheers for the reply mate, however this is just returning errors. i am very new to the php side of things so i may have put it in wrong?
March 14, 201016 yr Hi Craig, Cheers for the reply mate, however this is just returning errors. i am very new to the php side of things so i may have put it in wrong? Could you paste the errors here? Then I can help you debug them
March 14, 201016 yr Author Warning: Cannot modify header information - headers already sent by (output started at /home/fhlinux129/n/nextgensolutions.co.uk/user/htdocs/include/nav.php:55) in /home/fhlinux129/n/nextgensolutions.co.uk/user/htdocs/Scripts/activate.php on line 60 line 60 is Xhtml, Really appreciate your help!! Cheers Craig
March 14, 201016 yr Hi Craig, Warning: Cannot modify header information - headers already sent by (output started at /home/fhlinux129/n/nextgensolutions.co.uk/user/htdocs/include/nav.php:55) in /home/fhlinux129/n/nextgensolutions.co.uk/user/htdocs/Scripts/activate.php on line 60 line 60 is Xhtml, Really appreciate your help!! Cheers Craig Ah ok, the problem is that you need to make sure the code snippet I pasted above is the absolute first thing in your fail.php file. That error is basically telling you "Sorry! I've already sent stuff to the browser, so I can't change the headers now!"
March 15, 201016 yr Author thats awesome, it denys access, however it also doesnt allow me to access it if my login fails :| Cheers Craig
March 15, 201016 yr Hi Craig, thats awesome, it denys access, however it also doesnt allow me to access it if my login fails :| Hmm... try echoing $_SERVER['HTTP_REFERER'] instead of the code snippet I provided earlier to see what values it has in different circumstances. Hard to know without seeing exactly what you're doing now
Create an account or sign in to comment