Unstoppable Domains

Any Cookie coders here?

Spaceship Spaceship
Watch

vincenzo

VIP Member
Impact
14
:) Hi all,
I have never coded cookies, so please bare with me.
What I need, is to create a cookie that will store the referring URL, and date, for visitors.

Open to suggestions, but think I only need to store the following:

- Refferring URL
- Date of first visit
- Cookie expiry date

Purpose:
Need to track each form submission, with info regarding which site and/or banner referred these leads.

hence, I would then like to use the cookie information within the various forms on my site as a hidden field value. The forms use PHP/MySQL to both send an email with results and store into databse.

Would appreciate any help.
Many thanks,

- Vince
 
0
•••
The views expressed on this page by users and staff are their own, not those of NamePros.
.US domains.US domains
Ok, cookies are very easy to do with php, i'll try to talk you through it but the best referenece is the official php site - http://uk2.php.net/manual/en/function.setcookie.php

The code to set a cookie in php is quite simply setcookie()
the simplest form you can set a cookie is:
PHP:
$name="cookie1";
$value="hello";
setcookie("$name", $value);
this will set a cookie called cookie1, and the data within it will be hello, but remember when setting a cookie using php always put all of the code ABOVE any text, eg:
PHP:
<?php
$name="cookie1";
$value="hello";
setcookie("$name", $value);
//then the rest of the page
?>
<html>
a cookie such as that will never expire, then to retrieve the data from the cookie you use:
$_COOKIE['cookiename']
so once the cookie above is set, to view its data on another php page you would use:
PHP:
<?php
$cookiedata=$_COOKIE['cookie1'];
echo $cookiedata;
?>
which would return "hello", you just repeat those steps for each of the items of data that you want to be set as a cookie

hope this helps

Lee
 
0
•••
setcookie("name", "value", time()+86400);
That will set $_COOKIE['name'] to "value" for one day.


How long do cookies last if you don't set when they expire?
 
0
•••
i think they just last forever, ot until you delete the cookies manually, but something i learnt yesterday was that if you set the time to "0" it will act as a session cookie, and be deleted as soon as the browser window is closed
 
0
•••
lee101 said:
i think they just last forever, ot until you delete the cookies manually, but something i learnt yesterday was that if you set the time to "0" it will act as a session cookie, and be deleted as soon as the browser window is closed
Actually, don't set cookie to "0". Leaving it with NO set value, means it is session-only (closes when browser closes - as noted on link Lee gave above, or when cookie is killed-off by code, whichever comes first). Setting it to "0" makes it non-existant/pre-expired in some browsers from the get-go.
 
0
•••

We're social

Unstoppable Domains
Domain Recover
DomainEasy — Payment Flexibility
  • The sidebar remains visible by scrolling at a speed relative to the page’s height.
Back