yami007 Posted September 28, 2009 Share Posted September 28, 2009 well here's what i want to do set the cookie on a directory, and call it back from other directory ex : set on install/install.php and call it back on admin/profile.php thought it would work without problems dont know what i did wrong anyway my code for install.php: <?php $_SESSION['pseudo'] = $pseudo; $_SESSION['password'] = $password; $time_expire = time() + 365*24*3600; setcookie('pseudo', $pseudo, $time_expire); setcookie('password', $password, $time_expire); ?> here is the 2nd code for profile.php : <?php if(($_COOKIE['pseudo']) AND ($_COOKIE['password'])) { $pseudo = $_COOKIE['pseudo']; $password = $_COOKIE['password']; // try to find a user who looks like the cookies $query = "SELECT admin_email,admin_password FROM admin_cp WHERE admin_email='{$pseudo}' AND admin_password='{$password}' LIMIT 1 "; $result = mysql_query($query) or die(mysql_error()); $found_one = mysql_num_rows($result); if ($found_one > 0) { $_SESSION['pseudo'] = $pseudo; } } ?> for the same directory it works fine : code for admin/login.php <?php $_SESSION['pseudo'] = $pseudo; $_SESSION['password'] = $password; if ( $autologin == 1 ) { $time_expire = time() + 365*24*3600; setcookie('pseudo', $pseudo, $time_expire); setcookie('password', $password, $time_expire); } ?> so what's the problem?? Link to comment https://forums.phpfreaks.com/topic/175796-solved-problem-with-cookies/ Share on other sites More sharing options...
PFMaBiSmAd Posted September 28, 2009 Share Posted September 28, 2009 The 4th parameter in the setcookie() function call is a 'path' parameter that must be set to make the cookie available outside of the path where the setcookie() was executed. Ref: http://php.net/setcookie Link to comment https://forums.phpfreaks.com/topic/175796-solved-problem-with-cookies/#findComment-926342 Share on other sites More sharing options...
yami007 Posted September 28, 2009 Author Share Posted September 28, 2009 this way?? <?php $time_expire = time() + 365*24*3600; setcookie('pseudo', $pseudo, $time_expire, '~kun/install', 'localhost', 1); setcookie('password', $password, $time_expire, '~kun/install', 'localhost', 1); ?> Link to comment https://forums.phpfreaks.com/topic/175796-solved-problem-with-cookies/#findComment-926349 Share on other sites More sharing options...
yami007 Posted September 28, 2009 Author Share Posted September 28, 2009 this ddnt work, could not even save the cookies ok now i removed and it saved them but still got the same problem as before Link to comment https://forums.phpfreaks.com/topic/175796-solved-problem-with-cookies/#findComment-926352 Share on other sites More sharing options...
yami007 Posted September 28, 2009 Author Share Posted September 28, 2009 damn happy it's working now what i did is remove the value to the domain it's troubling me because i'm on localhost <?php setcookie('password', $password, $time_expire, '~kun/install', ''); ?> Link to comment https://forums.phpfreaks.com/topic/175796-solved-problem-with-cookies/#findComment-926355 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.