bob2588 Posted November 9, 2009 Share Posted November 9, 2009 ok i am try to make a remimber me script but i am have problems with the setcookie() ans the session_start(); here is the code <?php session_start(); if(!session_is_registered(username)){ header('location:login.php'); } ?> <?php include'db.php'; $session=$_SESSION['username']; $run=mysql_query(" SELECT * From admin WHERE login='$session'"); while($row=mysql_fetch_array($run)) { $row['login']=$user; $expire= time()+60*60*24*14; setcookie("$user", "$value", $expire);//Line 17 } ?> <!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=utf-8" /> <title>Untitled Document</title> </head> <body> </body> </html> and here is the ERROR Warning: Cannot modify header information - headers already sent by (output started at /home/bob/public_html/ad/admin/cookie.php:9) in /home/bob/public_html/ad/admin/cookie.php on line 17 Quote Link to comment https://forums.phpfreaks.com/topic/180912-stupid-little-problem/ Share on other sites More sharing options...
Gayner Posted November 9, 2009 Share Posted November 9, 2009 Wats in db.php? Change $expire to '.$expire.' or "$expire" Quote Link to comment https://forums.phpfreaks.com/topic/180912-stupid-little-problem/#findComment-954428 Share on other sites More sharing options...
bob2588 Posted November 9, 2009 Author Share Posted November 9, 2009 just the databases conntion stuff <?php $host = "localhost"; //database location $user = "bob_ad"; //database username $pass = "*********"; //database password $db_name = "bob_ad"; //database name //database connection $link = mysql_connect($host, $user, $pass); mysql_select_db($db_name); Quote Link to comment https://forums.phpfreaks.com/topic/180912-stupid-little-problem/#findComment-954430 Share on other sites More sharing options...
DavidAM Posted November 9, 2009 Share Posted November 9, 2009 See the blank lines outside of the php tags? ?> <?php Those are sent to the browser. So you cannot send any more header information to the browser because you have already sent content. Remove the blank lines. In fact, there is no reason to close and re-open the php tag, so remove them too. Quote Link to comment https://forums.phpfreaks.com/topic/180912-stupid-little-problem/#findComment-954431 Share on other sites More sharing options...
Gayner Posted November 9, 2009 Share Posted November 9, 2009 Try a space after : on header header('location:login.php'); header('location: login.php'); Also remove extra spaces Quote Link to comment https://forums.phpfreaks.com/topic/180912-stupid-little-problem/#findComment-954432 Share on other sites More sharing options...
bob2588 Posted November 9, 2009 Author Share Posted November 9, 2009 See the blank lines outside of the php tags? ?> <?php Those are sent to the browser. So you cannot send any more header information to the browser because you have already sent content. Remove the blank lines. In fact, there is no reason to close and re-open the php tag, so remove them too. i took that code from the another script that the reason it there is was removed before but i will delete all the lines bob Quote Link to comment https://forums.phpfreaks.com/topic/180912-stupid-little-problem/#findComment-954435 Share on other sites More sharing options...
bob2588 Posted November 9, 2009 Author Share Posted November 9, 2009 thanks for all the help that worked bob Quote Link to comment https://forums.phpfreaks.com/topic/180912-stupid-little-problem/#findComment-954437 Share on other sites More sharing options...
Dorky Posted November 9, 2009 Share Posted November 9, 2009 This function has been DEPRECATED as of PHP 5.3.0 and REMOVED as of PHP 6.0.0. Relying on this feature is highly discouraged. http://php.net/manual/en/function.session-is-registered.php if (!isset($_SESSION['user'])){ //do stuff} Quote Link to comment https://forums.phpfreaks.com/topic/180912-stupid-little-problem/#findComment-954440 Share on other sites More sharing options...
PFMaBiSmAd Posted November 9, 2009 Share Posted November 9, 2009 You also need to put an exit; statement right after the header() redirect to prevent the remainder of the code on the page from being executed while the browser preforms the redirect. The current code won't protect the content on the page if a hacker ignores the header() redirect. Quote Link to comment https://forums.phpfreaks.com/topic/180912-stupid-little-problem/#findComment-954444 Share on other sites More sharing options...
Gayner Posted November 9, 2009 Share Posted November 9, 2009 You also need to put an exit; statement right after the header() redirect to prevent the remainder of the code on the page from being executed while the browser preforms the redirect. The current code won't protect the content on the page if a hacker ignores the header() redirect. ??? lol Quote Link to comment https://forums.phpfreaks.com/topic/180912-stupid-little-problem/#findComment-954457 Share on other sites More sharing options...
Dorky Posted November 10, 2009 Share Posted November 10, 2009 if (!isset($_SESSION['user'])){ header("Location: http://whatever.com") exit; } Quote Link to comment https://forums.phpfreaks.com/topic/180912-stupid-little-problem/#findComment-954472 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.