June 2, 201313 yr hi guys this is my code, but I receive Cannot modify header information warning on the line which is Bold and Underlined. tnx <?php@session_start();$class="loginTextbox"; if ($_SESSION['url']!="/amlak/index.php"){ header("location:index.php"); exit ();}?><?php if (isset($_POST['password'])) { require_once './views/database/systemComponent.php'; require_once './views/database/dbConnector.php'; $dbConnectorObject =new dbConnector(); $sentPassword = $_POST['password']; $select = "SELECT * FROM password"; $result = mysql_query($select)or die(mysql_error());while($rows=mysql_fetch_array($result)) { $currentFirstPassword = $rows['password1']; $currentSecondPassword = $rows['password2']; }if(md5($sentPassword)==$currentFirstPassword) { $_SESSION['login']=true; header("location:add.php"); exit(); }else{ $class="failedloginTextbox"; } }?> Edited June 2, 201313 yr by stallman3738
June 2, 201313 yr Hi Stallman, Looking over your code I can only see one real obvious point of call and that is your database, what would be the result if you were to comment out the line you have highlighted? Do you have display errors enabled in your PHP ini?
June 2, 201313 yr You have 'required' 2 files in the views folder. Do either of these files send any HTML to the browser?
June 2, 201313 yr Author Hi Stallman, Looking over your code I can only see one real obvious point of call and that is your database, what would be the result if you were to comment out the line you have highlighted? Do you have display errors enabled in your PHP ini? yes display errors are enabled. If comment out the highlighted line then there will be no header and no redirection to add.php page. Edited June 2, 201313 yr by stallman3738
June 2, 201313 yr Author You have 'required' 2 files in the views folder. Do either of these files send any HTML to the browser? No, this is systemComponent.php <?php class systemComponent{ var $setting; function getSetting(){ $setting['dbhost']='localhost'; $setting[ ' dbusername' ]='root'; $setting['dbpassword']=''; $setting['dbname']='amlak'; return $setting; } } ?> and this is dbConnector.php, <?php require_once 'systemComponent.php'; class dbConnector extends systemComponent{ var $theQuery; var $link; function dbConnector(){ $setting=systemComponent::getSetting(); $host=$setting['dbhost']; $db=$setting['dbname']; $user=$setting['dbusername']; $pass=$setting['dbpassword']; $this->link=mysql_connect($host,$user,$pass)or die(mysql_error());; mysql_select_db($db) or die(mysql_error()); mysql_set_charset('utf-8'); } function query($query){ $this->theQuery=$query; return mysql_query($query,$this->link) or die(mysql_error()); } function fetchArray($result){ return mysql_fetch_array($result); } function close(){ mysql_close($this->link); } } ?> is there anything wrong?
June 2, 201313 yr hmmm. Is the quoted file standalone or is it being included by something else? I'm not positive but it looks like your code is being included by another script and if that script outputs something to the browser then the redirection won't work. One option would be to use output buffering in the calling script. As an aside, you might want to consider updating your database code to the mysqli extension or use the PDO class, both are pretty easy to learn. mysql is deprecated and I've read that php 5.5 will not support it.
June 2, 201313 yr Hello Stallman3738, I can remember I had this same issue, if I remember it correctly it was caused by whitespace. } ?> <!-- Here is whitespace. --> <?php if (isset($_POST['password'])) The white space between your php code is handled as output. You could try this: <?php // Make sure there is no whitespace before your opening tag. @session_start(); $class="loginTextbox"; if ($_SESSION['url']!="/amlak/index.php") { header("location:index.php"); exit (); } // Code merged. if (isset($_POST['password'])) { require_once './views/database/systemComponent.php'; require_once './views/database/dbConnector.php'; $dbConnectorObject =new dbConnector(); $sentPassword = $_POST['password']; $select = "SELECT * FROM password"; $result = mysql_query($select)or die(mysql_error()); while($rows=mysql_fetch_array($result)) { $currentFirstPassword = $rows['password1']; $currentSecondPassword = $rows['password2']; } if(md5($sentPassword)==$currentFirstPassword) { $_SESSION['login']=true; header("location:add.php"); exit(); } else{ $class="failedloginTextbox"; } } ?> Hope it helps, Léon Edited June 2, 201313 yr by Leonvv
June 2, 201313 yr Author Hello Stallman3738, I can remember I had this same issue, if I remember it correctly it was caused by whitespace. } ?> <!-- Here is whitespace. --> <?php if (isset($_POST['password'])) The white space between your php code is handled as output. You could try this: <?php // Make sure there is no whitespace before your opening tag. @session_start(); $class="loginTextbox"; if ($_SESSION['url']!="/amlak/index.php") { header("location:index.php"); exit (); } // Code merged. if (isset($_POST['password'])) { require_once './views/database/systemComponent.php'; require_once './views/database/dbConnector.php'; $dbConnectorObject =new dbConnector(); $sentPassword = $_POST['password']; $select = "SELECT * FROM password"; $result = mysql_query($select)or die(mysql_error()); while($rows=mysql_fetch_array($result)) { $currentFirstPassword = $rows['password1']; $currentSecondPassword = $rows['password2']; } if(md5($sentPassword)==$currentFirstPassword) { $_SESSION['login']=true; header("location:add.php"); exit(); } else{ $class="failedloginTextbox"; } } ?> Hope it helps, Léon No I tested this and still does not work;
June 2, 201313 yr Author There was something much more strange, I tested this <?php header("location:add.php"); ?> and still received the same warning
June 2, 201313 yr There was something much more strange, I tested this <?php header("location:add.php"); ?> and still received the same warning Do you have any whitespace before the <? part ? Léon
June 3, 201313 yr There was something much more strange, I tested this <?php header("location:add.php"); ?> and still received the same warning This error can be caused by a variety of things. Html output, php echos before the redirect,whitespace as mentioned,include files that contain any of the stuff I just mentioned. You basically just need to do some debugging and make sure you don't have any of the above. As an alternative you could try this <?php if(!headers_sent()){ header('Location:index.php'); exit; }else{ //Headers sent use javascript instead echo "<script>window.location = \"index.php\"</script>"; } ?> Edited June 3, 201313 yr by webdesigner93
June 3, 201313 yr Author This error can be caused by a variety of things. Html output, php echos before the redirect,whitespace as mentioned,include files that contain any of the stuff I just mentioned. You basically just need to do some debugging and make sure you don't have any of the above. As an alternative you could try this <?php if(!headers_sent()){ header('Location:index.php'); exit; }else{ //Headers sent use javascript instead echo "<script>window.location = \"index.php\"</script>"; } ?> Thanks alot it worked, how do I output the header_sent data to see what they are?
June 5, 201313 yr No, this is systemComponent.php <?php class systemComponent{ var $setting; function getSetting(){ is there anything wrong? "var" is depreciated and from PHP 5.0.0 through to 5.1.2 it will throw an error if used with E_STRICT errors enabled. This might be where your headers/output are coming from if you're using those versions. Also, the main reason why I'm replying; please, please, PLEASE tell me that you are not solely using MD5 for your password encryption methods?! It is categorically flawed and holds many weaknesses that allow it to be easily cracked. You should be using something with a stronger encryption method, specifically with salting. See crypt() and PHPass - which actually uses crypt and takes a lot of the nitty-gritty out of using it.
June 8, 201313 yr Author "var" is depreciated and from PHP 5.0.0 through to 5.1.2 it will throw an error if used with E_STRICT errors enabled. This might be where your headers/output are coming from if you're using those versions. Also, the main reason why I'm replying; please, please, PLEASE tell me that you are not solely using MD5 for your password encryption methods?! It is categorically flawed and holds many weaknesses that allow it to be easily cracked. You should be using something with a stronger encryption method, specifically with salting. See crypt() and PHPass - which actually uses crypt and takes a lot of the nitty-gritty out of using it. Hi, I found it, because I didn't save the file in UTF-8, it was in ANSI that is why that error reported. besides that I think it would be a good idea to redirect using .htaccess file to overcome such problems in situations where you can't find the solution. and about md5, yeah I have used this as the only method to encrypt the password; thanks for your suggestion Edited June 8, 201313 yr by stallman3738
Create an account or sign in to comment