PHP question

Get answers here.

Moderators: BBear, theunknownhost, flaguy

Post Reply
User avatar
Sapphyre
Official Test Penquin
Posts: 3337
Joined: Tue Nov 19, 2002 2:50 am
Location: Canada

PHP question

Post by Sapphyre » Mon Oct 15, 2007 3:09 pm

Code: Select all

@header("location: $gotolink");
@header("Content-type: text/plain");
@header("Content-Length: $gotosize");
@header("Connection: close");
die("<a href=\"$gotolink\">Add to Cart</a>");


Am I correct here in interpreting this code that the 'die' is only used as a fallback? Is the @header stuff a redirect and it should stop there? And if the browser does not do it, then it does the 'die' instead?

My client and her customer are seeing the 'Add to Cart' link, while I am being redirected automatically to the desired $gotolink. I suspect it is something in their browser setting that is causing this difference ?

m2
Hard Drive Crasher
Posts: 767
Joined: Sun Nov 21, 2004 2:19 pm
Location: Lexington, KY

Post by m2 » Mon Oct 15, 2007 3:57 pm

That's how I read it. If the first statement works, the browser redirects and this script loses control.

m2

User avatar
Sapphyre
Official Test Penquin
Posts: 3337
Joined: Tue Nov 19, 2002 2:50 am
Location: Canada

Post by Sapphyre » Mon Oct 15, 2007 5:48 pm

Great, thanks for corroborating my suspicion.

All products get manipulated thru the above code, yet the customer is getting redirected okay with other products, so it's the way her browser is handling (or rather NOT handling) the redirect crafted for this one product.

Do you have prior knopwledge of any gotchas to watch for w/r to sending headers - content length calculation is wrong perhaps? or a certain character in the URL can cause problems?

User avatar
Sapphyre
Official Test Penquin
Posts: 3337
Joined: Tue Nov 19, 2002 2:50 am
Location: Canada

You figure it out

Post by Sapphyre » Mon Oct 15, 2007 6:06 pm

Okay,
I think I got it. Can you solve it too? I discovered that I also get the 'Add to Cart' link for any option other than the first. So it is not a browser issue. Choosing the first option redirects as desired. Choosing any of the other options causing the fallback method to be deployed.

This is the code for this product's problematic select; the option chosen gets included as part of the URL ... can you spot the problem?

Code: Select all

<select size="1" name="optval1"><option value="Bib, Burp and Bear:0.00:">Bib, Burp and Bear $37.95</option><option value="
Blanket and Bib:10.00:">
Blanket and Bib $47.95</option><option value="
Blanket, Bib, Burp:20.00:">
Blanket, Bib, Burp $57.95</option><option value="
Blanket, Bib, Burp and Cap:30.00:">
Blanket, Bib, Burp and Cap $67.95</option><option value="
Blanket, Bib, Burp, Cap and Doll:45.00:">
Blanket, Bib, Burp, Cap and Doll $82.95</option></select>

User avatar
BBear
Hosting Superstar
Posts: 1915
Joined: Sat Jun 29, 2002 5:18 pm
Location: Connecticut

Post by BBear » Mon Oct 15, 2007 6:26 pm

Are these lines wrapped in the actual code, or just here in the example? if they are wrapped in the code, the only difference I see is that only the first option has it's complete value on one line. All the others are broken lines in the middle of the values.

Just a thought

User avatar
Sapphyre
Official Test Penquin
Posts: 3337
Joined: Tue Nov 19, 2002 2:50 am
Location: Canada

Post by Sapphyre » Mon Oct 15, 2007 6:56 pm

BINGO!
That is the way they come out in the code after having been entered like that in the DB.

It's the difference between

red~blue~green

red~
blue~
green

which is the way the end-user entered them in the admin area to enhance clarity. But the programmer did not account for that possibility by removing linebreaks after splitting the values up via the ~ delimiter.

SO, we have learned that location headers choke on line breaks.

m2
Hard Drive Crasher
Posts: 767
Joined: Sun Nov 21, 2004 2:19 pm
Location: Lexington, KY

Post by m2 » Mon Oct 15, 2007 7:13 pm

I think any header will choke on a \n or a \r; doesn't a line break terminate a header?

BlueWater
Nothing better to do.
Posts: 210
Joined: Tue Oct 09, 2007 8:45 pm
Location: Washington, DC
Contact:

Post by BlueWater » Wed Oct 17, 2007 3:35 pm

Recommend you use the PHP function 'headers_sent()' if you have any questions about that information is actually being sent through the headers.

PHP5 has a nicer function called 'headers_list()', with gives the headers and their values in an array.

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest