Jump to content

Recommended Posts

i have this problem i dont know if it a problem or it should be like that, im using cookie to display a name and in index.php the person write her/his name and press on submit then the site go to page call user.php and it needs to be reloaded before the name is display ([b]is that how it supposed to be?[/b]) so far so good and here comes the problem when i person want to delete the cookie and re-enter other name instead of a name i get a number for example 1165924546 (example "Hello, 1165924546!") i will write you the code im using for index.php and user.php

index.php code is:

<form action="user.php" method="post">
<input type="text" name="username">
<input type="submit" value="изпрати">
</form>

user.php:

<?php
ob_start()
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=koi8-r" />
<title>Потребителска информация</title>
</head>

<body>

<?php
if(!isset($_COOKIE['user']))
{
    setcookie ("user", $_POST['username']);
    header('user.php');
}
else
{
    echo 'Здравейте, '.$_COOKIE['user'];
}
?>

<?php
echo '!<br>Кликнете <a href="deletecookie.php">тук</a>, за да смените името, което посочихте или <a href="content.php">тук</a> за да продължите!'
?>


</body>
</html>

ps: some of the text is in bulgarian dont worrie about it :) and i have to say that i dont use any database (for now) i mean i dont want to use it and is it possible to do it without database? thank you very much!!!
Link to comment
https://forums.phpfreaks.com/topic/30345-question-about-cookie/
Share on other sites

You have to delete a cookie with the same parameters you set it with, so try this as the delete cookie page...

[code]<?php
setcookie ("user", '', time()-3600);
header("Location: http://localhost/phpuni/index.php"); /* Redirect browser */
exit;
?>[/code]

The number you were getting was because you were setting [code=php:0]time()-3600[/code] as the value of the cookie, not the expiry time.

Also, please use [b][nobbc][code][/code][/nobbc][/b] tags when posting code.

Regards
Huggie
Link to comment
https://forums.phpfreaks.com/topic/30345-question-about-cookie/#findComment-139615
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

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

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  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.

×
×
  • 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.