bulgaria_mitko Posted December 12, 2006 Share Posted December 12, 2006 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.phpindex.php code is:<form action="user.php" method="post"><input type="text" name="username"><input type="submit" value="изпрати"></form>user.php:<?phpob_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><?phpif(!isset($_COOKIE['user'])){ setcookie ("user", $_POST['username']); header('user.php');}else{ echo 'Здравейте, '.$_COOKIE['user'];}?><?phpecho '!<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!!! Quote Link to comment https://forums.phpfreaks.com/topic/30345-question-about-cookie/ Share on other sites More sharing options...
bulgaria_mitko Posted December 12, 2006 Author Share Posted December 12, 2006 also the code for deletecookie.php is:<?PHPsetcookie ("user", time() - 3600);header("Location: http://localhost/phpuni/index.php"); /* Redirect browser */exit;?> Quote Link to comment https://forums.phpfreaks.com/topic/30345-question-about-cookie/#findComment-139611 Share on other sites More sharing options...
HuggieBear Posted December 12, 2006 Share Posted December 12, 2006 You have to delete a cookie with the same parameters you set it with, so try this as the delete cookie page...[code]<?phpsetcookie ("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.RegardsHuggie Quote Link to comment https://forums.phpfreaks.com/topic/30345-question-about-cookie/#findComment-139615 Share on other sites More sharing options...
bulgaria_mitko Posted December 12, 2006 Author Share Posted December 12, 2006 thank you very much, HuggieBear! i didnt used code function because i saw that the cycrillic text it dosent display it letters instead it display numbers, but i test it now and i see it is ok, very strange. i will try now what u wrote me! Quote Link to comment https://forums.phpfreaks.com/topic/30345-question-about-cookie/#findComment-139632 Share on other sites More sharing options...
bulgaria_mitko Posted December 12, 2006 Author Share Posted December 12, 2006 btw its off-topic, but what is the code for using footer.php and header.php pages in one page (i dont know if u get my idea) Quote Link to comment https://forums.phpfreaks.com/topic/30345-question-about-cookie/#findComment-139634 Share on other sites More sharing options...
HuggieBear Posted December 12, 2006 Share Posted December 12, 2006 The syntax for having those appear on your page is [code=php:0]include_once('header.php');[/code] and it's that simple :)RegardsHuggie Quote Link to comment https://forums.phpfreaks.com/topic/30345-question-about-cookie/#findComment-140001 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.