seany123 Posted November 9, 2011 Share Posted November 9, 2011 why aint this working?? <?php if ($_COOKIE['watch_id']){ $cookie = $_COOKIE['watch_id']; $cookie_query = mysql_query("SELECT * FROM user WHERE cookie='$cookie'"); if (mysql_num_rows($cookie_query) >= 1){ ?> <li><a href="/index.php">Home</a></li> <li><a href="/cpanel.php">C-Panel</a></li> <li><a href="/logout.php">Logout</a></li> pass <?php } if (mysql_num_rows($cookie_query) <= 1){ ?> <li><a href="register.php">Register</a></li> <li><a href="#" onclick="OPEN_login();">Login</a></li> <li><a href="index.php">Home</a></li> fail1 <?php } } if(!$_COOKIE['watch_id']){ ?> <li><a href="register.php">Register</a></li> <li><a href="#" onclick="OPEN_login();">Login</a></li> <li><a href="/index.php">Home</a></li> fail2 <?php } ?> i have checked in the browser and the cookies match but it always echos fail2 which means that this line is returning false: if ($_COOKIE['watch_id']){ i have tried using isset but that didnt help either! any help? Quote Link to comment https://forums.phpfreaks.com/topic/250807-cant-get-this-cookie-to-work-properly/ Share on other sites More sharing options...
xyph Posted November 9, 2011 Share Posted November 9, 2011 Either the cookie isn't set properly and/or PHP isn't being given the cookie by the web server. Since I don't see print_r($_COOKIE); anywhere, I'm going to assume you haven't actually checked if it exists. If it does exist, ensure the value is what you'd expect. If it doesn't, there's an issue with your cookie or your web server. Verify that your client is actually sending the cookie along with the request. Quote Link to comment https://forums.phpfreaks.com/topic/250807-cant-get-this-cookie-to-work-properly/#findComment-1286836 Share on other sites More sharing options...
seany123 Posted November 9, 2011 Author Share Posted November 9, 2011 it doesnt show what im expecting however when i look in the chrome cookie manager my website is listed twice as domain.com and www.domain.com and its the domain.com cookies that are echoing. how can i set my cookie to domain.com instead of www.domain.com Quote Link to comment https://forums.phpfreaks.com/topic/250807-cant-get-this-cookie-to-work-properly/#findComment-1286840 Share on other sites More sharing options...
xyph Posted November 9, 2011 Share Posted November 9, 2011 By using setcookie correctly. You set the $domain argument. Quote Link to comment https://forums.phpfreaks.com/topic/250807-cant-get-this-cookie-to-work-properly/#findComment-1286846 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.