<?php
if(!isset($_SESSION['c_id']) || (!isset($_SESSION['s_id'])))
{
?>
Login/Register
<ul>
<li>
<a href="register.php">
Student Login
</a>
</li>
<li>
<a href="register.php">
Student Registration
</a>
</li>
<li>
<a href="company_register.php"">
Company Login
</a>
</li>
<li>
<a href="company_register.php">
Company Registration
</a>
</li>
</ul>
</li>
<?php
}
else
{
?>
<a href="logout_exec.php>Logout
</a>
</li>
<?php
}
?>
</ul>
This is my code snippet,
When the user is logged in, even then Logout
is not being displayed, as clear from the post if the SESSION IDs are not set means the user is not logged in, in that case the content pertaining to that condition is being displayed however not the other way round
The login_exec.php file
include ("db_conn.php");
function clean_input($data)
{
$data = stripslashes($data);
$data = trim($data);
$data = htmlspecialchars($data);
return $data;
}
//registration form data validation
if(!empty($_POST['Go']))
{
$email= $password= "";
$email= clean_input($_POST['email']);
$pass= clean_input($_POST['pass']);
$pass = hash("sha256", $pass);
$type= $_GET['type'];
global $query;
if($type=="student")
{
$query= "SELECT * FROM STUDENT WHERE email='$email' AND password='$pass'";
}
elseif($type=="company")
{
$query= "SELECT * FROM COMPANY WHERE email='$email' AND password='$pass'";
}
echo $query;
$query1= mysqli_query($dbhandle,$query);
if(!$query1)
{
echo 'MySQL Error: ' . mysqli_error();
exit;
}
$count= mysqli_num_rows($query1);
if($count==0)
{echo "No Data";
}
else
{
while($row=mysqli_fetch_assoc($query1))
if($type=="student")
{
session_start();
$_SESSION['sname']= $row['F_Name'].' '.$row['L_Name'];
$_SESSION['s_id']= $row['id'];
header('Location: /Internshala/index.php?s_id='.$_SESSION['s_id']);
}
elseif($type=="company")
{
session_start();
$_SESSION['cname']=$row['Name'];
echo $_SESSION['cname'];
$_SESSION['c_id']=$row['c_id'];
header('Location: /Internshala/index.php?c_id='.$_SESSION['c_id']);
}
}
}