madspof Posted November 22, 2007 Share Posted November 22, 2007 I have this function to set a cookie but at the moment it does not appear to be working $info = "random"; setcookie ("info",$info, $time+1800); Quote Link to comment Share on other sites More sharing options...
Wes1890 Posted November 22, 2007 Share Posted November 22, 2007 Change to: $info = "random"; setcookie ("info",$info,time()+1800); You had $time+1800 instead of time()+1800 (time is a function, not a global var) If that doesnt work, then make sure you have cookies enabled on your browser. Quote Link to comment Share on other sites More sharing options...
madspof Posted November 25, 2007 Author Share Posted November 25, 2007 Right well this is the code am using but i gt this warning when the page is loaded coudl this explain why i cannot see the cookie Warning: Cannot modify header information - headers already sent by (output started at /www/110mb.com/i/m/p/a/c/t/-/y/impact-ye/htdocs/Login.php:4) in /www/110mb.com/i/m/p/a/c/t/-/y/impact-ye/htdocs/Login.php on line 11 <?php $info = "random"; $user = $_POST['name']; $pass = $_POST['pass']; if( $user == "staff"){ if($pass == "password"){ $log = "you are now logged in"; setcookie ("info",$info,time()+1800); }else { echo "your password is wrong";} } else{ $log = "you are mot logged in"; } ?> and then later on in the html <?php echo $_COOKIE["info"]; echo "$log"; ?> Quote Link to comment Share on other sites More sharing options...
revraz Posted November 25, 2007 Share Posted November 25, 2007 Means you are outputting to the browser before you set the cookie. Quote Link to comment Share on other sites More sharing options...
madspof Posted November 25, 2007 Author Share Posted November 25, 2007 but the setcokie funation is one of the first things to be proccesed it is infront of the html code Quote Link to comment Share on other sites More sharing options...
PHP_PhREEEk Posted November 25, 2007 Share Posted November 25, 2007 There is a post PINNED at the top of this Forum regarding Header errors. Read it... PhREEEk Quote Link to comment Share on other sites More sharing options...
madspof Posted November 25, 2007 Author Share Posted November 25, 2007 Well i check that thing and it seems that my code is set out correctly i think but i still get errors <?php $info = "random"; $user = $_POST['name']; $pass = $_POST['pass']; if( $user == "staff"){ if($pass == "password"){ $log = "you are now logged in"; setcookie ("info",$info,time()+1800); }else { echo "your password is wrong";} } else{ $log = "you are mot logged in"; } ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="content-type" content="text/html; charset=utf-8" /> <title>Impact. A Branch of Young Enterprise</title> <meta name="keywords" content="" /> <meta name="description" content="" /> <link href="/default.css" rel="stylesheet" type="text/css" /> </head> <body> <div id="wrapper"> <div id="header"> <h1><a href="#">Impact</a></h1> <p>a young enterprise group </a></p> </div> <!-- end header --> <div id="menu"> <h2>Main Menu</h2> <ul> <li class="active"><a href="/index.html">Home</a></li> <li><a href="/products.html">Products</a></li> <li><a href="/services.html">Services</a></li> <li><a href="/forum.html">Forum</a></li> <li><a href="/support.html">Support</a></li> <li></li> <li><a href="/contact.html">Contact</a></li> <a href="/members.html">members</a> </ul> </div> <!-- end menu --> <div id="page"> <div id="content"> <h1>Welcome to Impact </h1> <p> <div align="center"><?php echo $_COOKIE["info"]; echo "$log"; ?></div> </p> <p> </p> <p> </p> <p> </p> <p> </p> <p> </p> <div class="boxed"> <h2 class="title">LATEST NEWS </h2> <div class="content"> <div> <p>On the 11 of October 2007 this site was set up and is currently under construction. </p> <p> </p> <p>Please be patient for the site to develop further. </p> <p> </p> <p>We are constantly updating and hopefully we will be fully active in a matter of weeks. </p> <blockquote> </blockquote> </div> <p> </p> <blockquote> </blockquote> </div> </div> </div> <!-- end content --> <div id="sidebar"> <ul> <li id="search"> <form id="searchform" method="get" action=""> <fieldset> <legend>Search</legend> <input id="searchfield" type="text" name="q" value="" /> <input id="searchsubmit" type="submit" value="Search" /> </fieldset> </form> </li> <li id="submenu"> <h2>Other Links</h2> <ul> <li>products will be here soon </li> <li> <ul> <li>Services also </li> </ul> </li> </ul> </li> <li id="news"></li> <li></li> <li></li> <li></li> <li></li> <li></li> <li></li> <li></li> <li></li> <li></li> <li></li> <li></li> <li></li> <li> <h2>News & Updates</h2> <ul> <li>11 October 2007 </li> <li>Site is up and running. </li> <li>Currently undergoing construction. </li> <li><p> </p> </li> </ul> </li> </ul> </div> <!-- end sidebar --> <div style="clear: both;"> </div> </div> <!-- end page --> <div id="footer"> <p id="legal">Copyright © 2007 Impact. All Rights Reserved.</p> <p id="links">Privacy Policy | <a href="#">Terms of Use</a></p> </div> <!-- end footer --> </div> <!-- end wrapper --> </body> </html> Quote Link to comment Share on other sites More sharing options...
madspof Posted November 25, 2007 Author Share Posted November 25, 2007 AM rly stuck can anyone help Quote Link to comment Share on other sites More sharing options...
PHP_PhREEEk Posted November 25, 2007 Share Posted November 25, 2007 Is this a standalone file? A index.php with no other code? Or is this file an include in another file? Have you THOROUGHLY scanned this doc for any rogue white-space characters? PhREEEk Quote Link to comment Share on other sites More sharing options...
madspof Posted November 25, 2007 Author Share Posted November 25, 2007 no its jsut a single file and i have had a look but i cannot see anything Quote Link to comment Share on other sites More sharing options...
revraz Posted November 25, 2007 Share Posted November 25, 2007 Where are these getting pulled from $user = $_POST['name']; $pass = $_POST['pass']; Quote Link to comment Share on other sites More sharing options...
madspof Posted November 25, 2007 Author Share Posted November 25, 2007 its coming from a html page called login.html and the code i have for the form is <form method="POST" action="Login.php" name="login">Username:</td> <td><input type="text" name="name" class="forminput" size="7"></td></tr> <tr><td>Password:</td> <td><input type="password" name="pass" class="forminput" size="7"></td></tr> <tr><td colspan="2"><center><input type="submit" value="Login"></form> Quote Link to comment Share on other sites More sharing options...
madspof Posted November 25, 2007 Author Share Posted November 25, 2007 Omg what is going this is so anoying i think its the server's fault Quote Link to comment Share on other sites More sharing options...
janim Posted November 25, 2007 Share Posted November 25, 2007 try this : ob_start(); <?php $info = "random"; $user = $_POST['name']; $pass = $_POST['pass']; if( $user == "staff"){ if($pass == "password"){ $log = "you are now logged in"; setcookie ("info",$info,time()+1800); }else { echo "your password is wrong";} } else{ $log = "you are mot logged in"; } ob_finish(); ?> Quote Link to comment Share on other sites More sharing options...
janim Posted November 25, 2007 Share Posted November 25, 2007 sorry the ob_start() inside <?php like this <?php ob_start(); <?php $info = "random"; $user = $_POST['name']; $pass = $_POST['pass']; if( $user == "staff"){ if($pass == "password"){ $log = "you are now logged in"; setcookie ("info",$info,time()+1800); }else { echo "your password is wrong";} } else{ $log = "you are mot logged in"; } ob_finish(); ?> Quote Link to comment Share on other sites More sharing options...
revraz Posted November 26, 2007 Share Posted November 26, 2007 That may buffer it, but it's just a band aid for a bleeding wound. Quote Link to comment 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.