Jump to content

php session


jalaladdin

Recommended Posts

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

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

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

--------------i have code html code before <?php session_start?>i don't know problem where it is
that 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

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

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

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

  • 2 weeks later...

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...