[SOLVED] session variables not passing to other pages
Moderator: General Moderators
[SOLVED] session variables not passing to other pages
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
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
Last edited by arukomp on Thu Jan 04, 2007 4:31 am, edited 1 time in total.
- Kieran Huggins
- DevNet Master
- Posts: 3635
- Joined: Wed Dec 06, 2006 4:14 pm
- Location: Toronto, Canada
- Contact:
-
kingconnections
- Forum Contributor
- Posts: 137
- Joined: Thu Jul 14, 2005 4:28 pm
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:
ie:
Code: Select all
echo "$_SESSION['your var here']";- RobertGonzalez
- Site Administrator
- Posts: 14293
- Joined: Tue Sep 09, 2003 6:04 pm
- Location: Fremont, CA, USA
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;
}
?>The results: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.
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 OptimizerI'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".
Here it is:volka wrote:What does phpinfo() say about the following parameters
System
Server API
error_reporting
display_errors
session.use_cookies
session.save_path
?
http://www.abtrix.com/new2/test.php
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:
Into this:
Now it's working very well 
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;
}Code: Select all
if (!empty($_GET['r'])) {
$_SESSION['ref'] = $_GET['r'];
}I've heard it was better practice to use isset() instead of !empty()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:
Into this:Code: Select all
$ref = $_GET['r']; if ($ref != "") { $_SESSION['ref'] = $ref; }
Now it's working very wellCode: Select all
if (!empty($_GET['r'])) { $_SESSION['ref'] = $_GET['r']; }
- RobertGonzalez
- Site Administrator
- Posts: 14293
- Joined: Tue Sep 09, 2003 6:04 pm
- Location: Fremont, CA, USA