Jump to content

cookies not working(plz i need help)


john_zakaria

Recommended Posts

--------------------------------------------------------------------------------

 

i want to make the following using cookies

When any user access the website, if this is the first time for him, he has to fill a form as follows

 

 

 

Name

 

Email

 

City

 

Country

 

Telephone number [area code] + [phone number]

 

 

 

After filling the above fields and submitting, the site wants all above to be saved on users machine as cookies, so that, after submission, when you close the browser, even the computer itself is closed and you opened the website again, you’ll not find the form with fields above, you’ll find instead the data inserted before.

 

plz can anyone help me to do the following , i want to know if this need a database or not? and how to make it?

 

 

 

i made this in page index.php

 

 

<html>

<body><form action="welcome.php" method="post">

Name: <input type="text" name="name" id="name" />

City: <input type="text" name="city" id="city" />

<input type="submit" />

</form></body>

</html>

 

 

and in welcome.php

 

<html>

<body>Welcome <?php echo $_POST["name"]; ?>.<br />

You are From <?php echo $_POST["city"]; ?> .</body>

 

<?

 

$expire=time()+60*60*24*30;

setcookie("user2", $_POST["name"], $expire);

//setcookie("user", "", 60);

 

?>

<?

if (isset($_COOKIE["user2"]))

echo "Welcome " . $_COOKIE["user2"] . "!<br />";

else

echo "Welcome guest!<br />";

?>

</html>

 

i tested if i got it from my form and after that i tried to print my cookir name but it did not work

can u help me plz

Link to comment
https://forums.phpfreaks.com/topic/133028-cookies-not-workingplz-i-need-help/
Share on other sites

You probably have error displays and reporting turned off.  If they were on, you would have received a HEADER error since you try to set a cookie after you have output to the browser.  Read the HEADER sticky for more info.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.