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]";
?>
Testing Cookie Problem
Moderator: General Moderators
-
bionicdonkey
- Forum Contributor
- Posts: 132
- Joined: Fri Jan 31, 2003 2:28 am
- Location: Sydney, Australia
- Contact:
Thanx 4 helping me guys,
But the problem is not in $_POST or $HTTP_POST_VARS, I will state my problem in points:
1. If I have a form (A) in (T.php) page
2. I hit the submit button in form (A)
3. The action of form (A) was the same page (T.php)
4. At the top of this page (T.php) was another form (B) with only hidden inputs
5. There was a javascript that execute the submit button automatically for form (B)
6. The action of form (B) was the same page also (T.php)
7. How can I refere back to the POST variables in form (A) after the automatic execution of form (B)?
I hope its clear now
PLEASE HELP ME GUYS, IM STUCKED.
But the problem is not in $_POST or $HTTP_POST_VARS, I will state my problem in points:
1. If I have a form (A) in (T.php) page
2. I hit the submit button in form (A)
3. The action of form (A) was the same page (T.php)
4. At the top of this page (T.php) was another form (B) with only hidden inputs
5. There was a javascript that execute the submit button automatically for form (B)
6. The action of form (B) was the same page also (T.php)
7. How can I refere back to the POST variables in form (A) after the automatic execution of form (B)?
I hope its clear now
PLEASE HELP ME GUYS, IM STUCKED.