I have three files: login.php, index.php, summary.php. All my session variables are set when user visits login.php. Below is my code snippet:
<?php
if( isset($_POST['submit']) )
{
$username = $_POST['username'];
$password = $_POST['password'];
$_SESSION['username'] = $username;
if(!($con = ssh2_connect('192.168.1.7', 22))){
echo "<script> alert(\"Fail: Unable to establish connection\"); </script>";
}
else {
if(!ssh2_auth_password($con, $username , $password )) {
echo "<script> alert(\"Fail: Unable to authenticate\"); </script>";
}
else {
//echo "<script> alert(\"Successfully logged in\"); </script>";
$_SESSION['con'] = $con;
header("Location: index.php");
//echo $_SESSION['con'];
}
}
}
?>
When I print my session variable $_SESSION['con']
in login.php, it prints Resource ID#1 as expected. Below is my index.php file which uses both the session variables.
<?php
session_start();
echo $_SESSION['username'];
echo $_SESSION['con'];
?>
When I print the session variables in index.php, $_SESSION['username']
gives me the correct output but $_SESSION['con']
prints 0
which was supposed to print Resource ID#1. That is, session variable con
's value has been changed to zero.