|
|
|||||||||
|
|||||||||
|
|||||||||
| |
|||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
|
|
Be the architects of evolution and help create the mobile internet future. It’s your move---enter to win here! |
|
#1
|
|||
|
|||
|
session help
When I call:
session_start(); I get warnings that say: Warning: Cannot send session cookie - headers already sent by (output started at c:\program files\apache group\apache\wwwroot\login.php:10) in c:\program files\apache group\apache\wwwroot\login.php on line 47 Warning: Cannot send session cache limiter - headers already sent (output started at c:\program files\apache group\apache\wwwroot\login.php:10) in c:\program files\apache group\apache\wwwroot\login.php on line 47 What do these mean and is there any way to get rid of them? Thanks in advance, Nick |
|
#2
|
|||
|
|||
|
Nick,
It means that you are outputting something before outputting your session_start() function. Do you have any HTML code before that line? You can't have any code (and no blank lines, for that matter) on any previous lines or you will receive that error. What are the first few lines of your code?
__________________
____________________________________________ Developer Shed Weekly Writer | DevArticles Forum Moderator Build Your Own KlipFolio Klip With PHP FrankManno.com - Under Construction Design Interactive Group - Under Construction |
|
#3
|
|||
|
|||
|
Hi Frank,
I was calling session.start() about half way down my file. I take it this needs to be called right after the <?PHP tag? Or does it need to go at the top after <HTML>? Thanks, Nick |
|
#4
|
|||
|
|||
|
Here is the code:
<html> <head> <title> PHP Test </title> </head> <body bgcolor = "0033FF"> <?PHP $dbServer = "localhost"; $dbName = "userdatabase"; $dbUser = "root"; $dbPass = "nick316"; $db = mysql_connect($dbServer,$dbUser,$dbPass) or die("Couldn't connect to the database."); mysql_select_db($dbName) or die("Couldn't select the database"); // Add slashes to the username, and make a md5 checksum of the password. $_POST['user'] = addslashes($_POST['user']); $_POST['pass'] = md5($_POST['pass']); echo $_POST['user']; echo $_POST['pass']; $result = mysql_query("SELECT userID FROM users WHERE userPass='$_POST[pass]' AND userName='$_POST[user]'") or die("Couldn't query the user-database."); $num = mysql_result($result, 0); if (!$num) { // When the query didn't return anything, // display the login form. echo "<h3>User Login</h3> <form action='$_SERVER[PHP_SELF]' method='post'> Username: <input type='text' name='user'><br> Password: <input type='password' name='pass'><br><br> <input type='submit' value='Login'> </form>"; } else { // Start the login session session_start(); I tried moving the session start to the top and got the same error. Any ideas? Thanks, Nick |
|
#5
|
|||
|
|||
|
whats happening, is its outputting the html first, then running session_start, what you need to do is, place your php code, AT THE VERY TOP, not even spaces(known as whitespace), otherwise you'll get that error
so if you wanted to start a session this is what it would look like PHP Code:
|
|
#6
|
|||
|
|||
|
Thanks Ben. It works great.
I am just starting to learn PHP and this is a great site. |
|
#7
|
|||
|
|||
|
Session help
Sir,
I have the same error when i trying to click the url of my page. here's the code.. <?php $dbServer = "localhost"; $dbUser = "admin"; $dbPass = "password"; $dbName = "cart"; function ConnectToDb($server, $user, $pass, $database) { $s = @mysql_connect($server, $user, $pass); $d = @mysql_select_db($database, $s); if(!$s || !$d) return false; else return true; } function GetCartId() { if(isset($_COOKIE["cartId"])) { return $_COOKIE["cartId"]; } else { session_start(); **here's the begiining of eeror** setcookie("cartId", "session_id()", time() + ((3600 * 24) * 30)); return session_id(); } } ?> |
|
#8
|
|||
|
|||
|
did you miss the hole part of this post! it needs to be placed before anything is outputted in the headers, in this case the $_COOKIE function is causing your problems
|
![]() |
| Viewing: Dev Articles Community Forums > Programming > General Programming Help > session help |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|