TheGatesofBill
Not So New User
Joined: 23 Jan 2003
Posts: 39
|
Posted: March 1st 2003, 9:17 am Post subject: Check the Shop Hack For an Item |
|
|
In this tutorial, I will demonstrate how to check if a user is in possession of an item. This could then be used to display the page only if the user owns a certain item. I had requested this many times, so I went and figured it out myself. NOTE: I am writing this by looking back over my "no tea.php" file which is linked at the bottom of this tutorial. This is based largely on Moogie's "groovy drink.php" file. I do not claim to have come up with this on my own, however, all the text (not code) in this tutorial is mine.
OK, here we go:
I have no idea what all these are, but they are needed, for more info check out AJ Quick's tutorial.
| Code:
|
define('IN_PHPBB', true);
$phpbb_root_path = './';
include($phpbb_root_path . 'extension.inc');
include($phpbb_root_path . 'common.' . $phpEx);
$userdata = session_pagestart($user_ip, PAGE_INDEX);
init_userprefs($userdata);
$user_id = ( isset($HTTP_GET_VARS['user_id']) ) ? intval($HTTP_GET_VARS['user_id']) : 0;
|
First, you want to set the username:
| Code:
|
|
$username = $userdata[username];
|
Then define which item you want to check for. NOTE: My experience is that this must be entered in all lowercase letters.
| Code:
|
|
$itemname = 'no tea';
|
Then we check to see if the user is logged in.
| Code:
|
$template->set_filenames(array(
'body' => 'use_body.tpl')
);
if ( !$userdata['session_logged_in'] )
{
$redirect = $itemname.".php";
header('Location: ' . append_sid("login.$phpEx?redirect=$redirect", true));
}
|
Now we make sure that they have the item and if they don't it, then it won't display the rest of the page.
| Code:
|
$sql = "select user_items from " . USERS_TABLE . " where username='$username'";
if ( !($result = $db->sql_query($sql)) ) { message_die(GENERAL_MESSAGE, 'Fatal Error Getting Items!'); }
$row = mysql_fetch_array($result);
if (substr_count($row['user_items'],"ß".$itemname."Þ") < 1)
{
message_die(GENERAL_MESSAGE, 'You don\'t have a '.$itemname.'!');
}
|
If the user has the item, then the content is displayed, in my example, the HHGG text game.
| Code:
|
$useaction = "<tr><td class=\"row1\" align=\"center\"><BR><span class=\"size2\"><b>".$username."</b> drank the <b>".$itemname."</b>!<p><applet align=\"center\" archive=\"ZPlet.jar\" code=\"Zplet.class\" width=\"500\" height=\"380\"><param name=\"Foreground\" value=\"white\"><param name=\"Background\" value=\"black\"><param name=\"StatusForeground\" value=\"green\"><param name=\"StatusBackground\" value=\"black\"><param name=\"StoryFile\" value=\"hhgg.z5\"></applet><P><P><b><i>".$username."</b> played <b>Hitchhiker's Guide to the Galaxy</b>!</i></span><P></td></tr>";
|
Here we define the variables needed in the template.
| Code:
|
$uselocation = ' -> <a href="'.$itemname.'.php" class="nav">Use the '.$itemname.'</A>';
$title = "Use the ". $itemname;
$page_title = "Use the ".$itemname;
$template->assign_vars(array(
'USELOCATION' => $uselocation,
'USEACTION' => $useaction,
'L_USE_TITLE' => $title,
));
$template->assign_block_vars('', array());
|
Then we output the webpage to the browser.
| Code:
|
include($phpbb_root_path . 'includes/page_header.' . $phpEx);
$template->pparse('body');
include($phpbb_root_path . 'includes/page_tail.' . $phpEx);
|
Now, you need to copy this code and put it in the directory of your current template as "use_body.tpl".
| Code:
|
<table width="100%" cellspacing="2" cellpadding="2" border="0" align="center">
<tr>
<td align="left"><span class="nav"><a href="{U_INDEX}" class="nav">{L_INDEX}</a>{USELOCATION}</span></td>
</tr>
</table>
<table width="99%" cellpadding="4" cellspacing="1" border="0" align="center" class="forumline">
<tr>
<th class="thHead">{L_USE_TITLE}</th>
</tr>
{USEACTION}
</table>
<br clear="all" />
|
There, now you are finished, enjoy. You can download my example ("no tea.php") from: http://www.phpbbhacks.com/tutorials/notea.zip (141kb). |
|