Jump to content

[SOLVED] Included header.php wont read cookie on all pages it is in.


farkewie

Recommended Posts

Hello i have a header.php that i include on all pages on my site and also a left.php and footer.php

 

when i login the header has the code

 

<?php echo $_COOKE['uname']; ?>

 

and the left.php has an if statment saysing

 

<?php
if (($_COOKIE['level']) == "Admin") { 
include ("adminlinks.php"); 

}
?>

 

 

now this works fine on the index page but not on any other page.

 

BUT i know the cookies are there because when i do my sql querys using cookies it can read them even though the echo or include statmens cant??

 

part of the header code

 

<div id="header-logo">
          <div id="logo" class="red style3"><span class="style5">WDCS</span> <span class="style4">Townsville <span class="style8">Welcome  </span><span class="style9"><?php echo $_COOKIE['fname'];?></span><br>
          	<br />
          </span> </div>

 

where the cookie is set

 


if ($user_row = mysql_fetch_assoc($user)) {



		setcookie("username",$user_row['uname'],time()+360000000);
		setcookie("team",$user_row['team'],time()+360000000);
		setcookie("fname",$user_row['fname'],time()+360000000);
		setcookie("lname",$user_row['lname'],time()+360000000);

		header ("Location:index.php");

 

the if statment

 

 

<div class="left-box">
    <ul class="sidemenu">
      <li><a href="<?php echo $url;?>walkthroughs/internet_cards/xp/xp_home.php">Windows XP</a></li>
      <li><a href="<?php echo $url;?>walkthroughs/internet_cards/vista/vista_home.php">Windows Vista </a></li>
      <li><a href="<?php echo $url;?>walkthroughs/internet_cards/osx10/osx10_home.php">Mac OSX 10.4 + </a></li>
    </ul>
  </div>
  <?php if (($_COOKIE['team']) == "Admin") { include ("admin/links.php");} ?>
  <h1>common </h1>
  <div class="left-box">
    <ul class="sidemenu">
      <li><a href="<?php echo $url;?>wdcs_cheat.php">Cheat Sheets </a></li>
      <li><a href="<?php echo $url;?>walkthroughs/pre-paid.php">Pre-Paid Codes </a></li>
      <li><a href="<?php echo $url;?>walkthroughs/internet_cards/pingtest/1.php">Ping Test </a></li>
    </ul>
  </div>

Link to comment
Share on other sites

Thanks but is here a way arround this?the whole site is coded to use cookies. maybe not my best idea.. "Still learning".

 

Security is not an issue on his site at all it is run inside a corporate network and the login is only there to grab a name so i can use it to log who is "checking equipment in and out"

Link to comment
Share on other sites

There appear to be some inconsitencies in your code.

You use the following :

if (($_COOKIE['level']) == "Admin") {

As far as I can see you NEVER set 'level' anywhere in your code.

 

You use BOTH of these, but which is it? :

include ("admin/links.php")

include ("adminlinks.php")

 

And what does $_COOKIE['team']) equal? I thought the test was on $_COOKIE['level'] ???

Link to comment
Share on other sites

So sorry, thats me being tired i typed the first samples and copied the real ones later

 

below is the real code i am using.

 

header.php

<div id="header-logo">
          <div id="logo" class="red style3"><span class="style5">WDCS</span> <span class="style4">Townsville <span class="style8">Welcome  </span><span class="style9"><?php echo $_COOKIE['fname'];?></span><br>
          	<br />
          </span> </div>

 


login.php

if ($user_row = mysql_fetch_assoc($user)) {



		setcookie("username",$user_row['uname'],time()+360000000);
		setcookie("team",$user_row['team'],time()+360000000);
		setcookie("fname",$user_row['fname'],time()+360000000);
		setcookie("lname",$user_row['lname'],time()+360000000);

		header ("Location:index.php");

 


left.php


<div class="left-box">
    <ul class="sidemenu">
      <li><a href="<?php echo $url;?>walkthroughs/internet_cards/xp/xp_home.php">Windows XP</a></li>
      <li><a href="<?php echo $url;?>walkthroughs/internet_cards/vista/vista_home.php">Windows Vista </a></li>
      <li><a href="<?php echo $url;?>walkthroughs/internet_cards/osx10/osx10_home.php">Mac OSX 10.4 + </a></li>
    </ul>
  </div>
  <?php if (($_COOKIE['team']) == "Admin") { include ("admin/links.php");} ?>
  <h1>common </h1>
  <div class="left-box">
    <ul class="sidemenu">
      <li><a href="<?php echo $url;?>wdcs_cheat.php">Cheat Sheets </a></li>
      <li><a href="<?php echo $url;?>walkthroughs/pre-paid.php">Pre-Paid Codes </a></li>
      <li><a href="<?php echo $url;?>walkthroughs/internet_cards/pingtest/1.php">Ping Test </a></li>
    </ul>
  </div>

 

once again sorry to confuse...

Link to comment
Share on other sites

Ok the next question I guess is where do these steps occur / happen?

When does your SQL get executed? By the looks of it I would say on login.

So assuming that you are performing your SQL query before you actually forward to index.php I would say your next debug step is to find out what your SQL is retrieving.

 

In your "if ($user_row = mysql_fetch_assoc($user)) {" loop do :

print_r($user_row);

 

Then let me know what you're getting back.

 

Also in your header to print_r($_COOKIE) and in your left.php do the same.

 

Is it the case that you're getting NO cookie information on your pages, or just some of it (i.e. no team information).

Link to comment
Share on other sites

url = http://127.0.0.1/mobiles/index.php

 

print_r(COOKIE);

 

header.php

 

Array ( [username] => d255111 [team] => Admin [fname] => Tyron [lname] => Gower )

 

left.php

Array ( [username] => d255111 [team] => Admin [fname] => Tyron [lname] => Gower )

 

 

http://127.0.0.1/mobiles/wdcs_cheat.php

 

print_r(COOKIE);

 

header.php

 

Array ( )

 

left.php

 

Array ( )

 

print_r($user_row);

http://127.0.0.1/mobiles/login.php

 

 

Array ( [id] => 26 [uname] => d255111 [fname] => Tyron [lname] => Gower [team] => Admin [status] => active )

 

Link to comment
Share on other sites

ok so i fixed it on all page in the root directory.

 

by changing this

 

<?php
$url = "http://".$_SERVER['HTTP_HOST']."/mobiles/";
##################################
#####		DO NOT MOVE    #######
include ($url."sql.php");
include ($url."top.php");
include ($url."left.php");
##################################

?>

to this

 


<?php
$url = "http://".$_SERVER['HTTP_HOST']."/mobiles/";
##################################
#####		DO NOT MOVE    #######
include ("sql.php");
include ("top.php");
include ("left.php");
##################################

?>

 

but in my subdirectorys i need the $url so i can include i dont get include errors.

Link to comment
Share on other sites

I understand that  ut how does that solve my problems of the cookie not being read whn i am on a page in a subdirectoery?

 

the problem is when i use the below code to include my header left links and footer they all include but cant read my cookie.

 




<?php
$url = "http://".$_SERVER['HTTP_HOST']."/mobiles/";
##################################
#####		DO NOT MOVE    #######
include ($url."sql.php");
include ($url."top.php");
include ($url."left.php");
##################################

?>

Link to comment
Share on other sites

Use print_r($_COOKIE) not print_r(COOKIE)

 

url = http://127.0.0.1/mobiles/index.php

 

print_r(COOKIE);

 

header.php

 

Array ( [username] => d255111 [team] => Admin [fname] => Tyron [lname] => Gower )

 

left.php

Array ( [username] => d255111 [team] => Admin [fname] => Tyron [lname] => Gower )

 

 

http://127.0.0.1/mobiles/wdcs_cheat.php

 

print_r(COOKIE);

 

header.php

 

Array ( )

 

left.php

 

Array ( )

 

print_r($user_row);

http://127.0.0.1/mobiles/login.php

 

 

Array ( [id] => 26 [uname] => d255111 [fname] => Tyron [lname] => Gower [team] => Admin [status] => active )

 

Link to comment
Share on other sites

You spelled COOKIE wrong here, not sure if its a typo just here or also in your code.

 

Hello i have a header.php that i include on all pages on my site and also a left.php and footer.php

 

when i login the header has the code

 

<?php echo $_COOKE['uname']; ?>

 

Link to comment
Share on other sites

no just a typo this is what it is supposed to be.

 

 


<div id="header-logo">
          <div id="logo" class="red style3"><span class="style5">WDCS</span> <span class="style4">Townsville <span class="style8">Welcome  </span><span class="style9"><?php echo $_COOKIE['fname'];?></span><br>
          	<br />
          </span> </div>

 

as i said it all works fine if i am in the root directory when the header.php is but when i am in a subdirectory including files from the root directory they will display ok but wont read the cookies that are set

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.