ArcEmu: Paging! - ArcEmu

Jump to content

Toggle shoutbox Lastest Announcements

dfighter  : (07 December 2014 - 12:06 PM) Arcemu is in hibernation mode, please read http://arcemu.org/fo...showtopic=26903
dfighter  : (01 January 2013 - 05:56 PM) Arcemu wishes you all a happy new year!
Hasbro  : (12 September 2012 - 10:01 AM) Please excuse our outage from the web! Our web host had a major malfunction!
dfighter  : (01 September 2012 - 04:05 PM) Since the spam bots just don't want to stop, I've enabled admin verification when registering.
dfighter  : (23 January 2012 - 09:56 PM) Please note that from now on you will need to confirm your email on the wiki in order to edit it!
Hasbro  : (31 December 2011 - 12:50 PM) Happy New Years all!
Navid  : (26 December 2011 - 04:09 AM) Merry Christmas !!!!!! Happy holidays all :)
WAmadeus  : (24 December 2011 - 03:54 PM) Merry Christmas to all!
dfighter  : (24 December 2011 - 11:05 AM) The Arcemu team wishes y'all a Merry Christmukkah!
Hasbro  : (05 October 2011 - 12:53 PM) Looking for web designers for upcoming web related project. If you're interested in designing user interfaces contact me
dfighter  : (02 September 2011 - 03:47 PM) So who here wants vehicles in Arcemu? :P http://arcemu.org/fo...showtopic=25440
Hasbro  : (14 August 2011 - 03:25 PM) Join us on irc, grab an irc client and connect to irc.freenode.net join channel #arcemu /server irc.freenode.net:6667 /join #arcemu
jackpoz  : (03 August 2011 - 05:33 AM) to all Lua Engine (old one) users: please check http://arcemu.org/fo...showtopic=25274
Hasbro  : (20 May 2011 - 05:27 PM) Looking for people experienced with CMake configuration and setup! Contact me asap
Hasbro  : (15 May 2011 - 05:03 PM) ArcEmu is recruiting C++ programmers, contact Hasbro if interested.
paroxysm  : (03 May 2011 - 06:26 PM) Updated luabridge gossip example to describe the whole gossip creation process rather than just how to create menu. Gossip tutorial
paroxysm  : (23 April 2011 - 11:35 AM) Lua writers can refer to the Luabridge Tutorials section in the Wiki to learn how to write gossip code correctly.
Hasbro  : (20 April 2011 - 05:22 PM) Thank you for your continuous contribution of bug reports, we are working on them.
Hasbro  : (17 April 2011 - 03:20 AM) Please consider donating to support our bills. Donations can be sent using PayPal to donations@arcemu.org - Thank you for your support.
paroxysm  : (10 April 2011 - 12:43 AM) Refer to the Luabridge Tutorials section in the Wiki to learn the new syntax of luabridge.
Resize Shouts Area

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Paging!

#1 User is offline   Bob Herman 

  • Interested
  • PipPipPipPip
  • Group: Members
  • Posts: 452
  • Joined: 11-October 08
  • Gender:Male

Posted 22 December 2009 - 11:47 AM

So you've probably seen those funky URL's that look like '?act=login', on sites like Wowhead, or even my PingueCMS. So in this quick tutorial I'm just going to teach you the basics, and then do an example.

The Basics

First, I need to teach you the correct URL syntax. You first have your URL, then your file name. Then the file name and the variable are separated by a ?, and then the variables come after. If you have more than one variable, you put a & (and) in between them

supahkewlwow.com/index.php?act=login&username=maverfax

A thing you really need to learn for this is the $_GET. $_GET gets variables inputted in the URL, and stores them in an array. From the example URL above, you could get the act and username by doing this:

<?php
$act = $_GET['act'];
$username = $_GET['username'];
?>


The Example

Okay, first things first. Since PHP is extremely picky, we first have to check if the $_GET['page'] variable is set. If we didn't, we would get tons of annoying notices. :)

<?php
#necessary to not get flamed with notices
if( isset($_GET['page']) ) {
}


Then, we can add a default value using the else.

<?php
#necessary to not get flamed with notices
if( isset($_GET['page']) ) {
}
#If the page isn't put in the URL, go to index (THIS IS THE DEFAULT VALUE)
else $page = 'index';  
?>


Now, let's store the $_GET variable as $page:

<?php
#necessary to not get flamed with notices
if( isset($_GET['page']) ) {
  
  #Store the page variable
  $page = $_GET['page']; 
}
#If the page isn't put in the URL, go to index (THIS IS THE DEFAULT VALUE)
else $page = 'index'; 
?>


The problem with this is that it can easily be hacked into. So let's put a little security. Basically, this checks if the file exists, and if makes sure that the page name isn't too long (a long $_GET['page'] usually means someone's trying to hack you :D ). If the $page doesn't exist, or the name is to long, it loads the index.php file.

<?php
#necessary to not get flamed with notices
if( isset($_GET['page']) ) {
  
  #Store the page variable
  $page = $_GET['page']; 

  #Security: checks for if page exists, and then makes sure we aren't trying to be hacked (with a page name greater than 8)
  if( !file_exists("pages/{$page}.php") || strlen($page) > 8 ) { 
    $page = 'index';
  }
}
#If the page isn't put in the URL, go to index (THIS IS THE DEFAULT VALUE)
else $page = 'index'; 
?>


And then, you just include the page you want your script to load :)

<?php
#necessary to not get flamed with notices
if( isset($_GET['page']) ) {
  
  #Store the page variable
  $page = $_GET['page']; 

  #Security: checks for if page exists, and then makes sure we aren't trying to be hacked (with a page name greater than 8)
  if( !file_exists("pages/{$page}.php") || strlen($page) > 8 ) { 
    $page = 'index';
  }
}
#If the page isn't put in the URL, go to index (THIS IS THE DEFAULT VALUE)
else $page = 'index'; 

#Get the page :)
include( "pages/{$page}.php" ); 
?>


And that's how it works.

(p.s. None of this was, like usual, tested. If you get errors post it here and I'll fix it)
0

#2 User is offline   pingue 

  • Member
  • Pip
  • Group: Members
  • Posts: 99
  • Joined: 18-July 09
  • Gender:Male
  • Location:EARTH LULZ!
  • Interests:web designing.. grilz n titz, wow :3

Posted 22 December 2009 - 11:52 AM

Ty mav <3 I is learnin da PHP!!!!!
Posted Image
0

#3 User is offline   Furt 

  • Member
  • Group: Banned
  • Posts: 98
  • Joined: 26-November 08
  • Gender:Male
  • Location:Deep South

Posted 23 December 2009 - 05:28 PM

Pretty nice bit of info heres the function i use.


function maincontent($pageid) {
	if(empty($pageid)) {
		$pageid = "home";
  		
		}else{ 
			
			$pageid = $_GET['pageid'];

			}

	include("pages/".$pageid."/".$pageid.".php");
	}}


then i just place maincontent($pageid); wherever i need it on the site.
Projects



Current retail Characters:
Realm Class Name Level
The Forgotten Coast - Druid - Jeeroy - 80
Senjin - Warlock - Maruderenn - 72

#4 User is offline   Bob Herman 

  • Interested
  • PipPipPipPip
  • Group: Members
  • Posts: 452
  • Joined: 11-October 08
  • Gender:Male

Posted 23 December 2009 - 11:18 PM

mhm, but that can be hacked. And also, that urges for more directories than I like.... But I guess in the end it comes down to preferences.
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users