herghost Posted October 13, 2009 Share Posted October 13, 2009 Hi all, Having a strange problem with displaying a different sidebar when user is logged in, for some reason it keeps displaying the sidebar for the non logged in user, as well as not showing the extra two options in the menu for logged in users: The user logs in on sidebar_0.php: <?php @include('../common/dbconnect.php'); // filter incoming values $username = (isset($_POST['username'])) ? trim($_POST['username']) : ''; $password = (isset($_POST['password'])) ? $_POST['password'] : ''; $redirect = (isset($_REQUEST['redirect'])) ? $_REQUEST['redirect'] : '../index.php'; if (isset($_POST['submit'])) { $query = 'SELECT admin_level FROM users WHERE ' . 'username = "' . mysql_real_escape_string($username, $conn) . '" AND ' . 'password = PASSWORD("' . mysql_real_escape_string($password, $conn) . '")'; $result = mysql_query($query, $conn) or die(mysql_error($conn)); if (mysql_num_rows($result) > 0) { $row = mysql_fetch_assoc($result); $_SESSION['username'] = $username; $_SESSION['logged'] = 1; $_SESSION['admin_level'] = $row['admin_level']; header ('Refresh: 4; URL=' . $redirect); echo "yup logged in" ; mysql_free_result($result); mysql_close($conn); die(); } else { // set these explicitly just to make sure $_SESSION['username'] = ''; $_SESSION['logged'] = 0; $_SESSION['admin_level'] = 0; $error = '<p><strong>You have supplied an invalid username and/or ' . 'password!</strong> </p>'; } mysql_free_result($result); } ?> <?php if (isset($error)) { echo $error; } ?> <div id="sidebar"> <ul> <li> <h2>Member Login</h2><br> <table border="0" align="center" cellspacing="0"> <tr> <td nowrap><img src="./images/img02.gif" alt="leftside" width="25" height="75px" border="0" align="middle"></td> <td><form action="include/sidebar_0.php" method="post"> <table cellspacing="0"> <tr> <td height="25px" bgcolor="#40c1d4"><span style="color:#FFF">Username:</span></td> <td bgcolor="#40c1d4"><input type="text" name="username" maxlength="20" size="20" value=""/></td> </tr><tr> <td height="25px" bgcolor="#40c1d4"><span style="color:#FFF">Password:</span></td> <td bgcolor="#40c1d4"><input type="password" name="password" maxlength="20" size="20" value=""/></td> </tr><tr> <td height="25px" bgcolor="#40c1d4"> </td> <td bgcolor="#40c1d4"> <input type="hidden" name="redirect" value="<?php echo $redirect ?>"/> <input type="submit" name="submit" value="Login"/> </tr> </table> </form> </td> <td><img src="./images/img09.gif" alt="rightside" width="25" height="75" align="middle"></td> </tr> </table> <br /> <br /> <a href="./pages/reg.php" title="Register" onclick=" Modalbox.show(this.href, {title: this.title, width: 600}); return false; "> New User</a><br /> </li> <li> <h2>Stock Of The Day</h2> </li> <li> <h2>Sponsers</h2> </li> </ul> </div> <!-- end sidebar --> This all works fine, I get the yup, logged in message on the redirect once the query has been submitted so I know that the username/password is correct etc, it then redirects back to index.php: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="content-type" content="text/html; charset=utf-8" /> <title>Stockluck.com.au - Australia's Favourite Cash Stock Game</title> <meta name="keywords" content="" /> <meta name="description" content="" /> </head> <body> <?php include('common/header.php'); include('pages/main.php'); if (isset($_SESSION['logged']) && $_SESSION['logged'] == 1) { include('include/sidebar_1.php'); } else { include('include/sidebar_0.php'); } include('common/footer.php'); ?> <!-- start page --> <!-- end content --> <!-- start sidebar --> </div> <!-- end page --> </body> </html> It is now meant to display sidebar_1.php, but still displays sidebar_0.php! Any ideas? the session is set in header.php <?php session_start(); ?> <script type="text/javascript" src="./mbox/prototype.js"></script> <script type="text/javascript" src="./mbox/scriptaculous.js?¬ load=builder,effects"></script> <script type="text/javascript" src="./mbox/modalbox.js"></script> <link href="include/style.css" rel="stylesheet" type="text/css" media="screen" /> <div id="header"> <div id="search"> <form method="get" action=""> <fieldset> <legend>Stock Search</legend> <input id="s" type="text" name="s" value="" /> <input id="x" type="submit" value="Search" /> </fieldset> </form> </div> <div id="logo"> <h1><a href="./index.php"><img src="./images/newlogo.jpg" width="350" height="39" alt="logo" /></a></h1> <h2></h2> </div> <div id="menu"> <ul> <li><a href="#">Home</a></li> <li><a href="#">About</a></li> <li><a href="#">Top 10</a></li> <li><a href="#">Contact</a></li> <?php if (isset($_SESSION['logged']) && $_SESSION['logged'] == 1) { ?> <li><a href="#">My Account</a></li> <li><a href="#">My Stocks</a></li> <?php } ?> </ul> </div> </div> Any blantant mistakes anyone can see? Thanks! Link to comment https://forums.phpfreaks.com/topic/177537-solved-isset-help/ Share on other sites More sharing options...
GKWelding Posted October 13, 2009 Share Posted October 13, 2009 no, but try doing a print_r on $_SESSION['logged'] to see what's actually set. this will indicate if anything's amiss there. Link to comment https://forums.phpfreaks.com/topic/177537-solved-isset-help/#findComment-936096 Share on other sites More sharing options...
backie Posted October 13, 2009 Share Posted October 13, 2009 Well you should be running start_session() on index.php and before the html headers. Link to comment https://forums.phpfreaks.com/topic/177537-solved-isset-help/#findComment-936103 Share on other sites More sharing options...
herghost Posted October 13, 2009 Author Share Posted October 13, 2009 hmm, echoed session and got : I started a session on index.php as well and that seems to have done it! Link to comment https://forums.phpfreaks.com/topic/177537-solved-isset-help/#findComment-936104 Share on other sites More sharing options...
grissom Posted October 13, 2009 Share Posted October 13, 2009 Just some suggestions quickly off the top of my head 1. Try a few more brackets as a "belt and braces" job around your if statement : if (isset($_SESSION['logged']) && ($_SESSION['logged'] == 1)) 2. Same again, but check that the session variable really needs to be a numeric type, not a string type, ie try : if (isset($_SESSION['logged']) && ($_SESSION['logged'] == '1')) 3. Take the session_start() command out of the included header and state it at the top of your index.php file 4. put this in your file as a debugging line above the if statement : echo 'The session variable is : ' . $_SESSION['logged']; Link to comment https://forums.phpfreaks.com/topic/177537-solved-isset-help/#findComment-936107 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.