Soda Tasting, an online show for those who love soda

Bookmark and Share

Check the Shop Hack For an Item

Check the Shop Hack For an Item

Postby TheGatesofBill » March 1st 2003, 10:17 am

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: Select all
define('IN_PHPBB', true); 
$phpbb_root_path = './'; 
include($phpbb_root_path . ''); 
include($phpbb_root_path . 'common.' . $phpEx); 
$userdata = session_pagestart($user_ip, PAGE_INDEX); 
$user_id = ( isset($HTTP_GET_VARS['user_id']) ) ? intval($HTTP_GET_VARS['user_id']) : 0; 

First, you want to set the username:

Code: Select all
$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: Select all
$itemname = 'no tea'; 

Then we check to see if the user is logged in.

Code: Select all
      '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: Select all
      $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: Select all
$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: Select all
   $uselocation = ' -> <a href="'.$itemname.'.php" class="nav">Use the '.$itemname.'</A>'; 
   $title = "Use the ". $itemname; 
   $page_title = "Use the ".$itemname; 

      'USELOCATION' => $uselocation, 
      'USEACTION' => $useaction, 
      'L_USE_TITLE' => $title, 
   $template->assign_block_vars('', array()); 

Then we output the webpage to the browser.

Code: Select all
include($phpbb_root_path . 'includes/page_header.' . $phpEx); 
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: Select all
  <table width="100%" cellspacing="2" cellpadding="2" border="0" align="center"> 
     <td align="left"><span class="nav"><a href="{U_INDEX}" class="nav">{L_INDEX}</a>{USELOCATION}</span></td> 
  <table width="99%" cellpadding="4" cellspacing="1" border="0" align="center" class="forumline"> 
     <th class="thHead">{L_USE_TITLE}</th> 

<br   clear="all" /> 

There, now you are finished, enjoy. You can download my example ("no tea.php") from: (141kb).
Not So New User
Posts: 39
Joined: January 23rd 2003, 1:17 pm

Return to phpBB 2: Miscellaneous

Who is online

Users browsing this forum: No registered users and 0 guests