Welcome to WebmasterWorld Guest from 54.147.134.218

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

redirect not finding required link

picking default with no value

     
1:07 am on Mar 16, 2010 (gmt 0)

Senior Member

WebmasterWorld Senior Member 5+ Year Member

joined:June 2, 2006
posts:2112
votes: 2


I have redirect scripts like this:

$link="http://www.example.com/"; //this is if the variable is not found
if ($g == "link1") {$link = "http://www.example.com/";}
if ($g == "link2") {$link = "http://www.example.com/";}
if ($g == "link3") {$link = "http://www.example.com/";}

header("Location: $link");


Some are small, some are big.

I noticed that sometimes the right link does not get picket, so the end redirect is the default page without $g value (the top one).

Why would this happen?

Thanks
1:30 am on Mar 16, 2010 (gmt 0)

Junior Member

10+ Year Member

joined:July 30, 2004
posts:81
votes: 0


Could it be that an unexpected value of $g is being input?

Instead of the series of "if" statements, why not try

if () {}
else if () {}
...
else {something that would notify you of an unexpected value}
7:00 am on Mar 16, 2010 (gmt 0)

Senior Member

WebmasterWorld Senior Member 5+ Year Member

joined:June 2, 2006
posts:2112
votes: 2


Could it be that an unexpected value of $g is being input?


No.

I use proven link and get redirects onto two different locations: expected and unexpected.

Please note that the unexpected happens only occasionally, can't really measure it.

Thanks
7:47 am on Mar 16, 2010 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:Apr 24, 2005
posts:697
votes: 0


is the value for $g trimmed ? could it be due to some white space that ocassionaly is there in its value? just a guess
1:17 pm on Mar 16, 2010 (gmt 0)

Junior Member

10+ Year Member

joined:July 30, 2004
posts:81
votes: 0


You have to use the "if else" control structure in order to prove that things are working as expected, and to handle the unexpected.
2:04 pm on Mar 16, 2010 (gmt 0)

Administrator

WebmasterWorld Administrator jatar_k is a WebmasterWorld Top Contributor of All Time 10+ Year Member

joined:July 24, 2001
posts:15755
votes: 0


you could add a log to record values when the default case is hit
2:58 am on Mar 18, 2010 (gmt 0)

Senior Member

WebmasterWorld Senior Member 5+ Year Member

joined:June 2, 2006
posts:2112
votes: 2


Thanks.

I just experienced a few in a raw. I'm not sure if IE 8 could play a role here since it's PHP (server side).

Anyhow, then I changed the "empty" value from this:

$link="http://www.example.com/"; //this is if the variable is not found

to this form:

if ($g == "") {$link = "http://www.example.com/";}

As I could see it, it was still empty, but in more defined form.

It worked right after I applied this change.

Do you agree that the two versions of empty value differ?

Thanks
7:20 am on Mar 20, 2010 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:Apr 24, 2005
posts:697
votes: 0


Yep the two versions are different imho.

Your first version, which is


$link="http://www.example.com/"; //this is if the variable is not found
if ($g == "link1") {$link = "http://www.example.com/";}
if ($g == "link2") {$link = "http://www.example.com/";}
if ($g == "link3") {$link = "http://www.example.com/";}


allows for 4 different values, link1,link2,link3, and "everything else"

and your second code, allows for 5 different values

link1,link2,link3,empty, and "everything else".

Just an opinion on the question, not any explanation of whats going on :)
8:05 pm on Mar 20, 2010 (gmt 0)

Senior Member

WebmasterWorld Senior Member 5+ Year Member

joined:June 2, 2006
posts:2112
votes: 2


and your second code, allows for 5 different values

link1,link2,link3,empty, and "everything else".


Thanks.

Are you saying that

if ($g == "") {$link = "http://www.example.com/";}

is both "empty" and "everything else"?
6:06 am on Mar 22, 2010 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:Apr 24, 2005
posts:697
votes: 0


its like this

$link="http://www.example.com/"; //this is if the variable is not found
if ($g == "link1") {$link = "http://www.example.com/";}
if ($g == "link2") {$link = "http://www.example.com/";}
if ($g == "link3") {$link = "http://www.example.com/";}
if ($g == "") {$link = "http://www.example.com/";}


1st value, when g is "link1"
2nd value, when g is "link2"
3rd value, when g is "link3"
4th value, when g is ""
5th value, when g is niether of the above 4


if ($g == "") {$link = "http://www.example.com/";}

is only when empty but in that code the 5th value is not being taken care of. Thats why an elseif structure would be more suited cause it would take care of all the 5 possible values.

if(g is empty)
elseif(g is link1)
elseif(g is link2)
elseif(g is link3)
elseif(g is link4)
else(this else covers "everything else")

That way you wont have unexpected outputs, 1 of your 5 provided links will always be there.
 

Join The Conversation

Moderators and Top Contributors

Hot Threads This Week

Featured Threads

Free SEO Tools

Hire Expert Members