Jump to content

[SOLVED] Simple if statement


me1000

Recommended Posts

so i had this working a few hours ago, and to my knowledge i havnt changed anything!

so why doesnt it work???  :'(

 

 

if ($cmd =="search" && $before == "" ) {
header( 'Location: http://www.site.com/3rd_ani_template/V2/template.php?type=html&page=search&before=yes&cmd=search&words='.$words.'&mode='.$mode.'&submit='.$submit ) ;
}else{
echo "it doesnt work";
}

 

the url when i goto that page is

 

so the if statement should see that "cmd = search" and that "before" is not defined, so it will redirect it to the same URL but defining the "before" variable in the URL.  therefore showing the search page, where it would not be shown before!

 

Thanks,

Link to comment
Share on other sites

nope, that didnt work.

 

its outputting the same thing as before...

 

assuming I got the code write, here is what i have now,

 

$before = trim($_GET['before']);

if ($cmd =="search" && (strlen($before) == 0) ) {
header( 'Location: http://www.site.com/3rd_ani_template/V2/template.php?type=html&page=search&before=yes&cmd=search&words='.$words.'&mode='.$mode.'&submit='.$submit ) ;
}else{
echo "still not working";
}

Link to comment
Share on other sites

Which is?

 

is $cmd being defined?

 

cmd should be defined in the redirect, but its the "before" that isnt being defined, at all,

 

the "else" is just there to tell me that one of the 2 conditions was not met.

 

this is the URL after the redirect,

 

http://www.site.com/3rd_ani_template/V2/template.php?cmd=search&words=Search+some+words&mode=normal&submit=Search

 

 

redarrow || is or, both statements need to be true for it to redirect, and why i do an or, it my browser goes into an redirect loop!

 

 

 

The code i used for you yesideez is as follows,

echo "cmd=".$cmd."<br />before=".$before."<br />words=".$words."<br />submit=".$submit."<br />";

 

for the URL

 

and I got this back,

 

cmd=

before=

words=

submit=

 

 

That doesnt make any since!

Link to comment
Share on other sites

<?php

if (($cmd =="search" )&&($before == "" )) {
header( 'Location: http://www.site.com/3rd_ani_template/V2/template.php?type=html&page=search&before=yes&cmd=search&words='.$words.'&mode='.$mode.'&submit='.$submit ) ;
}else{
echo "it doesnt work";
}
?>

 

Tell me it it works ok.

Link to comment
Share on other sites

<?php

if (($cmd =="search" )&&($before == "" )) {
header( 'Location: http://www.site.com/3rd_ani_template/V2/template.php?type=html&page=search&before=yes&cmd=search&words='.$words.'&mode='.$mode.'&submit='.$submit ) ;
}else{
echo "it doesnt work";
}
?>

 

Tell me it it works ok.

 

 

 

nope, that didnt work.

Link to comment
Share on other sites

You're trying to use your script as if register_globals was on. It's not. you need to get the variables, like I did in my example.

 

 

im almost positive it is, I had to tell my host to turn it on when i moved, I dont think they changed it...

 

 

However, I may know why it isnt on... ill check with my host!

Link to comment
Share on other sites

<?php

if (($_GET['cmd'] =="search" )&& strlen($before == 0 )) {
header( 'Location: http://www.site.com/3rd_ani_template/V2/template.php?type=html&page=search&before=yes&cmd=search&words='.$words.'&mode='.$mode.'&submit='.$submit ) ;
}else{
echo "it doesnt work";
}
?>

Link to comment
Share on other sites

When on, register_globals will inject your scripts with all sorts of variables, like request variables from HTML forms. This coupled with the fact that PHP doesn't require variable initialization means writing insecure code is that much easier. It was a difficult decision, but the PHP community decided to disable this directive by default. When on, people use variables yet really don't know for sure where they come from and can only assume. Internal variables that are defined in the script itself get mixed up with request data sent by users and disabling register_globals changes this.

 

 

link

http://uk.php.net/register_globals

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.