Jump to content

[SOLVED] Problem getting Sessions working


benn600

Recommended Posts

I cannot get sessions working on my PHP install.  It's Apache with PHP.

 

If I create the two files as shown here: http://www.php.net/manual/en/function.session-start.php

 

Nothing shows up on page2 as I think it should.  I am making a small site, also, where I want to use sessions and they do not appear to be working.  What may be wrong?

Link to comment
https://forums.phpfreaks.com/topic/77260-solved-problem-getting-sessions-working/
Share on other sites

Absolutely, sessions are enabled.

 

session

Session Support enabled

Registered save handlers files user

Registered serializer handlers php php_binary wddx

 

Here are the two pages (directly copied from above link)

http://ppcpathways.com/page1.php

http://ppcpathways.com/page2.php

 

<?php

// page1.php

 

session_start();

 

echo 'Welcome to page #1';

 

$_SESSION['favcolor'] = 'green';

$_SESSION['animal']  = 'cat';

$_SESSION['time']    = time();

 

// Works if session cookie was accepted

echo '<br /><a href="page2.php">page 2</a>';

 

// Or maybe pass along the session id, if needed

echo '<br /><a href="page2.php?' . SID . '">page 2</a>';

print '<br /><br />AND here is PHP info';

phpInfo();

?>

 

 

<?php

// page2.php

 

session_start();

 

echo 'Welcome to page #2<br />';

 

echo $_SESSION['favcolor']; // green

echo $_SESSION['animal'];  // cat

echo date('Y m d H:i:s', $_SESSION['time']);

 

// You may want to use SID here, like we did in page1.php

echo '<br /><a href="page1.php">page 1</a>';

?>

try making a new script,

try this:

 

page1.php

<?php
session_start();

$_SESSION['test'] = 'It Worked!';
echo '<a href="page2.php">page2</a>';

?>

 

page2.php

<?php
session_start();

if(!isset($_SESSION['test'])){
echo 'It\'s not working....';
} else{
echo $_SESSION['test'];
}

?>

 

that should work,

if it doesnt,

that i really have no idea whats wrong....

Thanks for your help.  I decided to reinstall.  I installed the latest but got an error code.  So I tried the one I had before, and again got an error!  So I downloaded the zip.  Then I unzipped it and installed.  Sessions started working but MySQL didn't.  I compared my previous and new php.ini files and found the problem.  It turns out changing allow_call_time_pass_reference fixed it for me.

 

ALL GOOD NOW!

 

I'm building a Christmas Wish List application for my family.  Should be interesting.  Thanks!

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.