Page 1 of 1

..(another) .. session question

Posted: Sun Oct 13, 2002 1:15 pm
by Fari
Hi there!

I'm trying to register 3 variables in a session to be used for DB access through a number of pages/scripts. These ($login_1, $pwd_1 and $server-1) are passed with a POST operation from the login script to this script. This is what the script looks like:

Code: Select all

<?php 
  include 'includes.php';
  session_register('login');   //this is line 9 in the script!!!
  session_register('pwd'); 
  session_register('server'); 
   $login=$login_1;
   $pwd = $pwd_1;
   $server = $server_1;
....
for which the browser returns the following error message:

Code: Select all

Warning: Cannot send session cookie - headers already sent by (output started at c:\program files\apache group\apache\htdocs\test\main_2.php:7) in c:\program files\apache group\apache\htdocs\test\main_2.php on line 9

Warning: Cannot send session cache limiter - headers already sent (output started at c:\program files\apache group\apache\htdocs\test\main_2.php:7) in c:\program files\apache group\apache\htdocs\test\main_2.php on line 9

Warning: open(C:\Program Files\PHP\sessiondata\sess_3ef61267c3cd66e0961e4dccbe8ac993, O_RDWR) failed: No such file or directory (2) in c:\program files\apache group\apache\htdocs\test\main_2.php on line 9

Notice: Undefined variable: server_1 in c:\program files\apache group\apache\htdocs\test\main_2.php on line 14
any ideas why??? It may have to do with the php.ini file... Help will be appreciated

Posted: Sun Oct 13, 2002 1:31 pm
by hob_goblin

Posted: Sun Oct 13, 2002 2:21 pm
by gilliepit
You may want to try two things.. I'm sorta new to php, though this should help a little.

First make sure that your "session.save_path" in your php.ini file has been set to the location where you would like sessions data to be saved. There is also a cookies 1/0 toggle that you may want to check as well.

Secondly, lets try and pull all your registered session variables into another file (this isn't necisarry, it will, however, help you pinpoint your problems)

In file a new file called sessionstart.php, copy the following code:

Code: Select all

<?
  session_start();

  $_SESSION&#1111;"firstname"]="Jason";
  $_SESSION&#1111;"lastname"]="Johnson";
  
  Header("Location: sessionoutput.php");
?>
and in sessionoutput.php, copy the following code:

Code: Select all

<? session_start(); ?>

<table>
  <tr>
    <td>First Name: <? print($_SESSION&#1111;"firstname"]);?></td>
  </tr>
  <tr>
    <td>Last Name: <? print($_SESSION&#1111;"lastname"]);?></td>
  </tr>
  <tr>
    <td><? print session_id(); ?></td>
  </tr>
</table>
That works on my box, all you need to do is access "sessionstart.php" and it should redirect you to sessionoutput.php.. place them in the same folder on your server.. if that doesn't work, email me and I'll walk you through something else.

Yes, it's very simple, but this will allow you to figure out those errors. Hope I've been of some use to you. Maybe someone else will have something to say about my code that will help you even more :D

Posted: Sun Oct 13, 2002 2:24 pm
by Coco
try putting all your session bits before the include?
the error is telling you that the include has done something that prevents you from sending cookies blah blah