SUNIL16 Posted January 27, 2009 Share Posted January 27, 2009 Hi Friends, I set cookie like below after the user login. <?php require "config.php"; $username=$_REQUEST["uname"]; $password=md5($_REQUEST["password"]); $sql="SELECT usersid,username,password FROM users WHERE username='$username' and password='$password'"; $result=mysql_query($sql); $rows=mysql_fetch_array($result); $memberid=$rows['usersid']; $count=mysql_num_rows($result); if($count == 1) { setcookie("myusername", "$username",time()+3600); include("welcome.php"); exit(); } else { include("re_login.html"); exit(); } But now the problem is the user can login but the cookie is set only after 2logins means he has to login again to post any thing. what is the problem with cookie... Link to comment https://forums.phpfreaks.com/topic/142590-setting-cookie/ Share on other sites More sharing options...
uniflare Posted January 27, 2009 Share Posted January 27, 2009 cookies cannot be used on the same execution that created them. use either a Header("location: ./url.php"); redirection, or log them in as you create the cookie, (rather than relying on the cookie to be there). Link to comment https://forums.phpfreaks.com/topic/142590-setting-cookie/#findComment-747346 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.