Hi, I use this script to redirect the page to the previous page after user login. echo "<META HTTP-EQUIV=\"refresh\" content=\"1; URL=javascript:history.back(-1)\">"; PHP: But, sometimes it is not working properly, i mean the page is stop and show white blank page, and not back to the previous page. I want to ask: 1. why it is not working constantly? 2. should i give a redirect button to counter this problem at the mentioned page? Thanks for your help
Why not use php to send it back instead of doing a meta refresh... header("Location: " . $_SERVER['HTTP_REFERER']); PHP:
Thanks for your reply, why i did it like that, because i have to show some text to the user as notification if their login has succeed, about 1 or 2 second before it redirected to the previous page. but i did what you mention above for some other pages
Be careful with the code. Some browsers don't send a referer, and it's easily fakeable, allowing you to inject code (i.e. a newline then a new header). I would hardcode your login URL, far safer and guarantees 100% compatibility.
If the refresh is unreliable then a 'click here to continue' link or button would be a good option. You could also try using javascript do the redirect.
@jayshah: do you mean that <META HTTP-EQUIV=\"refresh\" this script is dangerous? please explain it further, i'm not too smart in programming. Gents, can some one give me a best code to solve my problem, i mean just like this forum, after your login succeed, you will redirected to the previous page... Thanks
you mentioned you are having problem sometimes not always... i guess this is the problem; history.back() won't work if you visited previous page with a form post method.. So, i guess may be sometimes you visits your previous page with a form post method thatz why history.back never works to go back to that page. hope it helps..
What if it took them two tries to log in? Your login page should record the URL that the user originally wanted to go to, and explicitly send them there when the login has succeeded.
@SmallPotatoes: that's what i want to do before, but the only thing that i know is use URL=javascript:history.back(-1) PHP: could you show me how to do that? it's hard to do for me because there are so many GET variables that shown on URL, this is for example : localhost/test123/nextPage.php?ctnt=News&loader=Main&levCat=srcNews&src=News&hal=1&ctry=103 PHP: That's why i use that javascript... I hope someone here could solve my problem here... Thanks
In theory you will find the original request, including all the GET args, in $_SERVER['REQUEST_URI'] - you can store that in a session variable while you are processing the login and then redirect the user to it once they're in.