Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Cannot send session cookie / Cannot send session cache limiter 2

Status
Not open for further replies.

DoubleV

Programmer
Jan 11, 2002
358
US
don't know if php.ini settings are important here, but i'll include them anyway (the ones i think might be relevant):
session.save_handler = files
session.use_cookies = On
session.save_path = /tmp

then, i have 2 files, hello.php4
Code:
#!/usr/local/bin/php4 

<?php include 'accesscontrol.php4'; ?> 
<!DOCTYPE html PUBLIC &quot;-//W3C/DTD XHTML 1.0 Transitional//EN&quot; 
  &quot;[URL unfurl="true"]http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd&quot;>[/URL] 
<html xmlns=&quot;[URL unfurl="true"]http://www.w3.org/1999/xhtml&quot;>[/URL] 
<head> 
  <title> Members-Only Page </title> 
  <meta http-equiv=&quot;Content-Type&quot; 
    content=&quot;text/html; charset=iso-8859-1 
</head> 
<body> 
<p>Hello, <?=$username?>! You have entered a members-only area 
   of the site. Don't you feel special?</p> 
</body> 
</html>

and accesscontrol.php4 :
Code:
#!/usr/local/bin/php4 

<?php // accesscontrol.php 

session_start(); 

$uid = isset($_POST['uid']) ? $_POST['uid'] : $_SESSION['uid']; 
$pwd = isset($_POST['pwd']) ? $_POST['pwd'] : $_SESSION['pwd']; 

if(!isset($uid)) { 
  ?> 
  <!DOCTYPE html PUBLIC &quot;-//W3C/DTD XHTML 1.0 Transitional//EN&quot; 
    &quot;[URL unfurl="true"]http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd&quot;>[/URL] 
  <html xmlns=&quot;[URL unfurl="true"]http://www.w3.org/1999/xhtml&quot;>[/URL] 
  <head> 
    <title> Please Log In for Access </title> 
    <meta http-equiv=&quot;Content-Type&quot; 
      content=&quot;text/html; charset=iso-8859-1&quot; /> 
  </head> 
  <body> 
  <h1> Please Sign In: </h1> 
  <p>You must log in to access this area of the site. If you are 
     not a registered user, <a href=&quot;signup.php&quot;>click here</a> 
     to sign up for instant access!</p> 
  <p><form method=&quot;post&quot; action=&quot;<?=$_SERVER['PHP_SELF']?>&quot;> 
    User ID: <input type=&quot;text&quot; name=&quot;uid&quot; /><br /> 
    Password: <input type=&quot;password&quot; name=&quot;pwd&quot; /><br /> 
    <input type=&quot;submit&quot; value=&quot;Sign In&quot; /> 
  </form></p> 
  </body> 
  </html> 
  <?php 
  exit; 
} 

$_SESSION['uid'] = $uid; 
$_SESSION['pwd'] = $pwd; 

if ($pwd != &quot;hello&quot; ) { 
  unset($_SESSION['uid']); 
  unset($_SESSION['pwd']); 
  ?> 
  <!DOCTYPE html PUBLIC &quot;-//W3C/DTD XHTML 1.0 Transitional//EN&quot; 
    &quot;[URL unfurl="true"]http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd&quot;>[/URL] 
  <html xmlns=&quot;[URL unfurl="true"]http://www.w3.org/1999/xhtml&quot;>[/URL] 
  <head> 
    <title> Access Denied </title> 
    <meta http-equiv=&quot;Content-Type&quot; 
      content=&quot;text/html; charset=iso-8859-1&quot; /> 
  </head> 
  <body> 
  <h1> Access Denied </h1> 
  <p>Your user ID or password is incorrect, or you are not a 
     registered user on this site. To try logging in again, click 
     <a href=&quot;<?=$_SESSION['PHP_SELF']?>&quot;>here</a>. To register for instant 
     access, click <a href=&quot;signup.php&quot;>here</a>.</p> 
  </body> 
  </html> 
  <?php 
  exit; 
} 

$username = $uid; 
?>

the header (#!/usr/local/bin/php4) has to be there per host's instructions.

it's long to explain why i'm only checking for a set password, so let's leave that out of the discussion for now.

when i run hello.php4 the error message i get is

#!/usr/local/bin/php4
Warning: Cannot send session cookie - headers already sent by (output started at /cgi/hello.php4:2) in /cgi/accesscontrol.php4 on line 5

Warning: Cannot send session cache limiter - headers already sent (output started at /cgi/hello.php4:2) in /cgi/accesscontrol.php4 on line 5


line 5 of accesscontrol.php4 is session_start();

so how do i get tjis fixed?

--------------------------------------------------
Goals are dreams with deadlines
-------------------------------------
 
Your problem relates to the additional line before the PHP code. The line is sent which means that PHP can't send any headers or cookies.

What happens if you remove the line?
What does the host have to say, since this makes it impossible the use sessions?
 
You have a blank line between the shebang and the start of your PHP script. Try removing it.

//Daniel
 
DRJ478,
if I remove &quot;#!/usr/local/bin/php4&quot; from accesscontrol.php4, i still get the same thing, just without the &quot;#!/usr/local/bin/php4&quot; part:
Code:
Warning: Cannot send session cookie - headers already sent by (output started at /cgi/hello.php4:2) in /cgi/accesscontrol.php4 on line 3

Warning: Cannot send session cache limiter - headers already sent (output started at /cgi/hello.php4:2) in /cgi/accesscontrol.php4 on line 3

if I remove it from hello.php4, then i get a 500 error:
Code:
500 Server Error
The server encountered an internal error or misconfiguration and was unable to complete your request.
Error: HTTPd: malformed header from script /cgi/hello.php4

so should i be calling my host?

--------------------------------------------------
Goals are dreams with deadlines
-------------------------------------
 
danielhozac has the solution:

The # needs only to be in the file that starts the php execution. Included files don't need it.
Also, the additional line before the <? needs to go.
 
thanks - it did the trick (removing the shebang)!
gee, i never knew what that thingy is called. (where are the smilies in this forum??? i need a blushing one)

--------------------------------------------------
Goals are dreams with deadlines
-------------------------------------
 
ok guys,
i think i need a nother pair of eyes this time. it was working and now i messed it up, but not sure where!

hello.php4
Code:
#!/usr/local/bin/php4
<?php include 'accesscontrol.php4'; ?>
<!DOCTYPE html PUBLIC &quot;-//W3C/DTD XHTML 1.0 Transitional//EN&quot;
  &quot;[URL unfurl="true"]http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd&quot;>[/URL]
<html xmlns=&quot;[URL unfurl="true"]http://www.w3.org/1999/xhtml&quot;>[/URL]
<head>
  <title> Members-Only Page </title>
  <meta http-equiv=&quot;Content-Type&quot;
    content=&quot;text/html&quot;; charset=iso-8859-1
</head>
<body>
<p>Hello, <?=$HTTP_COOKIE_VARS[&quot;remember_uid&quot;]?>! You have entered a members-only area
   of the site. Don't you feel special?</p>
<p>
<?php
echo $HTTP_COOKIE_VARS[&quot;remember_uid&quot;] . '<br>';
echo $HTTP_COOKIE_VARS[&quot;remember_pwd&quot;] . '<br>';
echo $HTTP_COOKIE_VARS[&quot;remember_email&quot;] . '<br>';
session_unregister(&quot;uid&quot;);
session_unregister(&quot;pwd&quot;);
session_destroy();
?>
</body>
</html>


accesscontrol.php4
Code:
<?php
session_start();
$uid = isset($_POST['uid']) ? $_POST['uid'] : $_SESSION['uid'];
$pwd = isset($_POST['pwd']) ? $_POST['pwd'] : $_SESSION['pwd'];
$email = isset($_POST['email']) ? $_POST['email'] : $_SESSION['email'];

if(!isset($uid)) {
?>
	<!DOCTYPE html PUBLIC &quot;-//W3C/DTD XHTML 1.0 Transitional//EN&quot; &quot;[URL unfurl="true"]http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd&quot;>[/URL]
  <html xmlns=&quot;[URL unfurl="true"]http://www.w3.org/1999/xhtml&quot;>[/URL]
  <head>
  	<title> Please Log In for Access </title>
    <meta http-equiv=&quot;Content-Type&quot; content=&quot;text/html&quot;; charset=iso-8859-1&quot; />
    <script language=&quot;javascript&quot; type=&quot;text/javascript&quot; src=&quot;/web/test/frm_highlight.js&quot;></script>
    <link rel=&quot;stylesheet&quot; type=&quot;text/css&quot; href=&quot;/web/test/style.css&quot;>
  </head>
  <body>
  <h1> Please Sign In: </h1>
  <p>You must log in to access this area of the site.</p>
  <p>
  <form method=&quot;post&quot; action=&quot;<?=$_SERVER['PHP_SELF']?>&quot;>
  <table border=&quot;0&quot;>
  <tr>
  	<td>Name: </td>
  	<td><input type=&quot;text&quot; name=&quot;uid&quot; />
  </tr>
  <tr>
  	<td>Company Name: </td>
  	<td><input type=&quot;text&quot; name=&quot;co_name&quot; />
  </tr>	
  <tr>
  	<td>Email: </td>
  	<td><input type=&quot;text&quot; name=&quot;email&quot; />
  </tr>	
  <tr>
  	<td>Password: </td>
  	<td><input type=&quot;text&quot; name=&quot;pwd&quot; />
  </tr>
  <tr>
  	<td colspan=&quot;2&quot;><input type=&quot;submit&quot; value=&quot;Sign In&quot; name=&quot;submit&quot; id=&quot;submit&quot; />
  </tr>
  </table>
  </form></p>
  </body>
  </html>
  <?php
  exit;
}

$_SESSION['uid'] = $uid;
$_SESSION['pwd'] = $pwd;

if ($pwd != &quot;hello&quot;) {
  unset($_SESSION['uid']);
  unset($_SESSION['pwd']);
  ?>
  <!DOCTYPE html PUBLIC &quot;-//W3C/DTD XHTML 1.0 Transitional//EN&quot;
    &quot;[URL unfurl="true"]http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd&quot;>[/URL]
  <html xmlns=&quot;[URL unfurl="true"]http://www.w3.org/1999/xhtml&quot;>[/URL]
  <head>
    <title> Access Denied </title>
    <meta http-equiv=&quot;Content-Type&quot;
      content=&quot;text/html; charset=iso-8859-1&quot; />
  </head>
  <body>
  <h1> Access Denied </h1>
  <p>Your user ID or password is incorrect, or you are not a
     registered user on this site. To try logging in again, click
     <a href=&quot;<?=$_SESSION['PHP_SELF']?>&quot;>here</a>.</p>
  </body>
  </html>
  <?php
  exit;
}

$expiry = 60*60*24*365;	// 365 days

setcookie('remember_uid', $uid, time()+$expiry, &quot;/&quot; );
setcookie('remember_pwd', $pwd, time()+$expiry, &quot;/&quot; );
setcookie('remember_email', $email, time()+$expiry, &quot;/&quot; );
?>

i get the 500 error again
Code:
500 Server Error
The server encountered an internal error or misconfiguration and was unable to complete your request.

Please contact the server administrator, [URL unfurl="true"]www@www.orbusinc.com[/URL] and inform them of the time the error occurred , and anything you might have done that may have caused the error.

Error: HTTPd: malformed header from script /cgi/hello.php4

--------------------------------------------------
Goals are dreams with deadlines
-------------------------------------
 
sleipnir,
i do not think that's the root of the problem.
actually, it is totally bizzare! it just seems to be random. for example, i close the browser window. open it again, access the page get the above error. refresh and suddenly get the actual login screen. then i refreshed the login screen several times and suddenly i get the error agin.
i have no idea if it's php, a server or what else, 'cause i absolitely cannot spot what's wrong.



--------------------------------------------------
Goals are dreams with deadlines
-------------------------------------
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top