Hope someone can help me with this issue...

I added functionality to save a cookie to a user's computer so the site can recognize the user's computer before he or she logs in. Then a second program retrieves the cookie when the user types in a 4-digit PIN, verifies the cookie in relation with the PIN and allows the user to enter. If there is a problem, such as the cookie is not there, then the appropriate message should display.

The problem...

When there is no cookie installed on the user's computer, the application just takes him or her back to the login page but does not display the message. I am at a loss, as I display messages elsewhere with no problem. Perhaps you can help?

Here's the specs....

There are two pages:

* nda.php /* performs the action of the form */
* private_access.php /* contains the form */

The pertinent code on nda.php...

<?php

  include("private_access.php");
	
	$_COOKIE[name];

		if(isset($_COOKIE[name]))
		{
			$name = $_COOKIE[name];
		}
		else
		{
			$message = "<font color ='red'>Can't find the cookie. Hmm...</font><p><br>";
			include("private_access.php");
			exit();
		}

     /* next functionality should follow here if the cookie is found */

?>

The pertinent code on private_access.php...

<?php

            if (isset($message))                   
            echo "<b>$message <p> </b>";

?>

So what did I miss or screw up?

Thanks,

nixwave

I apologize for being a newbie. I just figured out about the wrap-code policy. Let me try again.

The pertinent code on nda.php...

<?php

include("private_access.php");

$_COOKIE[name];

if(isset($_COOKIE[name]))
{
$name = $_COOKIE[name];
}
else
{
$message = "<font color ='red'>Can't find the cookie. Hmm...</font><p><br>";
include("private_access.php");
exit();
}

/* next functionality should follow here if the cookie is found */

?>

The pertinent code on private_access.php...

<?php

if (isset($message)) 
echo "<b>$message <p> </b>";

?>

PoA,

I think I didn't make the important part of my post clear, 'cause you may have misunderstood. I want the program to be able to detect when the cookie is not on the user's computer. Therefore, if they do not have the cookie on their computer already from the page that set the cookie earlier, then even if they have the correct PIN, then they still won't be able to log in.

So, I'm still having the problem, but I did find one problem. On lines 5, 7 & 9 of the nda.php file, I forgot to include quotes around the cookie name. For instance, it should be:

$_COOKIE['name']

not...

$_COOKIE[name]

But anyway, it didn't change my results.

Anyone have any other ideas. Some things I have already checked was to make sure the cookie call was sent at the top of the page before anything at all. Also, I tried running the call as a function, using NULL if the cookie was not found.

Granted, I am new at the cookie functionality, but it seems as far as I can see that what I have is correct, but it's apparently not.

nixwave

This article has been dead for over six months. Start a new discussion instead.