HELP! Session cannot pass to another page after redirecting.

Please help! I am experiencing this annoying problem with session. My session variable which I made in test1.php cannot pass to test2.php after redirecting. I am completely new to web programming so please lead me to solve this one. I have read different threads with same issue, some say it might be on session.save_path configuration so I went to php.ini file and then it is noted there under sessionsavepath or sessionhandler (im not so sure) that For Windows users: this must be changed to use session’s function. What does that mean?

Here’s my code so far:
test1.php

<?php session_start(); $_session['sol']="Session is now working."; header('location: test2.php'); session_write_close(); ?>

test2.php

<?php session_start(); echo $_session['sol']; // this gives an error. It says Notice: Undefined variable: _session in C:\xammp\htdocs\test2.php on line 3 ?>

Any answer would be appreciated. :frowning:

The array you are looking for is $_SESSION, not $_session. While being a loosely typed language is still case sensitive.

From $_session I changed it to $_SESSION and I have this error:

Undefined index: sol in C:\xampp\htdocs\Ftest2.php on line 3

Any required modification on php.ini? Some threads mention about permission thingy. Pleeeease sir.

On test2.php do this,

[php]<?php
session_start();

$_SESSION[‘a’] = ‘a’;
$_SESSION[‘b’] = ‘b’;
$_SESSION[‘c’] = ‘c’;
echo “

”;
print_r( $_SESSION );
echo “
”;[/php]

See what shows.

With what you said, I have this output:

Array
(
[a] => a
[b] => b
[c] => c
)

Remove this,

session_write_close();

You are prematurely closing the session.

Just got it working without removing that session_write_close(). I just don’t have idea why. It starts working when I run the xampp control panel as an admin and then I did some modification on php.ini specifically session.cookie_sesure and session.gc something. Anyways, thank you so much aero. :smiley: really appreciated your guidance.

Sponsor our Newsletter | Privacy Policy | Terms of Service