www.webdeveloper.com
Results 1 to 4 of 4

Thread: Redirect after php script executes

  1. #1
    Join Date
    Apr 2014
    Location
    Little Rock, AR
    Posts
    24

    Question Redirect after php script executes

    Hey all,

    Here's my scenario. User clicks on an Adobe Edge Animation which is only an image, which is coded with a javascript onclick event that calls a php file. The php file executes and does a post to a remote server then they need to be transferred to another page immediately after the script completes.

    I've been reading about redirects on php.net and my question is, would this code as the last line of my php file do it?

    PHP Code:
    // 307 Temporary Redirect
    header("Location: /wordpress-page",TRUE,307); 

  2. #2
    Join Date
    Apr 2014
    Location
    Little Rock, AR
    Posts
    24
    After reading more, I see my path must be like this:

    Location header MUST be absolute uri with scheme, domain, port, path, etc.

    PHP Code:
    goodheader("Location: http://www.example.com/something.php?a=1"); 
    But where do I place the code?

  3. #3
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    19,384
    The main thing is that there can have been no output (even white-space not within your <?php tags) before the call to header(). Also, if you're using sessions, I find it good to do session_write_close() before you "get out of Dodge". I'll also exit right after it, if there's any code following it that should not be executed. So...
    PHP Code:
    <?php
    // lots of amazing PHP stuff with no echo/print stuff
    session_write_close();
    header('Location: http://www.example.com/');
    exit;
    // rest of page...
    ?>
    "Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
    ~ Terry Pratchett in Nation

    eBookworm.us

  4. #4
    Join Date
    Apr 2014
    Location
    Little Rock, AR
    Posts
    24
    Thanks NogDog. Let's call this one closed.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

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



Recent Articles