strlen() not working

Stumped on this one. I simply want to test the length of a string that comes from a cookie and then act on it based on the content of the first three characters.

the code

$thecookie = $_COOKIE["testRE"];
echo "<br>the cookie is = ", $thecookie;
if($thecookie = null) {$thecookie == "V85";}    #In case cookies are turned off
$testlenth = strlen($thecookie);
echo "<br> The test length is = " , $testlenth;
$cooklen = strlen($thecookie);
echo "<br>the cookie length is = ", $cooklen;
$strtest = substr($thecookie,0,3);

the output I am getting is

the cookie is = V853
The test length is = 0
the cookie length is = 0
the FIRST THREE CHARACTERS ARE =

I would have expected a test length of 4 and a cookie length of 4 and the first three characters to be = to V85 which I could then process as a certain class of visitor. Any ideas?

With your results it suggests the error is in the setting of the variable not in the strlen().

Try this:

    If (isset($_COOKIE['testRE']) { $thecookie = $_COOKIE['testRE']; } Else { $thecookie = 'V85'; }
    echo "<br>the cookie is = ", $thecookie;
    $testlenth = strlen($thecookie);
    echo "<br> The test length is = " , $testlenth;
    $cooklen = strlen($thecookie);
    echo "<br>the cookie length is = ", $cooklen;
    $strtest = substr($thecookie,0,3);

There was also an error in this line:
if($thecookie = null) {$thecookie == “V85”;} #In case cookies are turned off

Using = in statements:

Single = means you are setting a variable
Double (==) means you are comparing, however my code above makes your whole thing easier.

:o
If it were a snake, I would be dead. Thank you so much for helping me through this learning process.

Sponsor our Newsletter | Privacy Policy | Terms of Service