Jump to content

PHP cookie help


Recommended Posts

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!

Link to comment
Share on other sites

  • 4 weeks later...

Although Sessions are a good way of doing this, why not discuss how to use cookies anyway...

//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

Hope this helps.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Create New...