Hi there,
I want to check if the cookie is set or not, because as its mentioned in the manual:
so I have the following scenario:
In the index page I check if a cookie is set or not, if its not set, just set a new cookie and then redirect to a page called "TestCookie.php" to test the cookie if it was set successfully or not, but the problem is: Im always after testing the cookie it gave me that its not set, so where is the error in my scripts.
Common Pitfalls:
Cookies will not become visible until the next loading of a page that the cookie should be visible for.
Note: I noticed that if the index.php is in the same directory with TestCookie.php and Cookies.php it works fine, but if index.php is in an upper directory, it will not work! Is the problem with cookie's path? Although I set it "/" to be at the home directory to be viewable to all directories.
Here is my scripts:
Note that index.php at the root while (TestCookie.php and Cookies.php) in the "User" directory under the root.
index.php:
------------
<?
include("/Users/Cookies.php"
;
CheckCookie($HTTP_COOKIE_VARS[GuestSID]);
echo "Welcome";
?>
TestCookie.php:
-------------------
<?
$GuestSID = $HTTP_COOKIE_VARS[GuestSID];
if (!isset($GuestSID))
{
echo "Not Set";
}
else
{
Header ("Location: /index.php"
;
}
?>
Cookies.php:
---------------
<?
Function CheckCookie($cookieGuestSID)
{
if (!isset($cookieGuestSID))
{
SetNewCookie();
Header ("Location: /Users/TestCookie.php"
;
}
}
Function SetNewCookie()
{
$GuestSID = mt_rand();
setcookie ("GuestSID", $GuestSID,time()+900, "/", ".127.0.0.1", 0);
}
?>
Please Help ME.
I want to check if the cookie is set or not, because as its mentioned in the manual:
so I have the following scenario:
In the index page I check if a cookie is set or not, if its not set, just set a new cookie and then redirect to a page called "TestCookie.php" to test the cookie if it was set successfully or not, but the problem is: Im always after testing the cookie it gave me that its not set, so where is the error in my scripts.
Common Pitfalls:
Cookies will not become visible until the next loading of a page that the cookie should be visible for.
Note: I noticed that if the index.php is in the same directory with TestCookie.php and Cookies.php it works fine, but if index.php is in an upper directory, it will not work! Is the problem with cookie's path? Although I set it "/" to be at the home directory to be viewable to all directories.
Here is my scripts:
Note that index.php at the root while (TestCookie.php and Cookies.php) in the "User" directory under the root.
index.php:
------------
<?
include("/Users/Cookies.php"
CheckCookie($HTTP_COOKIE_VARS[GuestSID]);
echo "Welcome";
?>
TestCookie.php:
-------------------
<?
$GuestSID = $HTTP_COOKIE_VARS[GuestSID];
if (!isset($GuestSID))
{
echo "Not Set";
}
else
{
Header ("Location: /index.php"
}
?>
Cookies.php:
---------------
<?
Function CheckCookie($cookieGuestSID)
{
if (!isset($cookieGuestSID))
{
SetNewCookie();
Header ("Location: /Users/TestCookie.php"
}
}
Function SetNewCookie()
{
$GuestSID = mt_rand();
setcookie ("GuestSID", $GuestSID,time()+900, "/", ".127.0.0.1", 0);
}
?>
Please Help ME.