Problem with cookies in php

Asked

Viewed 395 times

0

I’m trying to generate a system that records a person’s email into a cookie so that they can add a list of a website’s properties to the database and when they upload the site via their email pulls up the list of favorite properties.

I made a simple form that plays to a page the post of his email. my Cod that gets this the following way.

if(!empty($_POST['Fmail'])){
   setcookie( "meuemail", $_POST['Fmail'], strtotime( '+1 year' ) );
}

after that he updates the page

on the property page I have a simple script to validate this cookie

echo $_COOKIE['meuemail'];

Only it always goes blank and it never gets filled. Where am I going wrong?

  • Check that you have the "Fmail" index of the $_POST is correct. Replace this with a string ex to see if it works. In fact, this is how cookies are defined.

1 answer

1


'/' means that the cookie is available throughout the site

if(!empty($_POST['Fmail'])){
  setcookie( "meuemail", $_POST['Fmail'], strtotime( '+1 year' ), '/' );
}
  • show, how do I check if this cookie exists? with isset or Empty ?

  • 1

    You can use the same if you created the cookie, if(!Empty($_COOKIE[meuemail]))' echo $_COOKIE[meuemail]; } on any page in any directory on the site.

  • thanks again helped a lot

Browser other questions tagged

You are not signed in. Login or sign up in order to post.