Jump to content

set cookie


bp90210

Recommended Posts

I have a problem with a cookie not being set it in any browser (IE or firefox).  can anyone help? thanks

 

<?php


//ob_start();
if($_GET['saref']){
//someone is coming to this page with a get string that starts with ref=something
//we need to id the offer and get some info
include "sa_config.php";
$con = sa_db_connect();
if(!$con){
	//could add some kind of admin email message here
}
//split the saref into its parts
list($offerID, $affiliateID) = explode("sa", $_GET['saref']);
//	echo "IDs:".$offerID.$affiliateID;
$q1 = "SELECT * FROM Offers WHERE OfferID = '$offerID' ";
$result1 = mysql_query($q1);
$row1 = mysql_fetch_array($result1);
if(mysql_num_rows < 1){
	//we have someone trying to access with an invalid offer id we should email the admin about this
}
$cookieExpiration = $row1[CookieExpire];
if($cookieExpiration > 0)
   	$cookieLifetime = time() + $cookieExpiration;
	else
    	$cookieLifetime =  time() + 3650*86400;


    SetCookie ("saref",$_GET['saref'], $cookieLifetime, $cookiePath, $cookieDomain);
SetCookie ("saref",$_GET['saref'], $cookieLifetime, $cookiePath, $cookieDomain);
SetCookie ("saref",$_GET['saref'], $cookieLifetime, $cookiePath, $cookieDomain);
SetCookie ("saref",$_GET['saref'], $cookieLifetime, $cookiePath, $cookieDomain);
	SetCookie ("saref",$_GET['saref'], $cookieLifetime, $cookiePath, $cookieDomain);


  	if(session_id() == ""){
	session_start();
}
  	$_SESSION['ref'] = $_GET['saref'];
$timeNow = date("U"); 
$q1 = "INSERT INTO Clicks (AffiliateID, OfferID, UnixTime, RemoteAddress, RefURL, Browser) VALUES 
('".$affiliateID."', '$offerID', '".$timeNow."', '".$clickIP."', '".$clickURL."', '".$clickBrowser."')";
$result1 = mysql_query($q1);
//echo $q1;

}
//ob_flush();
?>

Link to comment
https://forums.phpfreaks.com/topic/133203-set-cookie/
Share on other sites

Is this on an actual site or on Localhost?

 

If on localhost check out this article:

 

http://www.aeonity.com/frost/php-setcookie-localhost-apache

 

Why are you setting the cookie soo many times? I am not sure if this matters, but pHp is CaSe SenSitIve and you are using SetCookie, to be a good coder I would change it to be setcookie just to avoid any possiblity of error now or later.

 

So A: remove the 4 other checks, change the setcookie to lowercase and let us know if you are working on LocalHost as localhost has to have cookies set a different way, unfortunately.

Link to comment
https://forums.phpfreaks.com/topic/133203-set-cookie/#findComment-692772
Share on other sites

Where are you testing if the cookie has been set? Also what are the values of $cookiePath and $cookieDomain, as that can make or break the function.

 

edit:

Ah, setcookie has to be called before any input is sent to the browser. That is the issue right there. Move the include file above the <html> tag and I bet it will work.

Link to comment
https://forums.phpfreaks.com/topic/133203-set-cookie/#findComment-692789
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.