ToddAtWSU Posted May 19, 2007 Share Posted May 19, 2007 I am trying to set some cookies and display them if they exist but I am having major problems. I don't think I am creating them correctly. Here is what my creation code looks like: <meta http-equiv="refresh" content="5;url=."> <?php if( $_POST["userName"] != "" ) { setcookie( "COCName", $_POST["userName"], time( ) + 60 * 60 * 24 * 30 ); } if( $_POST["userEmail"] != "" ) { setcookie( "COCEmail", $_POST["userEmail"], time( ) + 60 * 60 * 24 * 30 ); } ?> <html> Here is what my retrieval code looks like: <td><input type="text" name="userName" value="<?php if( $_POST["userName"] != "" ) { echo $_POST["userName"]; } else if( isset( $_COOKIE["COCName"] ) ) { echo $_COOKIE["COCName"]; } ?>"></td> <td align="left"> <font color="#FF0000" face="Arial"> * </font> </td> </tr> <tr> <td align="right">Your E-mail</td> <td><input type="text" name="userEmail" value="<?php if( $_POST["userEmail"] != "" ) { echo $_POST["userEmail"]; } else if( isset( $_COOKIE["COCEmail"] ) ) { echo $_COOKIE["COCEmail"]; } ?>"></td> What does it appear I am doing incorrectly? Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/52163-solved-php-cookies/ Share on other sites More sharing options...
V34 Posted May 20, 2007 Share Posted May 20, 2007 <?php if( $_POST["userName"] != "" ) { setcookie( "COCName", $_POST["userName"], time( ) + 60 * 60 * 24 * 30 ); } if( $_POST["userEmail"] != "" ) { setcookie( "COCEmail", $_POST["userEmail"], time( ) + 60 * 60 * 24 * 30 ); } ?> <meta http-equiv="refresh" content="5;url=."> <html> setcookie() need to be on top of the page. The same with Header. Quote Link to comment https://forums.phpfreaks.com/topic/52163-solved-php-cookies/#findComment-257271 Share on other sites More sharing options...
ToddAtWSU Posted May 20, 2007 Author Share Posted May 20, 2007 Thanks. I thought it just needed to be before the <html> tag and it was okay if it wasn't past the META tag. Quote Link to comment https://forums.phpfreaks.com/topic/52163-solved-php-cookies/#findComment-257284 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.