Dániel Bencze Dániel Bencze - 1 year ago 54
PHP Question

PHP Session variables not passing but the session ids are the same

** SOLVED ** - Server Problem

As mentioned above, the session ids are the same on both pages but I can't access to the session variables. I need Session for a bigger project I created this to test it. I don't have any Idea why since the ids are the same.

First page:

<?php session_start();
echo "session started"
?>
<!DOCTYPE html>
<html>
<body>

<?php
// Set session variables
$_SESSION["favcolor"] = "green";
$_SESSION["favanimal"] = "cat";
echo "Session variables are set.";
echo "<br>";
print_r(session_id());
echo "<br>";
echo "<a href='use.php'>Display</a>"
?>

</body>
</html>


Second Page:

<?php session_start();
?>
<!DOCTYPE html>
<html>
<body>

<?php
// Echo session variables that were set on previous page
echo "Favorite color is " . $_SESSION["favcolor"] . ".<br>";
echo "Favorite animal is " . $_SESSION["favanimal"] . ".";
echo "<br>";
print_r(session_id());
?>

</body>
</html>

Answer Source

For those with the same problem: The problem was that the server( University project server which requires your uni login) required a login to access any file. That login started a session. When I wanted to start another session it just didn't worked. Solution you should use a server which is not requiring a login and than you can start your own session.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download