I have a login page which sets a _SESSION parameter of 'id' upon login. After logging in the user is redirected to the index.php page and at this point the session parameter is still set, I know this because I can print it with PHP. However, when navigating to the account.php page the parameter is lost and I am not sure why.
Most of the other questions asked on here regarding this are because of the session_start not being used but I have used this on the account.php page.
Any help in resolving this would be grateful.
The code for the account.php page is below:
<?php session_start(); ?>
<?php
$con=mysqli_connect("localhost","tkernick96","Tylerkernick1996","users");
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$id = $_SESSSION['id'];
$query = mysqli_query($con,"SELECT * FROM users WHERE id = $id");
$row = mysqli_fetch_array($query,MYSQLI_ASSOC);
$firstname = $row ['firstname'];
$lastname = $row ['lastname'];
$email = $row ['email'];
$age = $row ['age'];
$nationality = $row ['nationality'];
$language1 = $row ['language1'];
$language2 = $row ['language2'];
$language3 = $row ['language3'];
$language4 = $row ['language4'];
$language5 = $row ['language5'];
$form = "<div id='header'>
<img src='logo.png' id='logo'>
<div id='headerdiv'>
<table id='login'>
<tr>
<td style='padding-right: 20px;'>
<h2 style='margin-top: 0px'>No account?</h2>
<h3 style='margin-top: 0px'><a href='signup.php'>Sign Up Now!</a></h3>
</td>
<td style='padding-left: 20px; border-left: 1px solid #838383'>
<h3>Login:</h3>
<form method='post' action='login.php'>
<input id='logininput' type='email' name='email' placeholder='Email'>
<br>
<input id='logininput' type='password' name='password' placeholder='Password'>
<input type='submit' name='login' value='Login'>
</form>
<p id='p1'><a href='forgotdetails.php'>Forgotten Details?</a></p>
</td>
</tr>
</table>
</div>
</div>";
$account = "<div id='header'>
<img src='logo.png' id='logo'>
<div id='headerdiv'>
<table id='accounttable'>
<tr>
<td id='account'>
<p id='p2'><a href='account.php'>My Account</a></p>
<p id='p2'><a href='account/companions.php'>My Companions</a></p>
<p id='p2'><a href='account/messages.php'>Messages(".$messages.")</a></p>
<p id='p2'><a href='logout.php'>Sign Out</a></p>
</td>
</tr>
</table>
</div>
</div>
<table id='profiletable'>
<tr>
<td id='profiletabletd1' rowspan='2'>
<img src='images/avatar.png' id='profileimage'>
</td
<td id='profiletabletd1'><p id='profilename'>".$firstname." ".$lastname.", ".$age."</p></td>
</tr>
<tr>
<td id='profiletabletd3'><p id='profileinfo'>Nationality: <b>".$nationality."</b>     Languages Spoken: <b>".$language1." ".$language2." ".$language3." ".$language4." ".$language5."</b></p></td>
</tr>
</table>
";
if ($id == "") {
$output = $form;
}
else {
$output = $account;
}
mysqli_close($con);
?>
index.php:
<?php session_start(); ?>
<?php
$con=mysqli_connect("localhost","tkernick96","Tylerkernick1996","users");
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$id = $_SESSION['id'];
$form = "<table id='login'>
<tr>
<td style='padding-right: 20px;'>
<h2 style='margin-top: 0px'>No account?</h2>
<h3 style='margin-top: 0px'><a href='signup.php'>Sign Up Now!</a></h3>
</td>
<td style='padding-left: 20px; border-left: 1px solid #838383'>
<h3>Login:</h3>
<form method='post' action='login.php'>
<input id='logininput' type='email' name='email' placeholder='Email'>
<br>
<input id='logininput' type='password' name='password' placeholder='Password'>
<input type='submit' name='login' value='Login'>
</form>
<p id='p1'><a href='forgotdetails.php'>Forgotten Details?</a></p>
</td>
</tr>
</table>";
$account = "<table id='accounttable'>
<tr>
<td id='account'>
<p id='p2'><a href='account.php'>My Account</a></p>
<p id='p2'><a href='account/companions.php'>My Companions</a></p>
<p id='p2'><a href='account/messages.php'>Messages($messages) </a></p>
<p id='p2'><a href='logout.php'>Sign Out</a></p>
</td>
</tr>
</table>";
if ($id == "") {
$output = $form;
}
else {
$output = $account;
}
mysqli_close($con);
?>