SitePoint Sponsor

User Tag List

Results 1 to 8 of 8
  1. #1
    gimme the uuuuuuuuuuu duuudie's Avatar
    Join Date
    Feb 2004
    Location
    Switzerland
    Posts
    2,253
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Smile A basic question: I'm a bit lost when it comes to redirect.

    Hi,
    I have a form sent to a page. This page has a script that inserts the data in the db. Once done, I'd like to redirect the user to another page.
    In ASP I could use response.redirect. How could I do that in PHP?

    Thanks in advance.

  2. #2
    SitePoint Enthusiast sinatosk's Avatar
    Join Date
    Jul 2003
    Location
    PHP World
    Posts
    73
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    header('Location: http://www.url.com');

    or

    header('Refresh: 3;url=http://www.url.com');

    where it says 3. it waits 3 seconds before it redirects

    or

    echo '<meta http-equiv=\'refresh\' content=\'0; url=http://www.url.com\'>';
    exit();

    where it says 3. it waits 3 seconds before it redirects

  3. #3
    SitePoint Enthusiast
    Join Date
    Jan 2004
    Location
    sitepoint forums
    Posts
    81
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
    header("Location: http://site.com"); 

  4. #4
    ********* Callithumpian silver trophy freakysid's Avatar
    Join Date
    Jun 2000
    Location
    Sydney, Australia
    Posts
    3,798
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi

    You use:

    header('Location: http://www.domain.com/path/to/file.html');

    It is important to note that your script cannot produce any output before the call to header() which includes having any whitespace before the opening <?php tag.

    See www.php.net/header

  5. #5
    gimme the uuuuuuuuuuu duuudie's Avatar
    Join Date
    Feb 2004
    Location
    Switzerland
    Posts
    2,253
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    thanks a lot for your answers!

    what do you mean exactly by 'the script cannot produce any output'? That I couldn't echo something? Or include html tags?

  6. #6
    gimme the uuuuuuuuuuu duuudie's Avatar
    Join Date
    Feb 2004
    Location
    Switzerland
    Posts
    2,253
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    by the way... do I really need the http://www.domain.com/ part? Couldn't I just write the file name?

  7. #7
    ********* Callithumpian silver trophy freakysid's Avatar
    Join Date
    Jun 2000
    Location
    Sydney, Australia
    Posts
    3,798
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    From the manual:
    Note: HTTP/1.1 requires an absolute URI as argument to Location: including the scheme, hostname and absolute path, but some clients accept relative URIs. You can usually use $_SERVER['HTTP_HOST'], $_SERVER['PHP_SELF'] and dirname() to make an absolute URI from a relative one yourself:
    Your other question is also answered in the manual entry for header()

  8. #8
    gimme the uuuuuuuuuuu duuudie's Avatar
    Join Date
    Feb 2004
    Location
    Switzerland
    Posts
    2,253
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    thank you very much for your great help


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •