General Programming Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsProgrammingGeneral Programming Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
Be the architects of evolution and help create the mobile internet future. It’s your move---enter to win here!
  #1  
Old July 30th, 2002, 06:38 PM
nick316 nick316 is offline
Junior Member
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jul 2002
Location: N.S. Canada
Posts: 15 nick316 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
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

Reply With Quote
  #2  
Old July 30th, 2002, 06:42 PM
FrankieShakes FrankieShakes is offline
Frank The Tank!
Dev Articles Beginner (1000 - 1499 posts)
 
Join Date: Jun 2002
Location: Toronto, Canada
Posts: 1,246 FrankieShakes User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 8
Send a message via ICQ to FrankieShakes Send a message via MSN to FrankieShakes
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

Reply With Quote
  #3  
Old July 30th, 2002, 06:49 PM
nick316 nick316 is offline
Junior Member
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jul 2002
Location: N.S. Canada
Posts: 15 nick316 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
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

Reply With Quote
  #4  
Old July 30th, 2002, 07:08 PM
nick316 nick316 is offline
Junior Member
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jul 2002
Location: N.S. Canada
Posts: 15 nick316 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
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

Reply With Quote
  #5  
Old July 30th, 2002, 07:33 PM
Ben Rowe
Guest
Dev Articles Newbie (0 - 499 posts)
 
Posts: n/a  
Time spent in forums:
Reputation Power:
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:
<?php // <very first line!

//some code here, dont output anything,

ob_clean();
session_start();



?>

html here!

Reply With Quote
  #6  
Old July 30th, 2002, 07:39 PM
nick316 nick316 is offline
Junior Member
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jul 2002
Location: N.S. Canada
Posts: 15 nick316 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Thanks Ben. It works great.

I am just starting to learn PHP and this is a great site.

Reply With Quote
  #7  
Old September 18th, 2002, 03:46 AM
nik_crash nik_crash is offline
Junior Member
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Sep 2002
Posts: 6 nik_crash User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
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();
}
}

?>

Reply With Quote
  #8  
Old September 18th, 2002, 04:07 AM
Ben Rowe
Guest
Dev Articles Newbie (0 - 499 posts)
 
Posts: n/a  
Time spent in forums:
Reputation Power:
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

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingGeneral Programming Help > session help


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 

Iron Speed




© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 3 hosted by Hostway