phpBBHacks.com - Check the Shop Hack For an Item
Discuss internet community strategy at CommunityAdmins.com
StatsForums Home   RegisterRegister   ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in
FAQFAQ   SearchSearch   MemberlistMemberlist   TutorialsTutorials   ContactContact Us
Add Us:     MySpace     Facebook     StumbleUpon
Username:    Password:
Remember Me?    
Check the Shop Hack For an Item
BlinkList
del.icio.us
Furl
linkaGoGo
reddit
Simpy
Mister Wong
Yahoo! My Web

Post new topic   Reply to topic    phpBBHacks.com Support Forums Forum Index -> phpBB 2: Miscellaneous
 See a User Guidelines violation? Please contact us.
Author Message

TheGatesofBill
Not So New User

Joined: 23 Jan 2003
Posts: 39

PostPosted: March 1st 2003, 9:17 am    Post subject: Check the Shop Hack For an Item Reply with quote

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).
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    phpBBHacks.com Support Forums Forum Index -> phpBB 2: Miscellaneous All times are GMT - 6 Hours
Page 1 of 1
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum



Links: Big Message Boards - Free JavaScript - phpBB2 - phpbb styles - Suporte phpBB - phpBB.it - phpBB Česky - phpBB Turkiye - phpBBArabia.com - phpBB-fr.com - Romanian phpBB online community - phpBB-TW.net - phpBBservice.nl - phpBB Brasil

Network: iFroggy Network Blog - iFroggy Hosting - SportsForums.net - KarateForums.com - YanksBlog.com - DeveloperCube - Managing Online Forums - ManagingCommunities.com - CommunityAdmins.com - PhotoshopForums.com - MicrosoftBlog.com - DrGregHouse.com - Bad Boy Blog - BadBoyForums.com - SodaRatings.com - Patrick O'Keefe

< Advertising - Contact Us - Staff - User Guidelines >

Copyright © 2001-2008. iFroggy Network, phpBBHacks.com. All Rights Reserved. Privacy Policy. We Support phpBBHacks.com (of course!).
Powered by phpBB © phpBB Group. phpBB SEO. Hosted by 100MegsWebHosting. We are in no way affiliated with the phpBB Group. phpBB is copyright to the phpBB Group.