Page 1 of 1

[SOLVED] session variables not passing to other pages

Posted: Wed Jan 03, 2007 2:31 pm
by arukomp
Hello,

I've finally finished my script and uploaded it to my server. Now what i noticed is that the session variables are not passing to other pages. Everything is written very good, the script works perfect on my computer with xampp.

Maybe someone knows what the problem could be? I had a look at phpinfo of the server, session support is enabled.

Also, i looked at session_start() function. It says "session_start() creates a session or resumes the current one based on the current session id that's being passed via a request, such as GET, POST, or a cookie.". Now how do i pass session id? Maybe that would help?

Thanks a lot for your help

Posted: Wed Jan 03, 2007 2:45 pm
by Kieran Huggins
Try doing a phpinfo() and see what it says about sessions...

I've never had a problem using session_start() and the $_SESSION array.

Posted: Wed Jan 03, 2007 3:05 pm
by kingconnections
hmmm- You don't have to do anything to pass the session variables, they are just on. You access them on the next page.

ie:

Code: Select all

echo "$_SESSION['your var here']";

Posted: Wed Jan 03, 2007 6:28 pm
by volka
What does phpinfo() say about the following parameters
System
Server API
error_reporting
display_errors
session.use_cookies
session.save_path
?

Posted: Wed Jan 03, 2007 7:15 pm
by RobertGonzalez
This might also be helpful for us to know, so if you can, run the following in a new file and tell us the results please.

Code: Select all

<?php

$neg = array('off', 0, false, '', null);
$flags = array(
	'Register Globals' => 'register_globals',
	'Short Tags' => 'short_open_tag',
	'Display Errors' => 'display_errors',
	'Magic Quotes GPC' => 'magic_quotes_gpc',
	'Magic Quotes Runtime' => 'magic_quotes_runtime',
	'Magic Quotes Sybase' => 'magic_quotes_sybase',
);
$ve = phpversion();
$os = PHP_OS;
$er = intval(error_reporting());
foreach ($flags as $n => $v)
{
	$flags[$n] = (in_array(strtolower(ini_get($v)), $neg) ? 'Off' : 'On');
}
$cli = (php_sapi_name() == 'cli');
$eol = "\n";

$gle = get_loaded_extensions();
$rows = array();
$le = '';
$wide = 4;
$j = count($gle);
$pad = $wide - $j % $wide;
$len = max(array_map('strlen', $gle));
$func = create_function('$a', 'return str_pad($a, ' . intval($len) . ');');
$gle = array_map($func, $gle);
for($i = 0; $i < $j; $i += $wide)
{
	$le .= '   ' . implode('   ', array_slice($gle, $i, $wide)) . $eol;
}

$ec = array(
	'E_STRICT' => 2048, 'E_ALL' => 2047, 'E_USER_NOTICE' => 1024,
	'E_USER_WARNING' => 512, 'E_USER_ERROR' => 256, 'E_COMPILE_WARNING' => 128,
	'E_COMPILE_ERROR' => 64, 'E_CORE_WARNING' => 32, 'E_CORE_ERROR' => 16,
	'E_NOTICE' => 8, 'E_PARSE' => 4, 'E_WARNING' => 2, 'E_ERROR' => 1,
);

$e = array();
$t = $er;
foreach ($ec as $n => $v)
{
	if (($t & $v) == $v)
	{
		$e[] = $n;
		$t ^= $v;
	}
}
if (ceil(count($ec) / 2) + 1 < count($e))
{
	$e2 = array();
	foreach ($ec as $n => $v)
	{
		if (!in_array($n, $e) and $n != 'E_ALL')
		{
			$e2[] = $n;
		}
	}
	$er = $er . ' ((E_ALL | E_STRICT) ^ ' . implode(' ^ ', $e2) . '))';
}
else
{
	$er = $er . ' (' . implode(' | ', $e) . ')';
}

if (!$cli)
{
	echo '<html><head><title>quick info</title></head><body><pre>', $eol;
}

echo 'PHP Version: ', $ve, $eol;
echo 'PHP OS: ', $os, $eol;
echo 'Error Reporting: ', $er, $eol;
foreach ($flags as $n => $v)
{
	echo $n, ': ', $v, $eol;
}
echo 'Loaded Extensions:', $eol, $le, $eol;

if (!$cli)
{
	echo '</pre></body></html>', $eol;
}

?>

Posted: Thu Jan 04, 2007 3:49 am
by arukomp
Everah wrote:This might also be helpful for us to know, so if you can, run the following in a new file and tell us the results please.
The results:

Code: Select all

PHP Version: 4.4.1
PHP OS: FreeBSD
Error Reporting: 2039 ((E_ALL | E_STRICT) ^ E_STRICT ^ E_NOTICE))
Register Globals: On
Short Tags: On
Display Errors: On
Magic Quotes GPC: On
Magic Quotes Runtime: Off
Magic Quotes Sybase: Off
Loaded Extensions:
   xslt             xmlrpc           xml              wddx          
   tokenizer        standard         sockets          session       
   pspell           posix            pcre             overload      
   mysql            ming             mhash            mcrypt        
   mbstring         imap             iconv            gettext       
   gd               ftp              exif             domxml        
   curl             ctype            calendar         bz2           
   bcmath           zlib             openssl          apache        
   Zend Optimizer
The server I'm running the script on is StartLogic.com

I've putted session_start() in the very first line of the script. I put $_GET['ref'] variable into $_SESSION['ref'] at the beginning of the script. At the end of the script i echo that $_SESSION['ref'] and it shows what it should show. Now when going to another page, $_GET['ref'] is not set, so i don't make any changes to $_SESSION['ref']. At the end of the second page, the script echoes empty space, like "ref: " and it should be like "ref: 3".

Posted: Thu Jan 04, 2007 4:14 am
by arukomp
volka wrote:What does phpinfo() say about the following parameters
System
Server API
error_reporting
display_errors
session.use_cookies
session.save_path
?
Here it is:

http://www.abtrix.com/new2/test.php

Posted: Thu Jan 04, 2007 4:30 am
by dude81
Can you try session_autostart=on in /etc/php.ini?? I guess it can help

Posted: Thu Jan 04, 2007 4:37 am
by arukomp
I don't know if i can try... It's a shared server, so i can't change anything.

It seems I've wrote something wrong what didn't work well on the server. I changed some code.

I changed this code:

Code: Select all

$ref = $_GET['r'];
if ($ref != "") {
	$_SESSION['ref'] = $ref;
}
Into this:

Code: Select all

if (!empty($_GET['r'])) {
	$_SESSION['ref'] = $_GET['r'];
}
Now it's working very well :)

Posted: Thu Jan 04, 2007 7:52 am
by wildwobby
arukomp wrote:I don't know if i can try... It's a shared server, so i can't change anything.

It seems I've wrote something wrong what didn't work well on the server. I changed some code.

I changed this code:

Code: Select all

$ref = $_GET['r'];
if ($ref != "") {
	$_SESSION['ref'] = $ref;
}
Into this:

Code: Select all

if (!empty($_GET['r'])) {
	$_SESSION['ref'] = $_GET['r'];
}
Now it's working very well :)
I've heard it was better practice to use isset() instead of !empty()

Posted: Thu Jan 04, 2007 8:46 am
by onion2k
wildwobby wrote:I've heard it was better practice to use isset() instead of !empty()
They're not really the same thing. A variable can be set and be empty at the same time.

Posted: Thu Jan 04, 2007 10:36 am
by RobertGonzalez
I always suggest checking whether a variable is set first, then checking if it is empty. But that is just me.