views:

59

answers:

2

hello

I have this code in a function

$_SESSION['id'] = $id;
$_SESSION['pineapple'] = $hashbrown;
$_SESSION['username'] = $username;

However, the session data never gets set, even on the initial page. Can sessions be edited though a function or not?

info on cookies/ect

this is the code for starting the session

<!-- a bunch of info about versions and build goals ect -->
<?php include "loader.php";?>
<!--some more comments -->

loader.php

<?php
// Load Core functions and initalise enviroment
session_start();
include "../music/php/logic/core.php";
include "../music/php/logic/secure.php";
include "../music/php/logic/forms.php";
openDatabase ($set_host, $set_username, $set_password, $set_database);
$core = getCoreSettings ($set_prefix);
and so on...

loader.php initalises everything and includes the right page script.

I don't set any cookies explicitly, and this is what print_r($_COOKIE); produces:

 [SQLiteManager_currentLangue] => 2
+8  A: 

Can sessions be edited though a function or not?

Yes they can, $_SESSION is a superglobal.

Have you initialized a session using session_start()?

Pekka
yes in a word. I'll have to step though the whole process and check the conditions I think.
YsoL8
Strange. Does the session really get created? Are you getting a session file in the temp directory? I think you can find out the directory in `phpinfo()`.
Pekka
as in a file with an extension?
YsoL8
@YsoL8 for each session, a file will be created in the `session.save_path` directory, usually the temp directory. It contains the actual session data. I don't know whether it has an extension or not, I think it hasn't.
Pekka
I have four or five files in the folder indicated in phpinfo. I am getting a value set for session id in a separate function - although that is recycled on every reload so it isn't clear that the value itself is persisting. I'll try a striped down version of this function and see what happens.
YsoL8
OK I made a function that just sets some session values. These new values are only reflected in print_r($_SESSION); if the function is called beforehand in the script. This appears to indicate that the session is only being remembered for the duration of that page load. I'll add phpinfo's session report to the question
YsoL8
Can you show the code you use to start the session with? Do you get a session cookie in the bworser? What is its lifetime?
Pekka
I did some more checks and the problem is resolved. Thanks for all the help!
YsoL8
@YsoL8 you're welcome. What was it in the end?
Pekka
I found a hole in my data flow that meant the session data is created after it is used in the problem code. So I need to rearrange the code so close that gap.
YsoL8
A: 

You should call session_start() in each of your PHP scripts, where $_SESSION array uses

582