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!

Hidding GET variable

Status
Not open for further replies.

alsaffar

Programmer
Oct 25, 2001
165
KW
Hi there,

Im setting a cookie in a page and then refresh the page to test if the cookie was set or not and Im using a GET variable to acomplish my mission of testing if the cookie was set or not.

My script:

<?
if (!isset($HTTP_GET_VARS[C]))
{
setcookie(&quot;TestCookie&quot;, &quot;Test&quot;);
Header(&quot;Location: $PHP_SELF?C=1&quot;);
}
else
{
if (isset($HTTP_COOKIE_VARS[TestCookie]))
{
echo &quot;Cookie is set $HTTP_COOKIE_VARS[TestCookie]&quot;;
}
else
{
echo &quot;Cookie was not set&quot;;
}
}
?>

My question is:

I just want to set a GET variable but I want it to be hidden to the page's viewers, can I? Because it (GET variable) looks ugly in the URL, and one more thing, if the user delete the GET variable from the URL and hit enter, the cookie will be recreated!

So, I want to get rid of the GET variable?

I apreciate your kind help :)
 
You already have the answer in your code...

<?php
if (isset($HTTP_COOKIE_VARS[TestCookie]))
{
echo &quot;Cookie is set $HTTP_COOKIE_VARS[TestCookie]&quot;;
}
else
{
setcookie(&quot;TestCookie&quot;, &quot;Test&quot;);
}
?>
 
Sorry,

But this way you cant retrieve the cookie value because you cant retrieve the cookie value until the next page, so I refresh the page to test the cookie settings. And in my mind I cant find an another way than using the GET variable, so is there a better idea, cause as I said I dont like the look of the GET variables.
 
If you're setting the cookie, why can't you get it, you obviouslly know the value because you just set it.

And even if what you said was a problem then just put your

Header(&quot;Location: $PHP_SELF?C=1&quot;);

Line in after the setcookie line.

-Rob
 
Ofcourse I know whats the content of the cookie, the secret behind my test is to test if the was accepted from the user or not, this is why.

And the header line is already after the setcookie line!!!

My question to be clear, can I make the GET varibale hidden? Or can I get rid of them and my script get working.

I built my script based on the User contributed notes of setcookie manual.
 
There'd be some convoluted ways, but then you'd have to assume they're allowing client side scripting. I think the easiest way would be to just use two pages.

Maybe there's something else, but I don't know it.

(The client side scripting method would be to make a form which POSTS instead of GETS and submit it onloading the page.)
-Rob
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top