bp90210 Posted November 18, 2008 Share Posted November 18, 2008 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(); ?> Quote Link to comment https://forums.phpfreaks.com/topic/133203-set-cookie/ Share on other sites More sharing options...
premiso Posted November 18, 2008 Share Posted November 18, 2008 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. Quote Link to comment https://forums.phpfreaks.com/topic/133203-set-cookie/#findComment-692772 Share on other sites More sharing options...
bp90210 Posted November 18, 2008 Author Share Posted November 18, 2008 i changed to setcookie and have only one isntance now and it still isnt working. also, not on a local host Quote Link to comment https://forums.phpfreaks.com/topic/133203-set-cookie/#findComment-692780 Share on other sites More sharing options...
bp90210 Posted November 18, 2008 Author Share Posted November 18, 2008 i have this code as part of an include on another php page before <html> if that helps. Quote Link to comment https://forums.phpfreaks.com/topic/133203-set-cookie/#findComment-692786 Share on other sites More sharing options...
premiso Posted November 18, 2008 Share Posted November 18, 2008 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. Quote Link to comment https://forums.phpfreaks.com/topic/133203-set-cookie/#findComment-692789 Share on other sites More sharing options...
PFMaBiSmAd Posted November 18, 2008 Share Posted November 18, 2008 Add the following two lines immediately after your first opening <?php tag in your main file to get php to help you - ini_set ("display_errors", "1"); error_reporting(E_ALL); Quote Link to comment https://forums.phpfreaks.com/topic/133203-set-cookie/#findComment-692822 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.