#1
  1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2000
    Posts
    1
    Rep Power
    0
    I've looked thru all my books for this one...

    In perl, if I want to load a url after my script executes, I simply do
    > print "Location: http://www.thing nn";
    and lo, a new page pops up in the browser like it's supposed to.

    Now, I can get PHP to redirect immediately by using header(Location but I wish to load the url only upon successful completion of the script. Said script is embedded in html, so the headers have obviously already loaded and now it's time to display a *new* page if and only if the script's criteria are met.


    Help??
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 1999
    Posts
    114
    Rep Power
    16
    As I see it, you have two choices: a bad one and a good one.

    The bad one:
    Using <meta /> elements or JavaScript. This is a very weak solution and it depends on client-side support.

    The good one:
    Store all of your HTML output in a variable and don't echo() it until you're sure that you will not have to call header.

    -- Christopher
  4. #3
  5. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2000
    Posts
    1
    Rep Power
    0
    Brilliant...I totally didn't think of that. Here's what I did, for anyone interested:

    script.php: <?php
    if (!criteria met) {
    include('html1.html');
    }
    elseif (criteria met) {
    include('html2.html');
    }
    ?>

    That way, I avoid worrying about headers altoghther and can loop thru my criteria as many times as I need, including the proper files at the proper time. Not quite as elegant as I'd hoped, but it certainly works like a charm and doesn't rely on browsers and javascript. Thanks!!!
  6. #4
  7. Banned (not really)
    Devshed Supreme Being (6500+ posts)

    Join Date
    Dec 1999
    Location
    Brussels, Belgium
    Posts
    14,640
    Rep Power
    4476
    If you're not against using javascript, you can echo the following out wherever you want another page to load.

    echo "<script language=javascript>
    location.href='page2.php';
    </script>";

    You can do that after header is sent and as soon as the page gets to it, it loads the other page. You can echo a variable for the page, also.

    ---John Holmes...
  8. #5
  9. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2000
    Location
    Atlanta, GA
    Posts
    10
    Rep Power
    0

    This is the only thing about PHP I have found that I don't like. I hate the fact you cannot redirect somewhere in the middle of your code if you have already sent text or some other headers to the browser.

    You can do this in cold fusion, you can do this in ASP, why not PHP?
  10. #6
  11. Banned (not really)
    Devshed Supreme Being (6500+ posts)

    Join Date
    Dec 1999
    Location
    Brussels, Belgium
    Posts
    14,640
    Rep Power
    4476
    There is a way to "wrap" your code between two functions so that you can use header wherever you want. I can't find the names of the functions in the manual, though. Anyone know what I'm talking about?

    It'll allow you to do something like this:

    header_start();
    if (x==1)
    {
    print "x = 1";
    header("Location: <A HREF="http://www.x1.com");" TARGET=_blank>www.x1.com");</A>
    }
    else
    {
    print "x = ?";
    header("Location: <A HREF="http://www.?.com");" TARGET=_blank>www.?.com");</A>
    }
    header_end();

    This might help you out, if someone can remind me what the functions are...

    ---John Holmes...

    [This message has been edited by SepodatiCreations (edited November 13, 2000).]

Similar Threads

  1. redirect to another page
    By ivan447 in forum PHP Development
    Replies: 2
    Last Post: February 12th, 2004, 10:44 AM
  2. How to redirect to another page?
    By sdotsen in forum PHP Development
    Replies: 6
    Last Post: January 31st, 2004, 10:14 PM
  3. Header redirect function not working after host switch
    By Jhorra in forum PHP Development
    Replies: 5
    Last Post: January 26th, 2004, 10:28 AM
  4. redirect to private page
    By FlyingFinn in forum PHP Development
    Replies: 4
    Last Post: January 18th, 2004, 07:08 AM
  5. php redirect without using header?
    By mickeyren in forum PHP Development
    Replies: 4
    Last Post: January 14th, 2004, 07:00 PM

IMN logo majestic logo threadwatch logo seochat tools logo