farkewie Posted November 14, 2007 Share Posted November 14, 2007 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> Quote Link to comment Share on other sites More sharing options...
aschk Posted November 14, 2007 Share Posted November 14, 2007 Don't use COOKIE, use SESSION instead. Sessions cant be altered directly by the user, cookies can. Quote Link to comment Share on other sites More sharing options...
farkewie Posted November 14, 2007 Author Share Posted November 14, 2007 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" Quote Link to comment Share on other sites More sharing options...
aschk Posted November 14, 2007 Share Posted November 14, 2007 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'] ??? Quote Link to comment Share on other sites More sharing options...
farkewie Posted November 14, 2007 Author Share Posted November 14, 2007 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... Quote Link to comment Share on other sites More sharing options...
aschk Posted November 14, 2007 Share Posted November 14, 2007 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). Quote Link to comment Share on other sites More sharing options...
farkewie Posted November 14, 2007 Author Share Posted November 14, 2007 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 ) Quote Link to comment Share on other sites More sharing options...
aschk Posted November 14, 2007 Share Posted November 14, 2007 Interestingly it looks like the WHOLE cookie is being dropped. Quote Link to comment Share on other sites More sharing options...
farkewie Posted November 14, 2007 Author Share Posted November 14, 2007 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. Quote Link to comment Share on other sites More sharing options...
aschk Posted November 14, 2007 Share Posted November 14, 2007 You're about to learn something new today... Try the following : page1.php <?php $myvar = "something"; include("page2.php"); ?> page2.php <?php echo $myvar; ?> Quote Link to comment Share on other sites More sharing options...
farkewie Posted November 14, 2007 Author Share Posted November 14, 2007 sorry you have lost me. Quote Link to comment Share on other sites More sharing options...
revraz Posted November 14, 2007 Share Posted November 14, 2007 Run page1.php and you'll notice that it pulls the echo from page2.php and prints "something" on your screen. Quote Link to comment Share on other sites More sharing options...
farkewie Posted November 14, 2007 Author Share Posted November 14, 2007 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"); ################################## ?> Quote Link to comment Share on other sites More sharing options...
revraz Posted November 14, 2007 Share Posted November 14, 2007 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 ) Quote Link to comment Share on other sites More sharing options...
revraz Posted November 14, 2007 Share Posted November 14, 2007 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']; ?> Quote Link to comment Share on other sites More sharing options...
farkewie Posted November 14, 2007 Author Share Posted November 14, 2007 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 Quote Link to comment Share on other sites More sharing options...
farkewie Posted November 15, 2007 Author Share Posted November 15, 2007 fixed it. moved all my included files to the root directorey and just did <? include ("../../../left.php"); ?> all works fine now. i just have to go change every page. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.