Hi everybody,
I have a big problem using cookies,
I have a script that I included it in every single page in my web site to set my cookie and check if my cookie was set or not in the user's PC. The problem is I have to use either POST or GET variable to make my script working.
The script works just fine, if the page that Im including my script into, have no forms inside, BUT if it has a form then all the form's variables will be useless.
I know it looks not clear, but please give it a try. It will works if you remove the include statement from Test.php (look down).
So, how can I make it works with the include statment?
Don't ask me to use Sessions because I want my cookie to stay at the user's PC even after he/she left my website.
Cookies.php (The script that set the cookie and test if it was set!)
----------------
<?
if (!isset($HTTP_POST_VARS[C]))
{
if (!isset($HTTP_COOKIE_VARS[TestCookie])) setcookie("TestCookie", "Test Data"
;
?>
<form name="CookieForm" action="<?=$PHP_SELF?>" method="POST">
<input type="hidden" name="C" value="1">
</form>
<script language="javascript"> document.CookieForm.submit(); </script>
<?
}
else
{
if (isset($HTTP_COOKIE_VARS[TestCookie])) echo "Cookie contents ($HTTP_COOKIE_VARS[TestCookie])";
else echo "Cookie was not set";
}
?>
Test.php
----------
<?
include("Cookies.php"
;
if ($HTTP_POST_VARS[ShowResults] != 'Yes')
{?>
<form name="TestForm" method="POST" action="<? echo "$_SERVER[PHP_SELF]"; ?>">
First Name: <input name="FirstName"> Last Name: <input name="LastName"> <input type="submit">
<input type="hidden" name="ShowResults" value="Yes">
</form>
<?} else echo "My Name is $HTTP_POST_VARS[FirstName] $HTTP_POST_VARS[LastName]";
?>
I have a big problem using cookies,
I have a script that I included it in every single page in my web site to set my cookie and check if my cookie was set or not in the user's PC. The problem is I have to use either POST or GET variable to make my script working.
The script works just fine, if the page that Im including my script into, have no forms inside, BUT if it has a form then all the form's variables will be useless.
I know it looks not clear, but please give it a try. It will works if you remove the include statement from Test.php (look down).
So, how can I make it works with the include statment?
Don't ask me to use Sessions because I want my cookie to stay at the user's PC even after he/she left my website.
Cookies.php (The script that set the cookie and test if it was set!)
----------------
<?
if (!isset($HTTP_POST_VARS[C]))
{
if (!isset($HTTP_COOKIE_VARS[TestCookie])) setcookie("TestCookie", "Test Data"
?>
<form name="CookieForm" action="<?=$PHP_SELF?>" method="POST">
<input type="hidden" name="C" value="1">
</form>
<script language="javascript"> document.CookieForm.submit(); </script>
<?
}
else
{
if (isset($HTTP_COOKIE_VARS[TestCookie])) echo "Cookie contents ($HTTP_COOKIE_VARS[TestCookie])";
else echo "Cookie was not set";
}
?>
Test.php
----------
<?
include("Cookies.php"
if ($HTTP_POST_VARS[ShowResults] != 'Yes')
{?>
<form name="TestForm" method="POST" action="<? echo "$_SERVER[PHP_SELF]"; ?>">
First Name: <input name="FirstName"> Last Name: <input name="LastName"> <input type="submit">
<input type="hidden" name="ShowResults" value="Yes">
</form>
<?} else echo "My Name is $HTTP_POST_VARS[FirstName] $HTTP_POST_VARS[LastName]";
?>