duncan_cowan Posted February 16, 2007 Share Posted February 16, 2007 hi i have made a script that is meant to process a login and it used to run with sessions but i wanted to use cookies to carry the loggin info so i set it to set some cookies but it doesnt work...please could someone help?script: $username = $_POST['uname']; $password = $_POST['passwd']; setcookie("username", "$username"); setcookie("password", "$password"); thanks in advance... Link to comment Share on other sites More sharing options...
justsomeguy Posted February 16, 2007 Share Posted February 16, 2007 Explain what you mean by it doesn't work. What does it do and not do? Link to comment Share on other sites More sharing options...
duncan_cowan Posted February 16, 2007 Author Share Posted February 16, 2007 the cookies are not seti test them with this script: if (isset($_COOKIE["username"])){echo "set";echo $_COOKIE["username"];} else {echo "not set";} Link to comment Share on other sites More sharing options...
duncan_cowan Posted February 16, 2007 Author Share Posted February 16, 2007 there must be a problem with that script because even thougt it says that they are not set they are... Link to comment Share on other sites More sharing options...
justsomeguy Posted February 16, 2007 Share Posted February 16, 2007 OK. Either you are setting the cookie wrong or checking it wrong. Keep in mind that you cannot check a cookie on the same page that you set it. Cookies get sent by the browser when it asks for the page, so by the time the PHP starts all cookies have already been sent. So you have to set the cookie on one page, and then have a link on the page to another page that checks the cookie. It's also not a good idea to redirect after you set a cookie, some browsers will ignore the cookie and just redirect. So you want to set the cookie, and then show some HTML on the page. You also can't set cookies after you send any HTML output, cookies need to be set before you output any HTML.Check the reference page for setcookie to see other parameters for it, like the path and domain. Scroll down the page to see code examples, and scroll down farther to see comments and examples from other people.http://www.php.net/manual/en/function.setcookie.php Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now