sstangle73 Posted July 29, 2007 Share Posted July 29, 2007 <?php setcookie("UserName", $_POST['UserName'], time()+604800); ?> What am i doing wrong? Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/62276-solved-cookies/ Share on other sites More sharing options...
trq Posted July 29, 2007 Share Posted July 29, 2007 What is the problem? Quote Link to comment https://forums.phpfreaks.com/topic/62276-solved-cookies/#findComment-309913 Share on other sites More sharing options...
sstangle73 Posted July 29, 2007 Author Share Posted July 29, 2007 the cookie isnt writeing my site is stangle.info and its the remember my name thing right on the home page i cant figure it out Quote Link to comment https://forums.phpfreaks.com/topic/62276-solved-cookies/#findComment-309914 Share on other sites More sharing options...
trq Posted July 29, 2007 Share Posted July 29, 2007 the cookie isnt writeing  Can you explain how you know this? What steps are you actually taking to come to this conclusion? We simply need more info, this isn't a guessing game. Quote Link to comment https://forums.phpfreaks.com/topic/62276-solved-cookies/#findComment-309915 Share on other sites More sharing options...
sstangle73 Posted July 29, 2007 Author Share Posted July 29, 2007 the fact that nothing changes on my site saying that cookie wasnt written http://stangle.info try it mabie im just way too tired lol Quote Link to comment https://forums.phpfreaks.com/topic/62276-solved-cookies/#findComment-309917 Share on other sites More sharing options...
wildteen88 Posted July 29, 2007 Share Posted July 29, 2007 There is probably a problem with your script as I get no cookies set when I fill in your form and submit it even though my browser does except cookies. Â Post the the code here that sets the cookie and how you retrieve the cookie. Â Make sure when you set the cookie there is now output before you use setcookie function. To retrieve a cookie you must use $_COOKIE['cookie_name_here'] variable. Quote Link to comment https://forums.phpfreaks.com/topic/62276-solved-cookies/#findComment-310029 Share on other sites More sharing options...
sstangle73 Posted July 29, 2007 Author Share Posted July 29, 2007 To get the data <? if (isset($_COOKIE['UserName'])) { echo ?> <form action="mail.php" method="post"> Your Name: <input type="text" name="name"><br> E-mail: <input type="text" name = "email"><br><br> Comments<br> <textarea name="comments"></textarea><br><br> <input type="submit" value="Submit"> </form> <? } else { echo ?> <form action="name.php" method="post"> Your Name: <input type="text" name="UserName"><br> <input type="submit" value="Remember My Name!"> </form> <? } ?>  on name.php:  <?php setcookie("UserName", $_POST['UserName'], time()+604800); ?> <html>...</head>... <?php $UserName=$_POST['UserName']; php?> <?php echo "Thanks $UserName"; php?> <br> <?php if (isset($_COOKIE["user"])) { echo "Your name will be remembered for one week or untill your cookies are cleared!"; } else { echo "Error Cookie not set Please try again. Check to make sure you browser allows cookies!"; } php?>   here is retriveing the cookie back on the index.php:  <?php if (isset($_COOKIE['UserName'])) { echo "Hello, ".$_COOKIE['UserName']."! Welcome back!"; } else { echo "Please provide your name below!"; } php?> Quote Link to comment https://forums.phpfreaks.com/topic/62276-solved-cookies/#findComment-310187 Share on other sites More sharing options...
wildteen88 Posted July 29, 2007 Share Posted July 29, 2007 In name.php you are retrieving a cookie called user but you set a cookie called UserName Quote Link to comment https://forums.phpfreaks.com/topic/62276-solved-cookies/#findComment-310194 Share on other sites More sharing options...
sstangle73 Posted July 29, 2007 Author Share Posted July 29, 2007 allright thanks but the cookie still isnt setting Quote Link to comment https://forums.phpfreaks.com/topic/62276-solved-cookies/#findComment-310196 Share on other sites More sharing options...
sstangle73 Posted July 30, 2007 Author Share Posted July 30, 2007 bumpercars Quote Link to comment https://forums.phpfreaks.com/topic/62276-solved-cookies/#findComment-310967 Share on other sites More sharing options...
sstangle73 Posted July 30, 2007 Author Share Posted July 30, 2007 bumpercars Quote Link to comment https://forums.phpfreaks.com/topic/62276-solved-cookies/#findComment-311052 Share on other sites More sharing options...
pyrodude Posted July 30, 2007 Share Posted July 30, 2007 PHP.net says regarding setcookie(): setcookie() defines a cookie to be sent along with the rest of the HTTP headers. Like other headers, cookies must be sent before any output from your script (this is a protocol restriction). This requires that you place calls to this function prior to any output, including <html> and <head> tags as well as any whitespace.  Once the cookies have been set, they can be accessed on the next page load with the $_COOKIE or $HTTP_COOKIE_VARS arrays. Note, superglobals such as $_COOKIE became available in PHP 4.1.0. $HTTP_COOKIE_VARS has existed since PHP 3. Cookie values also exist in $_REQUEST.  So your verification in name.php seems pointless. Also, you should get rid of the empty echo statements in the first batch of code you posted. If you exit the PHP code, you don't need to use echo statements. However, this still doesn't correct your problem of them not setting, it's just simple schematics. Quote Link to comment https://forums.phpfreaks.com/topic/62276-solved-cookies/#findComment-311071 Share on other sites More sharing options...
sstangle73 Posted July 30, 2007 Author Share Posted July 30, 2007 fixed the schematics stuff but like you said its not going to help the setting Quote Link to comment https://forums.phpfreaks.com/topic/62276-solved-cookies/#findComment-311080 Share on other sites More sharing options...
sstangle73 Posted July 30, 2007 Author Share Posted July 30, 2007 <?php setcookie("UserName", $_POST['UserName'], time()+604800, "stangle", ".stangle.info"); ?> Quote Link to comment https://forums.phpfreaks.com/topic/62276-solved-cookies/#findComment-311227 Share on other sites More sharing options...
sstangle73 Posted July 30, 2007 Author Share Posted July 30, 2007 anyone? Quote Link to comment https://forums.phpfreaks.com/topic/62276-solved-cookies/#findComment-311435 Share on other sites More sharing options...
sstangle73 Posted July 31, 2007 Author Share Posted July 31, 2007 this is sad:( im almost crying jk Quote Link to comment https://forums.phpfreaks.com/topic/62276-solved-cookies/#findComment-311626 Share on other sites More sharing options...
jitesh Posted July 31, 2007 Share Posted July 31, 2007 (1) First check cookies are enable in your browser. (2) Try  <?php if(isset($_POST['UserName']) and !empty($_POST['UserName'])){  setcookie("UserName", $_POST['UserName'], time()+604800, "/");  }else{  echo "Problem";  } ?> Quote Link to comment https://forums.phpfreaks.com/topic/62276-solved-cookies/#findComment-311627 Share on other sites More sharing options...
sstangle73 Posted July 31, 2007 Author Share Posted July 31, 2007 in the header?> Quote Link to comment https://forums.phpfreaks.com/topic/62276-solved-cookies/#findComment-311636 Share on other sites More sharing options...
sstangle73 Posted July 31, 2007 Author Share Posted July 31, 2007 no go either way Quote Link to comment https://forums.phpfreaks.com/topic/62276-solved-cookies/#findComment-311642 Share on other sites More sharing options...
sstangle73 Posted July 31, 2007 Author Share Posted July 31, 2007 sigh this is making me sad Quote Link to comment https://forums.phpfreaks.com/topic/62276-solved-cookies/#findComment-311947 Share on other sites More sharing options...
sstangle73 Posted July 31, 2007 Author Share Posted July 31, 2007 is anyone else haveing problems with 1and1 and php cookies? Quote Link to comment https://forums.phpfreaks.com/topic/62276-solved-cookies/#findComment-312150 Share on other sites More sharing options...
sstangle73 Posted July 31, 2007 Author Share Posted July 31, 2007 ok i called 1and1 and it did end up being problems on their end thanks all that helped! Quote Link to comment https://forums.phpfreaks.com/topic/62276-solved-cookies/#findComment-312153 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.