Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    Regular Coder
    Join Date
    Jun 2008
    Posts
    173
    Thanks
    2
    Thanked 9 Times in 9 Posts

    why only one function is performed

    hi all

    If shipping_option is not selected then i want to redirect the user to shipping page and show a alert box.

    If i comment header() code then alert() code works.
    If i comment alert() code then header() code works.

    but i want to make both functions to perform together.

    PHP Code:
    if($shiping_option == NULL)
    {
    header("Location:".$domain."/shipping/");
    echo(
    "<SCRIPT LANGUAGE='JavaScript'>
    alert('Select Shipping')
    </SCRIPT>"
    );
    ?> 
    vineet

  • #2
    Senior Coder
    Join Date
    Jan 2011
    Location
    Missouri
    Posts
    4,316
    Thanks
    23
    Thanked 613 Times in 612 Posts
    If the redirect works the browser stops executing script and goes to the other page so what comes after it does not execute.

    Given this
    i want to redirect the user to shipping page and show a alert box.
    Put the alert box on the shipping page. If you need to use an if statement on it, send the if trigger as a GET in the url.

    header("Location:".$domain."/shipping?show=yes");

  • #3
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,994
    Thanks
    4
    Thanked 2,662 Times in 2,631 Posts
    Quote Originally Posted by sunfighter View Post
    If the redirect works the browser stops executing script and goes to the other page so what comes after it does not execute.

    Given this Put the alert box on the shipping page. If you need to use an if statement on it, send the if trigger as a GET in the url.

    header("Location:".$domain."/shipping?show=yes");
    This is correct, but has a slight ambiguity in interpretation. Calling a header location asks your browser to move its location to another. The code following the header call will still execute per normal, but by using a Location header the browser itself will not render the returned HTML code, instead if follows the location to the new page.
    So code wise, calling header(Location) will not stop the script from continuing. The script will continue until it finished and then send the headers and results to the client, where the client then detects the location and follows it instead of rendering. For this reason, header location is usually followed by an exit or die call, since more often than not the remaining process isn't required (but not always).

    So yep, the HTML and JS in use needs to be provided by the page that the client will end up on. Using the querystring, a cookie or sessions are the best way, but will determine if the JS is constructed by the PHP (where you can use sessions), or simply by a hard coded JS (in which you should use the QS or possibly cookies [which I'd suggest you avoid overall]).

  • Users who have thanked Fou-Lu for this post:

    sunfighter (09-30-2012)

  • #4
    Regular Coder
    Join Date
    Jun 2008
    Posts
    173
    Thanks
    2
    Thanked 9 Times in 9 Posts
    thanks for the suggestions.

    i will work accordingly

    vineet


  •  

    Posting Permissions

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