CrazeD Posted March 13, 2007 Share Posted March 13, 2007 This is pissing me off beyond belief. So my admin area of my site is being fricken retarded. I'm trying to add a news feature, so admins can add/edit/delete news topics that come up on the front page. It works but not when I make it so you have to be admin/logged in. Now, I used the EXACT SAME METHOD that I did before and now it doesn't work? WTF?! I have this: <?php if ($_SESSION['user_level'] == 1) { admin stuff admin stuff admin stuff admin stuff } else { print '<p>Must be logged in as an admin to view this page!</p>'; } ?> That's basically what I have. It works fine on one script, but not the other... I thought PHP was supposed to be reliable? How can code work once but then not work again? I even made a file with just this in it: <?php if ($_SESSION['user_level'] == 1 ){ print 'WTF'; } ?> And that doesn't work, yet my other admin page works. Just for the record, here's the page that does work: <?php require_once('mysql.php'); if (isset ($_SESSION['username'])) { if ($_SESSION['user_level'] == 1 ) { if (isset ($_POST['submit'])) { $query = "INSERT INTO pr0n_record ( pr0n_record_id, clan_name, size, map, our_score, their_score, date ) VALUES ( 0, '{$_POST['clan_name']}', '{$_POST['size']}', '{$_POST['map']}', '{$_POST['our_score']}', '{$_POST['their_score']}', '{$_POST['date']}' )"; if (@mysql_query ($query)) { print 'A scrim has been added to the record!<br /> <a href="manage_record.php">Back</a>'; } else { // MySQL Error die ('<p>An error has occured:<b> ' . mysql_error() . '</b></p<'); } } else { // Submit not set print "<form method=\"post\" action=\"manage_record.php\"> <table border=\"1\" bordercolor=\"#000000\" width=\"545\"> <tr> <td align=\"center\"><font color=\"#707070\" face=\"Arial\" size=\"3\">Clan Name:</font></td> <td align=\"center\"><input type=\"text\" name=\"clan_name\" /></td> </tr> <tr> <td align=\"center\"><font color=\"#707070\" face=\"Arial\" size=\"3\">Size:</font></td> <td align=\"center\"><input type=\"text\" name=\"size\" /></td> </tr> <tr> <td align=\"center\"><font color=\"#707070\" face=\"Arial\" size=\"3\">Map Played:</font></td> <td align=\"center\"><select name=\"map\"> <option value=\"please_choose\" selected=\"selected\">Choose A Map...</option> <option value=\"obj/\">--- Objective ---</option> <option value=\"obj/obj_team1\">The Hunt</option> <option value=\"obj/obj_team2\">V2 Rocket Facility</option> <option value=\"obj/obj_team3\">Omaha Beach</option> <option value=\"obj/obj_team4\">The Bridge</option> <option value=\"tdm\">--- Team Death Match ---</option> <option value=\"dm/mohdm1\">Southern France</option> <option value=\"dm/mohdm2\">Destroyed Village</option> <option value=\"dm/mohdm3\">Remagen</option> <option value=\"dm/mohdm4\">Crossroads</option> <option value=\"dm/mohdm5\">Snowy Park</option> <option value=\"dm/mohdm6\">Stalingrad</option> <option value=\"dm/mohdm7\">Algiers</option> </select></td> </tr> <tr> <td align=\"center\"><font color=\"#707070\" face=\"Arial\" size=\"3\">Our Score:</font></td> <td align=\"center\"><input type=\"text\" name=\"our_score\" /></td> </tr> <tr> <td align=\"center\"><font color=\"#707070\" face=\"Arial\" size=\"3\">Their Score:</font></td> <td align=\"center\"><input type=\"text\" name=\"their_score\" /></td> </tr> <tr> <td align=\"center\"><font color=\"#707070\" face=\"Arial\" size=\"3\">Date Played:</font></td> <td align=\"center\"><input type=\"text\" name=\"date\" /></td> </tr> </table> <br /><br /> <center><input type=\"submit\" name=\"submit\" value=\"Submit!\" /></center> </form><br /><br />"; } print '<table border="1" bordercolor="#000000" width="545"> <tr> <td align="center"><font color="#707070" face="Arial" size="2"><b>Clan Name</b></font></td> <td align="center"><font color="#707070" face="Arial" size="2"><b>Size</b></font></td> <td align="center"><font color="#707070" face="Arial" size="2"><b>Map</b></font></td> <td align="center"><font color="#707070" face="Arial" size="2"><b>Result</b></font></td> <td align="center"><font color="#707070" face="Arial" size="2"><b>Date Played</b></font></td> <td align="center"><font color="#707070" face="Arial" size="2"><b>Edit/Delete</b></font></td> </tr>'; $get_query = 'SELECT * FROM pr0n_record ORDER BY pr0n_record_id DESC'; if ($r = mysql_query ($get_query)) { while ($row = mysql_fetch_array ($r)) { print "<tr> <td align=\"center\"><font color=\"#707070\" face=\"Arial\" size=\"2\">{$row['clan_name']}</font></td> <td align=\"center\"><font color=\"#707070\" face=\"Arial\" size=\"2\">{$row['size']}</font></td> <td align=\"center\"><font color=\"#707070\" face=\"Arial\" size=\"2\">{$row['map']}</font></td> <td align=\"center\"><font color=\"#707070\" face=\"Arial\" size=\"2\">{$row['our_score']} - {$row['their_score']}</font></td> <td align=\"center\"><font color=\"#707070\" face=\"Arial\" size=\"2\">{$row['date']}</font></td> <td align=\"center\"><font color=\"#707070\" face=\"Arial\" size=\"2\"> <a href=\"edit_record.php?id={$row['pr0n_record_id']}\">Edit</a>/<a href=\"delete_record.php?id={$row['pr0n_record_id']}\">Delete</a></font></td> </tr>"; } } else { // MySQL Error die ('<p>An error has occured:<b> ' . mysql_error() . '</b></p>'); } mysql_close(); } else { // Not admin print '<p>You do not have access to this page!</p>'; } } else { // Not logged in print '<p>You must be logged in as an admin to view this page!<br /> <a href="/login.php">Click here</a> to login.</p>'; } ?> Link to comment https://forums.phpfreaks.com/topic/42480-how-can-the-same-code-not-work-twice/ Share on other sites More sharing options...
monk.e.boy Posted March 13, 2007 Share Posted March 13, 2007 try: print_r( $_SESSION ); print_r( $_COOKIE ); print_r( $_REQUEST ); in the file that doesn't work. Please post the output here. monk.e.boy Link to comment https://forums.phpfreaks.com/topic/42480-how-can-the-same-code-not-work-twice/#findComment-206101 Share on other sites More sharing options...
CrazeD Posted March 13, 2007 Author Share Posted March 13, 2007 I get this: Array ( [pr0nclan_data] => a:2:{s:11:\"autologinid\";s:32:\"2288ed5754fddeb53e5eb01b0c437a47\";s:6:\"userid\";i:2;} ) Array ( [pr0nclan_data] => a:2:{s:11:\"autologinid\";s:32:\"2288ed5754fddeb53e5eb01b0c437a47\";s:6:\"userid\";i:2;} ) Link to comment https://forums.phpfreaks.com/topic/42480-how-can-the-same-code-not-work-twice/#findComment-206102 Share on other sites More sharing options...
monk.e.boy Posted March 13, 2007 Share Posted March 13, 2007 Is there a session ID being passed? There is usually a session ID, then PHP takes this and uses it to read in the $_SESSION data. If you are not passing the ID, or it is corrupt, the $_SESSION data will be blank. monk.e.boy Link to comment https://forums.phpfreaks.com/topic/42480-how-can-the-same-code-not-work-twice/#findComment-206240 Share on other sites More sharing options...
CrazeD Posted March 13, 2007 Author Share Posted March 13, 2007 I have two different scripts that both use the exact same code. They start with if ($_SESSION['user_level'] == 1) { and then it has all the stuff I want only admins to be able to do. One script works, the other one does not. It's the EXACT same code, I even copy/pasted it. I don't understand how this is possible... Link to comment https://forums.phpfreaks.com/topic/42480-how-can-the-same-code-not-work-twice/#findComment-206553 Share on other sites More sharing options...
kenrbnsn Posted March 13, 2007 Share Posted March 13, 2007 Do you call the "session_start()" function in either script at the very start? Ken Link to comment https://forums.phpfreaks.com/topic/42480-how-can-the-same-code-not-work-twice/#findComment-206556 Share on other sites More sharing options...
CrazeD Posted March 13, 2007 Author Share Posted March 13, 2007 Wow..... Actually that's called in my header. This page didn't have my header because I was testing something. lol... I'm an idiot, thank you. Link to comment https://forums.phpfreaks.com/topic/42480-how-can-the-same-code-not-work-twice/#findComment-206606 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.