Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Testing Cookie Problem

Status
Not open for further replies.

alsaffar

Programmer
Oct 25, 2001
165
KW
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(&quot;TestCookie&quot;, &quot;Test Data&quot;);
?>
<form name=&quot;CookieForm&quot; action=&quot;<?=$PHP_SELF?>&quot; method=&quot;POST&quot;>
<input type=&quot;hidden&quot; name=&quot;C&quot; value=&quot;1&quot;>
</form>
<script language=&quot;javascript&quot;> document.CookieForm.submit(); </script>
<?
}
else
{
if (isset($HTTP_COOKIE_VARS[TestCookie])) echo &quot;Cookie contents ($HTTP_COOKIE_VARS[TestCookie])&quot;;
else echo &quot;Cookie was not set&quot;;
}
?>

Test.php
----------
<?
include(&quot;Cookies.php&quot;);
if ($HTTP_POST_VARS[ShowResults] != 'Yes')
{?>
<form name=&quot;TestForm&quot; method=&quot;POST&quot; action=&quot;<? echo &quot;$_SERVER[PHP_SELF]&quot;; ?>&quot;>
First Name: <input name=&quot;FirstName&quot;> Last Name: <input name=&quot;LastName&quot;> <input type=&quot;submit&quot;>
<input type=&quot;hidden&quot; name=&quot;ShowResults&quot; value=&quot;Yes&quot;>
</form>
<?} else echo &quot;My Name is $HTTP_POST_VARS[FirstName] $HTTP_POST_VARS[LastName]&quot;;
?>
 
Please help me guys,

Let me 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)?

PLEASE HELP ME.
 
if your inputs are hidden and say POSTed then you should still be able to retrieve them.
try adding

print_r($_POST);

this should show you all POST variables sent to the page. ______________________________________________________________________
There's no present like the time, they say. - Henry's Cat.
 
Just try to trace the code, or install it on your system, the POST variable in Test.php will not be shown because when the page reloaded, there is at the top another form in Cookies.php with hidden input and a javascript that will automatically reload the page one more time,

So, the POST variables from first form will be lost. My question how can I get these lost POST variables?
 
where is the hidded input passed to when the java reloads the page ? pass any and all info at this point and the $_POST array should have all you need. ______________________________________________________________________
There's no present like the time, they say. - Henry's Cat.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top