Results 1 to 4 of 4

Thread: 'you will be redirected...' script

Hybrid View

  1. #1

    Thread Starter
    Frenzied Member Jmacp's Avatar
    Join Date
    Jul 2003
    Location
    UK
    Posts
    1,959

    '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 ?

  2. #2
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    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.

  3. #3
    VBA Nutter visualAd's Avatar
    Join Date
    Apr 2002
    Location
    Ickenham, UK
    Posts
    4,906

    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.
    PHP || MySql || Apache || Get Firefox || OpenOffice.org || Click || Slap ILMV || 1337 c0d || GotoMyPc For FREE! Part 1, Part 2

    | PHP Session --> Database Handler * Custom Error Handler * Installing PHP * HTML Form Handler * PHP 5 OOP * Using XML * Ajax * Xslt | VB6 Winsock - HTTP POST / GET * Winsock - HTTP File Upload

    Latest quote: crptcblade - VB6 executables can't be decompiled, only disassembled. And the disassembled code is even less useful than I am.

    Random VisualAd: Blog - Latest Post: When the Internet becomes Electricity!!


    Spread happiness and joy. Rate good posts.

  4. #4
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    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
  •  



Click Here to Expand Forum to Full Width