Forum Moderators: coopster

Message Too Old, No Replies

saving 'QUERY_STRING' to a cookie and insert...

         

rebeat

10:32 am on Nov 1, 2004 (gmt 0)

10+ Year Member



Hi, What i want to do is store a query as a cookie so i can insert that captured query value (from cookie) into any page on my site... the linking format i wish to use is: /index.php?xyz -or- /index.php?refer=xyz (where xyz is stored as cookie).

The stored cookie value (ie: xyz) can then be placed anywhere within the site via a php include... similar to the 'QUERY_STRING' method (see below) but obviously calling the cookie (NOT $_SERVER).

example:

<form action="https://www.paypal.com/cgi-bin/webscr" method="post">
<input type="hidden" name="item_name" value="<?php echo $_SERVER['QUERY_STRING'];?></">
<input type="hidden" name="item_number" value="1001">
<input border="0" name="submit" alt="Make payments with PayPal">
</form>

or

<a href=http://anysite.com/query=<?php echo $_SERVER['QUERY_STRING'];?>/index.html>special query derived link</a>

Cheers, Wayne.

[edited by: jatar_k at 7:05 pm (utc) on Nov. 1, 2004]
[edit reason] removed url [/edit]

Zipper

3:28 pm on Nov 1, 2004 (gmt 0)

10+ Year Member



Hi.. If I understood u correctly, I think you're heading in the wrong direction.. If you want a query string value to be stored in a cookie, then the only way you can access this peice of information is by using php cookie funtions and not any other.

For an instance, when someone visits the url
[domain.com...]
you can access this value (xyz) using $_GET['refer']

then you may store this in a cookie like this..
setcookie("refer", $_GET['refer'], time()+60*60*24*30);

now that u have the value stored, you can access it in your pages in the following way..

if(isset($HTTP_COOKIE_VARS["refer"])){
echo $_COOKIE["refer"];
}

Hope it helps..

rebeat

12:58 pm on Nov 2, 2004 (gmt 0)

10+ Year Member



Thanks Zipper :) worked great!

Cheers, rebeat ;))

rebeat

1:14 pm on Nov 2, 2004 (gmt 0)

10+ Year Member



One question...

The cookie is stored fine but when i view the page again without any query (?), the cookie is removed (obviously reset by having no query or (?) - is there anyway that any valid query willbe stored and not be overwritten by an empty query? ie: retrieves last "valid" query, so if someone does visit the link and tries to get around the query by removing the (?), it will retrieve the valid cookie (wont appear as empty.)

Cheers, rebeat

Zipper

5:21 pm on Nov 2, 2004 (gmt 0)

10+ Year Member



just check for the query string & the cookie before u set it up, in the following way..

if(isset($_GET['refer']) &&!isset($HTTP_COOKIE_VARS["refer"])){
setcookie("refer", $_GET['refer'], time()+60*60*24*30);
}

rebeat

11:36 am on Nov 3, 2004 (gmt 0)

10+ Year Member



Thanks Zipper, again you deliver the goods :)) works perfect.. :)

Cheers, ReBeAt