fohanlon Posted November 23, 2006 Share Posted November 23, 2006 Hi GuysI am spending hours on php cookies and looking at the code in IE and FF.But neither broswer is setting the cookies. I have seen the setcookie on php manuals and tried all the various suggested functions. I have looked at the various ways to setcookie. I am using the warning in firefox to test that a cookie has been set. Sometimes I get the cookie set but I need them to be set each time the website is visited.Register globals is on for the ISP (I checked this).Here is an example of what I was using:setcookie("ifxun", $_POST['username'], time()+3600, "/", "mydomain.com");Any useful comments/experences would be vey much appreciated or code I could try. I am at a loss and have read the same comments over and over again on the web forums but the suggestions do not work.Many Thanks,Fergal. Quote Link to comment Share on other sites More sharing options...
btherl Posted November 23, 2006 Share Posted November 23, 2006 Can you post more of your code? The code which sometimes works but sometimes doesn't would be the best to look at.Cookies can be affected by displaying HTML before the setcookie() call, as they must be sent with the headers. Quote Link to comment Share on other sites More sharing options...
ataria Posted November 23, 2006 Share Posted November 23, 2006 do you have 'ob_start();' at the beginning and 'ob_flush();' at the end? Quote Link to comment Share on other sites More sharing options...
ataria Posted November 23, 2006 Share Posted November 23, 2006 Ohh.and you mind need to add '{' infront and after the $_POSt...like so..setcookie("ifxun", {$_POST['username']}, time()+3600, "/", "mydomain.com"); Quote Link to comment Share on other sites More sharing options...
fohanlon Posted November 23, 2006 Author Share Posted November 23, 2006 Hi Guys,Thanks for the responses. Still no luck. Here's the scenario, I have a members login page with a username and password form, this is passed to a login check page code as below:<?phprequire('config.php');$username = $_POST['username']; $password = $_POST['password'];$user_exists = mysql_query("SELECT * FROM members WHERE username = BINARY '$username' AND user_password = BINARY '$password'");$num_users = mysql_num_rows($user_exists);if($num_users == 0) { include 'index.php'; exit(); // exit the script}else{ setcookie("ifxun", $_POST['username'], time()+3600, "/"); setcookie("ifxpw", $_POST['password'], time()+3600, "/"); header("location: test.php");}?>I am using Mozilla FF warning procedure - that cookies are being set. the above code does not call the FF warning and cookie are not being set.Can you help me out further.many thanks,Fergal. Quote Link to comment Share on other sites More sharing options...
ataria Posted November 23, 2006 Share Posted November 23, 2006 change it to..[code]<?phpob_start();require('config.php');$username = $_POST['username'];$password = $_POST['password'];$user_exists = mysql_query("SELECT * FROM members WHERE username = BINARY '$username' AND user_password = BINARY '$password'");$num_users = mysql_num_rows($user_exists);if($num_users == 0){ include 'index.php'; exit(); // exit the script}else{ setcookie("ifxun", $_POST['username'], time()+3600, "/"); setcookie("ifxpw", $_POST['password'], time()+3600, "/"); header("location: test.php");}ob_flush();?>[/code] Quote Link to comment Share on other sites More sharing options...
fohanlon Posted November 23, 2006 Author Share Posted November 23, 2006 atariathe ob_start and ob_flush worked. Thanks for your support and help.I checked the php man files and am I correct in stating that it has to do with sending only header information in the buffer.Many Thanks,Fergal. Quote Link to comment 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.