PHP - Isset不工作,逻辑是对的

Ok this is a really stupid one but something is definitely wrong.

I have a php script that needs to check for 2 variables ($token and $pid)

if(isset($token) && isset($pid)){
$ppurl = "https://api-3t.paypal.com/nvp";
$cURL = curl_init();
curl_setopt($cURL, CURLOPT_HEADER, false);
curl_setopt($cURL, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($cURL, CURLOPT_TIMEOUT, 5);
$GetExpressCheckoutDetails = $ppurl."?USER=".$apiuser."&PWD=".$apipwd."&SIGNATURE=".$apisig."&METHOD=GetExpressCheckoutDetails&VERSION=78&TOKEN=".$token;
curl_setopt($cURL, CURLOPT_URL, $GetExpressCheckoutDetails);
$info = parsePPResponse(curl_exec($cURL));
die (what);
}

Still, when I access the script directly without any variable it still runs that code.

The same way, if I add this before:

if(!isset($token)){ die(novar); }

It will still run the code and die with the message what .

This doesn't make any sense, anyone have a clue why this might be happenning ?

Based on your description, my best guess is that $pid was actually set and is just empty.

Before your if(isset($token) && isset($pid)){ run the following code:

print '<pre>';
print_r(get_defined_vars());
print '</pre>';

Then see if $pid or $token is present in the page output. If it is, you might need to change your condition to use the empty() function instead of isset().

Try to add var_dump($token) to make sure that the variable is really not set and that you are really editing the same file you think you are editing (happened to me)

!empty($token)

might work better