jalaladdin Posted July 2, 2010 Share Posted July 2, 2010 please help me this problem when i write this code in the notepadIE doesn't show error <?php session_start();if(isset($_POST['username'])){ $con=mysql_connect("localhost","root","");if(!$con){die('could not connect');}mysql_select_db("register",$con); $username = addslashes($_POST[username]); $password=addslashes($_POST[password]);$result = mysql_query("SELECT count(*) FROM users WHERE username = '$username' and password = '$password'");//$p = mysql_query("SELECT count(*) FROM users WHERE password = '$password'"); if (!$result) { echo 'Could not run query: ' . mysql_error(); exit;}$row = mysql_fetch_row($result);//$row = mysql_fetch_row($p); if($row[0]>0 ){$_SESSION['username'] = $username;$_SESSION['password'] = $password;header("Location: index.php"); printf("welcome%s<br />", $username); printf('<form action="index.php" method="post" class=" dir"><br/><input type="submit" value="exit" />'); exit;}else{echo"invalid username or password";printf('<form action="1.php" method="post" class=" dir"> <input type="text" name="username" /><input type="password" name="password" /> <br/><input type="submit" value="login" /><a href="register.html" ><div class="dir">register new user </a></div><a href="back password.html" ><div class="dir">forgetting password </a></div></form>'); } }?> but when i write this code in the dreamweaver ,IE show me this errorWarning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at C:\wamp\www\1.php:9) in C:\wamp\www\1.php on line 13 Link to comment Share on other sites More sharing options...
thescientist Posted July 2, 2010 Share Posted July 2, 2010 do you have any code before <?php. session start has to be the first thing outputted to the page, no HTML, white lines, spaces, etc. Link to comment Share on other sites More sharing options...
jalaladdin Posted July 2, 2010 Author Share Posted July 2, 2010 do you have any code before [/b]<?php[/b]. session start has to be the first thing outputted to the page, no HTML, white lines, spaces, etc.--------------i have code html code before <?php session_start?>i don't know problem where it is Link to comment Share on other sites More sharing options...
thescientist Posted July 2, 2010 Share Posted July 2, 2010 --------------i have code html code before <?php session_start?>i don't know problem where it isthat IS the problem, that's why I asked.http://us3.php.net/manual/en/function.session-start.php Link to comment Share on other sites More sharing options...
jeffman Posted July 2, 2010 Share Posted July 2, 2010 Be clear on what you're seeing. IE is not reporting a browser error. It is displaying text sent to the browser by your server. Your server is experiencing an error.sessions work by sending cookies to the browser. When a cookie is sent, a header is sent. When HTML is sent, a header is sent. The way PHP works, cookies will be sent at the same time as HTML (requiring just one set of headers), but only if the cookies are sent first. (PHP just waits and sends them together.) But if any other output is sent first, then the headers would be separated. This is not allowed.Notice carefully: any other output.EDIT: I sent this before thescientist's more recent post. Link to comment Share on other sites More sharing options...
jalaladdin Posted July 3, 2010 Author Share Posted July 3, 2010 i wrote <?php session_start();?> before html code ,IE show me this errorWarning: session_start() [function.session-start]: Cannot send session cookie - headers already sent by (output started at C:\wamp\www\4\index.php:1) in C:\wamp\www\4\index.php on line 2Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at C:\wamp\www\4\index.php:1) in C:\wamp\www\4\index.php on line 2 Link to comment Share on other sites More sharing options...
boen_robot Posted July 3, 2010 Share Posted July 3, 2010 No you haven't. There's still something... maybe a whitespace or a blank line, but there IS something.In fact, the error message says it: <?php session_start();?> is one line long, and the message says Warning: session_start() [function.session-start]: Cannot send session cookie - headers already sent by (output started at C:\wamp\www\4\index.php:1) in C:\wamp\www\4\index.php on line 2 That means that there is one line above "<?php". Regardless of what that line contains, as soon as you have a newline plus "<?php", you've already sent the headers, because the newline character itself is a character that becomes part of the output. Link to comment Share on other sites More sharing options...
HungryMind Posted July 11, 2010 Share Posted July 11, 2010 Salam!Try This CODE:xxxxxxxxxxxxxxxxxxx<?php ob_start();// Try To Write session_start() Command On Top & Be Sure, It's Not Using Multiple Times In Same Page.session_start();// ALL YOUR CODE WILL BE HERE AFTER ob_start(); And session_start(); And BEFORE ob_flush().ob_flush();?>xxxxxxxxxxxxxxxxxxThnx & Regards: Hungry Mind (http://hungrymind.tk/) Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.