|
-
Apr 29th, 2007, 03:04 AM
#1
Thread Starter
Frenzied Member
'you will be redirected...' script
does anybody have a script that will let me display a 'you will be directed in 5 sec, as your login was unsuccesfull' kind of thing, i need some kind of delay / timer function ?
-
Apr 29th, 2007, 03:13 AM
#2
Re: 'you will be redirected...' script
PHP Code:
header('Refresh: 5; URL=http://example.com/mynewlocation');
Remember to include the http:// protocol and domain, as well as the page.
This is often used to get the user one step away from the POST request, so that they don't go back and accidentally submit things again. However, I dislike this method; partly because the delay is annoying (and often not long enough to read the text anyway), and partly because it doesn't really solve the problem: if you hit Back twice, you can still get to the expired POST request, which shouldn't be cached at all.
The superior solution is to silently redirect using a 303 code. This tells the browser that it must not cache the POST request. If the user then presses the Back button, they'll be taken back to the page where the form submission was made (in this case, the login screen).
PHP Code:
header('HTTP/1.1 303 See Other');
header('Location: http://example.com/mynewlocation');
For more information, see HTTP/1.1: Status Code Definitions.
-
Apr 29th, 2007, 04:10 AM
#3
Re: 'you will be redirected...' script
Leaving out the status modification will cause PHP to send a 302 status code. The browser should honour the redirection with the same HTTP method as the original request, but the majority (if not all) use a GET request.
If you want to force a POST redirection, send a 307 status. This will often cause the browser to generate a warning though as it could potentially be used to send form data to another site.
-
Apr 29th, 2007, 04:14 AM
#4
Re: 'you will be redirected...' script
I haven't tried 307 but 303 works fine and I use it with all of my forms.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|