View Full Version : any standard code to each page use cookies for using a PHP cookie in a page ?

01-29-2007, 09:18 PM
I must include any standard code when using cookies to a webpage[ http://www.paphoscarhire.com/reservations.htm ] , since cookies set in home-page[ http://www.paphoscarhire.com ] like

session_start( );
$affiliate = '10000'; //default value
if (isset($_COOKIE['aff']) && ($_COOKIE['aff'] != Null))
$affiliate = $_COOKIE['aff'];
else if (isset($_GET['aff']) && ($_GET['aff'] != Null)) {
$affiliate = $_GET['aff'];
setcookie("aff", $affiliate, time()+60*60*24*90); // 3 months
$_SESSION['affiliate'] = $affiliate ;

or the small code
<script language="JavaScript">
var affiliate = <?= $affiliate ?>;


<input type="hidden" name="affiliate" value="<?= $affiliate ?>">
<script language="JavaScript">
document.write("You book through affiliate ID: " + affiliate )

only is ok in a webpage [after the code in home-page] ? If I must include it to each webpage use cookies, which part of the page to insert this standard code ?
Tell me this for using PHP cookies and for using JS cookies ?

01-30-2007, 09:01 AM
i don't understand much of your post.

cookies are sent to and from the browser on each request/response so you don't need to do anything special to have access to a cookie. if you set it on the first page that the user visits (with the code that you posted), then you'll be able to read the cookie on all following pages (on that same domain, for the next 90 days).

01-30-2007, 10:22 AM
a)...then you'll be able to read the cookie on all following pages ::: using ONLY the small code I refer ?
b)How I convert a PHP cookie to a js cookie ?

01-30-2007, 10:02 PM
All you need is the appropriate PHP or Javascript code in the page that reads the cookie in order to access it.

Since cookies are the same regardles of the language used to create them there is no conversion required in order to read a cookie in Javascript that was created in PHP ir vice versa.