cdoyle Posted June 20, 2008 Share Posted June 20, 2008 Hello again, In my game, I have it so if you die you go into the 'medical ward' for so many minutes. During that time, I've made it so users can't explore the city or do anything really. But what I do want them to be able to do is, is access their inventory (inventory.php). So they can use meds to get out of the hospital earlier. Right now I'm using this in the private header of my game, to stop the from accessing all the other pages. <?php $playerdead = $db->execute("SELECT p1.username as killedby, Time_Left FROM medical_ward m INNER JOIN players p1 ON m.Killed_By_ID = p1.id where playerdead_ID = $player->id"); $playerdead1= $playerdead->fetchrow(); if($playerdead1 [Time_Left] > 0) { echo "You were put in the hospital by " .$playerdead1[killedby] ."<p>"; echo "You have \n" . $playerdead1[Time_Left] . "\n Minutes remaining"; exit(); } ?> How can I enable them to access just the inventory.php page? and still restrict everything else? Quote Link to comment https://forums.phpfreaks.com/topic/111181-grant-access-to-specfic-page/ Share on other sites More sharing options...
lemmin Posted June 20, 2008 Share Posted June 20, 2008 You aren't showing any code that restricts them from accessing anything. Is there a reason you can't do: if page is inventory.php then allow access? Quote Link to comment https://forums.phpfreaks.com/topic/111181-grant-access-to-specfic-page/#findComment-570642 Share on other sites More sharing options...
cdoyle Posted June 21, 2008 Author Share Posted June 21, 2008 The code I posted was the IF statement that displays a warning message if they are dead. If they are listed with any time greater then 0 in the medical ward table, it displays the message with them being dead. No matter what link they click on, that's all they see. Once their time is up, all the pages start working again. This part is all working pretty well, but I can't seem to figure out how to access just the 1 page. On another forum, someone recommended trying this if($playerdead1 [Time_Left] > 0 && $PHP_SELF != 'inventory.php') { but it didn't work for me, inventory.php was still blocked when they were in the ward. Quote Link to comment https://forums.phpfreaks.com/topic/111181-grant-access-to-specfic-page/#findComment-570667 Share on other sites More sharing options...
cdoyle Posted June 21, 2008 Author Share Posted June 21, 2008 Is there a reason you can't do: if page is inventory.php then allow access? How would you code this? I'm not sure how to allow access to that one page. Quote Link to comment https://forums.phpfreaks.com/topic/111181-grant-access-to-specfic-page/#findComment-570724 Share on other sites More sharing options...
peranha Posted June 21, 2008 Share Posted June 21, 2008 if($playerdead1 [Time_Left] > 0 && $PHP_SELF != 'inventory.php') { Should be if($playerdead1 [Time_Left] > 0 && $_SERVER['PHP_SELF'] != 'inventory.php') { Give that a try. Quote Link to comment https://forums.phpfreaks.com/topic/111181-grant-access-to-specfic-page/#findComment-570736 Share on other sites More sharing options...
.josh Posted June 21, 2008 Share Posted June 21, 2008 I assume you already have a login routine for your game? You take that principle and apply it to those other pages. Instead of checking to see if someone is logged in to access the page, you check to see if they are dead. Quote Link to comment https://forums.phpfreaks.com/topic/111181-grant-access-to-specfic-page/#findComment-570737 Share on other sites More sharing options...
cdoyle Posted June 21, 2008 Author Share Posted June 21, 2008 if($playerdead1 [Time_Left] > 0 && $PHP_SELF != 'inventory.php') { Should be if($playerdead1 [Time_Left] > 0 && $_SERVER['PHP_SELF'] != 'inventory.php') { Give that a try. I had actually been searching the web, and came up with that same code. But it doesn't work either Quote Link to comment https://forums.phpfreaks.com/topic/111181-grant-access-to-specfic-page/#findComment-570935 Share on other sites More sharing options...
cdoyle Posted June 21, 2008 Author Share Posted June 21, 2008 I'm looking at my functions.php and found this if (!isset($_SESSION['userid']) || !isset($_SESSION['hash'])) { header("Location: index.php"); exit; } else { $check = sha1($_SESSION['userid'] . $_SERVER['REMOTE_ADDR'] . $secret_key); if ($check != $_SESSION['hash']) { session_unset(); session_destroy(); header("Location: index.php"); exit; does any of that look like something I can use? Quote Link to comment https://forums.phpfreaks.com/topic/111181-grant-access-to-specfic-page/#findComment-570939 Share on other sites More sharing options...
cdoyle Posted June 22, 2008 Author Share Posted June 22, 2008 if($playerdead1 [Time_Left] > 0 && $PHP_SELF != 'inventory.php') { Should be if($playerdead1 [Time_Left] > 0 && $_SERVER['PHP_SELF'] != 'inventory.php') { Give that a try. Should this work if($playerdead1 [Time_Left] > 0 && $_SERVER['PHP_SELF'] != 'inventory.php') { Or is there something else I could use? I'm looking at the login page, and not seeing anything how to modify it to work to display the 1 page if ($_POST['login']) { if ($_POST['username'] == "") { $errormsg .= "Please enter a username!"; $error = 1; } else if ($_POST['password'] == "") { $errormsg .= "Please enter your password!"; $error = 1; } else if ($error == 0) { $query = $db->execute("select `id`, `username` from `players` where `username`=? and `password`=?", array($_POST['username'], sha1($_POST['password']))); if ($query->recordcount() == 0) { $errormsg .= "You could not login! Please check your username/password!"; $error = 1; } else { $player = $query->fetchrow(); $query = $db->execute("update `players` set `last_active`=? where `id`=?", array(time(), $player['id'])); $hash = sha1($player['id'] . $_SERVER['REMOTE_ADDR'] . $secret_key); $_SESSION['userid'] = $player['id']; $_SESSION['hash'] = $hash; header("Location: home.php"); } } } Quote Link to comment https://forums.phpfreaks.com/topic/111181-grant-access-to-specfic-page/#findComment-571247 Share on other sites More sharing options...
cdoyle Posted June 22, 2008 Author Share Posted June 22, 2008 Does anyone else have any suggestions as to why this wouldn't work? if($playerdead1 [Time_Left] > 0 && $_SERVER['PHP_SELF'] != 'inventory.php') or which part of the code from the login script, I could use to make it so only 1 page is visible when they player is dead. Quote Link to comment https://forums.phpfreaks.com/topic/111181-grant-access-to-specfic-page/#findComment-571688 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.