Jump to content

Archived

This topic is now archived and is closed to further replies.

foreverhex

question about an if() issue

Recommended Posts

Ok so have this script here is an example:
[code]
<?php
if($cmd == 'add' AND isset($user)) {
//content
} else {
//other
} ?>
[/code]

well no matter what I do it always acts as if $user is set. Any ideas.

Share this post


Link to post
Share on other sites
have you echo'd out $cmd and $user to see what values they hold?  and is your problem that your conditional always returns true or that $user is always set?  if $user appears to be always set and you have register_globals ON in your php.ini file, then any superglobal ($_GET/$_POST) that has a ['user'] element set will automagically be interpreted by $user.

Share this post


Link to post
Share on other sites
&& instead of AND?

Share this post


Link to post
Share on other sites
Another thing to watch out for is that even if a variable is assigned an empty value, it will still return true on isset()

Share this post


Link to post
Share on other sites
[quote author=xyph link=topic=102091.msg404727#msg404727 date=1154028725]
Another thing to watch out for is that even if a variable is assigned an empty value, it will still return true on isset()
[/quote]

Well it know that there isn't a $user set and the script works fine if I take out the isset($user) of the if() statement. Here is my accual code:
[code]
<?php
$cmd = $_GET['cmd'];

//check if loged in
if(isset($user)) {
$addlink = '<center><a href="2minhate.php?cmd=add">Add your own stuff</a></center>';
} else {
$addlink = '<center><a href="checkuser.php">Login to add your own stuff</a></center>';
}

//If page = 2minhate.php?cmd=add then show form

if(($cmd == 'add') && isset($user)) {
//this is where the form goes
} else {
//show page as normall
}
?>[code]


[/code][/code]

Share this post


Link to post
Share on other sites

×

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.