sessions

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
YoussefSiblini
Forum Contributor
Posts: 206
Joined: Thu Jul 21, 2011 1:51 pm

sessions

Post by YoussefSiblini »

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
YoussefSiblini
Forum Contributor
Posts: 206
Joined: Thu Jul 21, 2011 1:51 pm

Re: sessions

Post by YoussefSiblini »

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.
Dodon
Forum Commoner
Posts: 64
Joined: Wed Aug 03, 2011 4:11 am
Location: Netherlands

Re: sessions

Post by Dodon »

Does this work:

Code: Select all

if ($existCount == 0) 
{ 
  include_once "includes/header.php";
 }
 else
 {
   include_once "includes/header_Secure.php";
 };
edit: seems like you got the solution while I was typing :)
YoussefSiblini
Forum Contributor
Posts: 206
Joined: Thu Jul 21, 2011 1:51 pm

Re: sessions

Post by YoussefSiblini »

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 :)
Post Reply