Jump to content


Photo

cannot send session cookie, headers already sent by.....


  • Please log in to reply
11 replies to this topic

#1 devvie

devvie
  • New Members
  • Pip
  • Newbie
  • 7 posts

Posted 27 July 2006 - 08:25 PM

Im getting this message when i load my login page.  its brand new, so i hjave a million directions i can go.  I want a secure login with sessions so that i can remove the logins on other outside apps on the site. 
Warning: session_start() [function.session-start]: Cannot send session cookie - headers already sent by (output started at /home/c4sale/public_html/main/Connections/connection.php:12) in /home/c4sale/public_html/main/login.php on line 36

Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at /home/c4sale/public_html/main/Connections/connection.php:12) in /home/c4sale/public_html/main/login.php on line 36

heres the header of my page
<?php require_once('Connections/connection.php'); ?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
{
  $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;

  $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

  switch ($theType) {
    case "text":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;    
    case "long":
    case "int":
      $theValue = ($theValue != "") ? intval($theValue) : "NULL";
      break;
    case "double":
      $theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";
      break;
    case "date":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;
    case "defined":
      $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
      break;
  }
  return $theValue;
}
}
?>

<?php
// *** Validate request to login to this site.
if (!isset($_SESSION)) {
  session_start();
}

$loginFormAction = $_SERVER['PHP_SELF'];
if (isset($_GET['accesscheck'])) {
  $_SESSION['PrevUrl'] = $_GET['accesscheck'];
}

if (isset($_POST['textfield'])) {
  $loginUsername=$_POST['textfield'];
  $password=$_POST['textfield2'];
  $MM_fldUserAuthorization = "";
  $MM_redirectLoginSuccess = "user/index.php";
  $MM_redirectLoginFailed = "login_deny.php";
  $MM_redirecttoReferrer = true;
  mysql_select_db($database_forsale, $forsale);
  
  $LoginRS__query=sprintf("SELECT Desired_Username, Password FROM login1_table WHERE Desired_Username=%s AND Password=%s",
    GetSQLValueString($loginUsername, "text"), GetSQLValueString($password, "text")); 
   
  $LoginRS = mysql_query($LoginRS__query, $forsale) or die(mysql_error());
  $loginFoundUser = mysql_num_rows($LoginRS);
  if ($loginFoundUser) {
     $loginStrGroup = "";
    
    //declare two session variables and assign them
    $_SESSION['MM_Username'] = $loginUsername;
    $_SESSION['MM_UserGroup'] = $loginStrGroup;	      

    if (isset($_SESSION['PrevUrl']) && true) {
      $MM_redirectLoginSuccess = $_SESSION['PrevUrl'];	
    }
    header("Location: " . $MM_redirectLoginSuccess );
  }
  else {
    header("Location: ". $MM_redirectLoginFailed );
  }
}
?>
and heres the form
<form name="form1" method="POST" action="<?php echo $loginFormAction; ?>">
    <label>Username<br><input name="textfield" type="text" accesskey="l" tabindex="1" size="15"><br></label><label>Password<br><input name="textfield2" type="password" tabindex="2" size="15"><br></label><input type="submit" name="Submit" value="Submit" tabindex="3"></form>


#2 kenrbnsn

kenrbnsn
  • Staff Alumni
  • Advanced Member
  • 8,235 posts
  • LocationHillsborough, NJ, USA

Posted 27 July 2006 - 09:11 PM

What's line 12 of Connections/connection.php? The error message is complaining that this line already sent output to the browser.

Ken

#3 devvie

devvie
  • New Members
  • Pip
  • Newbie
  • 7 posts

Posted 27 July 2006 - 09:28 PM

thats where the bugger comes in, there is no line 12, heres teh complete lines, thats it.  10 lines

<?php
# FileName="Connection_php_mysql.htm"
# Type="MYSQL"
# HTTP="true"
$hostname_forsale = "localhost";
$database_forsale = "db";
$username_forsale = "user";
$password_forsale = "pass";

?>

#4 kenrbnsn

kenrbnsn
  • Staff Alumni
  • Advanced Member
  • 8,235 posts
  • LocationHillsborough, NJ, USA

Posted 27 July 2006 - 09:29 PM

Then you must have blank lines before the "<?php" or after the "?>".

Ken

#5 devvie

devvie
  • New Members
  • Pip
  • Newbie
  • 7 posts

Posted 27 July 2006 - 11:28 PM

you know i read soemthing about a cache limiter recently, and i never activated it(if necessary), or payed any attention it, and i notice that in the error message. could this be it?

BUT, it also says session headers already started, so might i need to do a session destroy or unset first?

#6 kenrbnsn

kenrbnsn
  • Staff Alumni
  • Advanced Member
  • 8,235 posts
  • LocationHillsborough, NJ, USA

Posted 27 July 2006 - 11:47 PM

Did you read the sticky note at the top of this forum entitled "HEADER ERRORS - READ HERE BEFORE POSTING THEM"?

Ken

#7 redarrow

redarrow
  • Members
  • PipPipPip
  • Advanced Member
  • 7,308 posts
  • Locationlondon

Posted 28 July 2006 - 03:20 AM

    if (isset($_SESSION['PrevUrl']) && true) {
      $MM_redirectLoginSuccess = $_SESSION['PrevUrl'];
   
    header("Location: " . $MM_redirectLoginSuccess );
  }
}
  else {
    header("Location: ". $MM_redirectLoginFailed );
  }
}
Wish i new all about php DAM i will have to learn
((EMAIL CODE THAT WORKS))
http://simpleforum.ath.cx/mail2.inc
((PAYPAL INTEGRATION THAT WORKS))
http://simpleforum.a...aypal1_info.inc

#8 devvie

devvie
  • New Members
  • Pip
  • Newbie
  • 7 posts

Posted 28 July 2006 - 06:25 PM

Ken, i wouldnt have understood it completely anyway, but now looking back on it, thanks for the link, becuase it starting to make more sense. I really dont understand  what headers are yet.  I read chapters of php everyday, so its coming more clear, but headers are still mystery for the most part.

redarrow, whats teh code you sent me, it looks like its a direct copy from my page.  can you give a comment with your post?

if (isset($_SESSION['PrevUrl']) && true) {
      $MM_redirectLoginSuccess = $_SESSION['PrevUrl'];
    }
    header("Location: " . $MM_redirectLoginSuccess );
  }
  else {
    header("Location: ". $MM_redirectLoginFailed );
  }
}

#9 akrytus

akrytus
  • Members
  • PipPipPip
  • Advanced Member
  • 70 posts

Posted 28 July 2006 - 06:32 PM

You did this code in dreamweaver?  I had the same problem and the code looks identical to the code that dreamweaver produces.  I played around with it for several hours before I got around it.  Wish I was sweet enough to tell you what I did to fix it.  Chances are though, if I were to do it again, I would run into the same problem!  Let me know how it works out so I know in the future.  Good luck!

#10 Ninjakreborn

Ninjakreborn
  • Members
  • PipPipPip
  • Information Technology Specialist
  • 3,922 posts
  • Age:33

Posted 28 July 2006 - 06:33 PM

THe bottom line is if you have
session_start();
at the first line of code, ther eshould be no reason why it's saying headers already sent.

------

Business Website: http://www.infotechnologist.biz

Personal Website: http://www.joyelpuryear.com

Blog Site: http://www.realmofwriting.com
Services: Web development, application development, mobile development, and custom development. All services listed on my website.


#11 devvie

devvie
  • New Members
  • Pip
  • Newbie
  • 7 posts

Posted 28 July 2006 - 07:20 PM

Akr, i use dreamweaver but i got this code from hotscripts i believe

about that businessman, you notice its NOT the first line of code, its like the 30th.....  look at my php code ont he top of this post.  would you consider the session start to be the first line of code in that example?  if so, then i am really confused.  Or, is that the problem, where the session start shoudl be on LINE1???

#12 Ninjakreborn

Ninjakreborn
  • Members
  • PipPipPip
  • Information Technology Specialist
  • 3,922 posts
  • Age:33

Posted 28 July 2006 - 07:26 PM

No matter what if session_start();
is not LINE 1, ONLY, no other line, no spaces, no text, nothing at all before session_start()
then
error headers already sent, always pop's up at the top of the screen
always cop y and paste session_start() above all pages using sessions.
Preferably in it's own
<?php
session_start();
?> exactly like that before html or anything
if you have any includes, it's best to do them in another island, below the session start code island

------

Business Website: http://www.infotechnologist.biz

Personal Website: http://www.joyelpuryear.com

Blog Site: http://www.realmofwriting.com
Services: Web development, application development, mobile development, and custom development. All services listed on my website.





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users