Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 09-29-2012, 01:08 PM   PM User | #1
vineet
Regular Coder

 
Join Date: Jun 2008
Posts: 173
Thanks: 2
Thanked 9 Times in 9 Posts
vineet is an unknown quantity at this point
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
vineet is offline   Reply With Quote
Old 09-29-2012, 04:38 PM   PM User | #2
sunfighter
Senior Coder

 
Join Date: Jan 2011
Location: Missouri
Posts: 2,498
Thanks: 18
Thanked 362 Times in 361 Posts
sunfighter is on a distinguished road
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
Quote:
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");
sunfighter is offline   Reply With Quote
Old 09-29-2012, 06:35 PM   PM User | #3
Fou-Lu
God Emperor


 
Fou-Lu's Avatar
 
Join Date: Sep 2002
Location: Saskatoon, Saskatchewan
Posts: 15,752
Thanks: 4
Thanked 2,468 Times in 2,437 Posts
Fou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to all
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]).
Fou-Lu is offline   Reply With Quote
Users who have thanked Fou-Lu for this post:
sunfighter (09-30-2012)
Old 09-30-2012, 07:04 AM   PM User | #4
vineet
Regular Coder

 
Join Date: Jun 2008
Posts: 173
Thanks: 2
Thanked 9 Times in 9 Posts
vineet is an unknown quantity at this point
thanks for the suggestions.

i will work accordingly

vineet
vineet is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 09:11 AM.


Advertisement
Log in to turn off these ads.