Jump to content

Grant Access to specfic page


cdoyle

Recommended Posts

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?

Link to comment
Share on other sites

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.

 

 

Link to comment
Share on other sites

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 :(

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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");
	}
}
}

Link to comment
Share on other sites

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.

 

 

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.