Hi guys,
I have 2 headers to include: header_Secure.php and header.php.
What I am trying to do is when session exist include header_Secure.php and when session does not exist include header.php.
Here is my code:
<?php
// headers change between logged in and not logged in
session_start();
$header = '';
// Be sure to check that this manager SESSION value is in fact in the database
$managerID = $_SESSION["id"];
$manager = $_SESSION["manager"];
$password = $_SESSION["password"];
include 'register/includes/connect_to_mysql.php';
$sql = mysql_query("SELECT * FROM members WHERE id ='$managerID' AND Email ='$manager' AND Password='$password' LIMIT 1");
$existCount = mysql_num_rows($sql); // count the row nums
if ($existCount == 0)
{
$header = ' <?php include_once "includes/header.php";?> ';
}
else
{
$header = ' <?php include_once "includes/header_Secure.php";?> ';
};
?>
But the problem I am having is that it is not picking any headers, I am not sure since I am new to php if I am able to use php inside php like $header = ' <?php include_once "includes/header.php";?> ';
Youssef
sessions
Moderator: General Moderators
-
YoussefSiblini
- Forum Contributor
- Posts: 206
- Joined: Thu Jul 21, 2011 1:51 pm
Re: sessions
I sorted it out I used:
<?php
// headers change between logged in and not logged in
session_start();
$header = '';
// Be sure to check that this manager SESSION value is in fact in the database
$managerID = $_SESSION["id"];
$manager = $_SESSION["manager"];
$password = $_SESSION["password"];
include 'register/includes/connect_to_mysql.php';
$sql = mysql_query("SELECT * FROM members WHERE id ='$managerID' AND Email ='$manager' AND Password='$password' LIMIT 1");
$existCount = mysql_num_rows($sql); // count the row nums
if ($existCount == 0)
{
$header ='includes/header.php';
}
else
{
while($row = mysql_fetch_array($sql))
{
$First_Name = $row["First_Name"];
$header = 'includes/header_Secure.php';
}
}
?>
and I put <?php include_once "$header" ?> in the body and it worked fine.
<?php
// headers change between logged in and not logged in
session_start();
$header = '';
// Be sure to check that this manager SESSION value is in fact in the database
$managerID = $_SESSION["id"];
$manager = $_SESSION["manager"];
$password = $_SESSION["password"];
include 'register/includes/connect_to_mysql.php';
$sql = mysql_query("SELECT * FROM members WHERE id ='$managerID' AND Email ='$manager' AND Password='$password' LIMIT 1");
$existCount = mysql_num_rows($sql); // count the row nums
if ($existCount == 0)
{
$header ='includes/header.php';
}
else
{
while($row = mysql_fetch_array($sql))
{
$First_Name = $row["First_Name"];
$header = 'includes/header_Secure.php';
}
}
?>
and I put <?php include_once "$header" ?> in the body and it worked fine.
Re: sessions
Does this work:
edit: seems like you got the solution while I was typing 
Code: Select all
if ($existCount == 0)
{
include_once "includes/header.php";
}
else
{
include_once "includes/header_Secure.php";
};
-
YoussefSiblini
- Forum Contributor
- Posts: 206
- Joined: Thu Jul 21, 2011 1:51 pm
Re: sessions
Thank you,
It is working now when I used the above code I used the $header as the path and I included it in the include_once and it worked fine
It is working now when I used the above code I used the $header as the path and I included it in the include_once and it worked fine