XaVi3r Posted November 9, 2009 Share Posted November 9, 2009 ok so ive been learning php and up until now i have avoided using cookies. the page im trying to make right now however, i need to use them. basically what i would like to do is have the user enter a username and when they submit it have it written to a cookie and then display the username on the pages they link to. i understand how to create a cookie but am not sure of the logic on how to make it so whatever they input is what the cookie will remember and then im not sure how i would go about outputting it on another page. ive looked on other sites and just cant seem to find exactly what im looking for or atleast not with the simplicity im looking for. would anyone be able to shed some light on this for me? it would be greatly appreciated! Quote Link to comment Share on other sites More sharing options...
Netshroud Posted November 9, 2009 Share Posted November 9, 2009 For login details, using sessions would probably be better. Quote Link to comment Share on other sites More sharing options...
pabloacastillo Posted November 12, 2009 Share Posted November 12, 2009 its as easy as this: <?php @session_start(); // THIS GOES AT THE BEGINNING OF THE FILE $_SESSION['thename']='is my name'; echo $_SESSION['thename']; ?> I hope it helps :) Quote Link to comment Share on other sites More sharing options...
XaVi3r Posted November 18, 2009 Author Share Posted November 18, 2009 I ended up figuring it out with cookies and then as i kept messing around with different stuff started using sessions...thanks for the help tho! much appreciated! Quote Link to comment Share on other sites More sharing options...
theshane Posted December 16, 2009 Share Posted December 16, 2009 Although Sessions are a good way of doing this, why not discuss how to use cookies anyway... <?php //This sets the cookie called TestCookie to a variable $value setcookie("TestCookie", $value); //This sets a variable to the value of TestCookie. This can be used on any page in the domain. $testcookie = $_COOKIE["TestCookie"]; //This will show you all of your cookies that are set for your domain var_dump($_COOKIE); ?> Hope this helps. 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.