..(another) .. session question

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Fari
Forum Commoner
Posts: 42
Joined: Thu Sep 19, 2002 8:41 pm
Location: Timmins - Ontario

..(another) .. session question

Post 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
User avatar
hob_goblin
Forum Regular
Posts: 978
Joined: Sun Apr 28, 2002 9:53 pm
Contact:

Post by hob_goblin »

gilliepit
Forum Newbie
Posts: 9
Joined: Sat Oct 12, 2002 12:52 pm
Location: usa.sc.cola
Contact:

Post 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
Last edited by gilliepit on Sun Oct 13, 2002 2:27 pm, edited 1 time in total.
Coco
Forum Contributor
Posts: 339
Joined: Sat Sep 07, 2002 5:28 am
Location: Leeds, UK
Contact:

Post 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
Post Reply