[PHP/OOP] Useful functions to create a website.
Hey,
I spent some time writing some functions in PHP (OOP) to make it easier for you to create websites in PHP.
--
What does it contain?
Code:
- Functions to check if a query returned 0 row, 1 row or more rows. (Useful for other function you want to make.)
- Login function.
- Basic register function (with e-mail check).
- Admin, jjang and ban check functions.
- Check if a character belongs to an account. (For create clan functions,etc.)
- Check if a character is the owner of a clan.
- Check if a character has got a clan.
- Check if a char exists.
- Useful functions to get data out of the Account, Character or Clan table.
- Function to get the coins/credits of an account.
- Add item function.
- Buy item function. (Can be used for item shops.)
- Create clan function.
- Function for showing errors on an easy way.
- Two anti SQL injection functions. One recommended for $_GET methods and the other is recommended for $_POST methods.
- Redirect, alert and kill session function.
--
The anti SQL injection that I recommend for the $_GET method basically replaces bad words with nothing ("") so if the URL is Website.com and a hacker adds a single quote behind the URL ('), the page will ignore it and it will show the page.
The anti SQL injection function for the $_POST method stops the script once it detects a SQL injection and it will alert an error on the screen.
--
How to use?
It's very easy to use.
The first thing you need to do is to put
PHP Code:
session_start();
require("/class/class_load.php");
on top of every page.
Now I also recommend you to put session_start(); on top of the require since the function that shows errors uses SESSIONS.
As example I take the create clan function.
Take a look at the source of class_sqlfunctions.php and check what the function needs.
It needs the clan name, character name and account name.
PHP Code:
$z = $sqlf->createclan("Trust", "^7Dave", "SuperWaffle");
This will try to create the clan Trust on the character ^7Dave and the account name SuperWaffle.
The function has all kind of checks to make sure the clan does not exist, the char exists, the char is the owner of the account name,etc.
To check if it made the clan:
PHP Code:
if($z == true)
{
// It made the clan!
}
else
{
showmsg(); // Show the error msg.
}
If you still don't get it then I will show another example of the getchardata function. This is an easy function to get the value of a certain column in the table Character.
As you can see in the source, it needs the column name and the character name.
PHP Code:
$cid = $sqlf->getchardata("CID", "^7Dave");
echo $cid;
This will echo the CID of the character ^7Dave.
Easy right?
--
You also need to edit the class_connect.php file in the class folder. This connects with the database.
This only works with a MSSQL enabled web server.
Post suggestions, errors or other things here.
Of course I'm only going to code the basic functions.
--
TLDR; Edit class_connect.php and require class_load.php on top of every page.
You dislikez? I couldn't care less.
You don't understand this? Read the above starting from line one.
You still don't understand? Post it in this thread.
You still don't understand it after the above? Learn PHP, it's not that hard.
Re: [PHP/OOP] Useful functions to create a website.
nice work!
good release too.
we need this kind of things.
Re: [PHP/OOP] Useful functions to create a website.
Updated the getcoins function.
I forgot to edit a line which I used for testing purposes.
Re: [PHP/OOP] Useful functions to create a website.
Thank you for this! This will help me with learning some SQL :)
Nice release.
Re: [PHP/OOP] Useful functions to create a website.
I rlly dont understand it but the functions are nice.
Posted via Mobile Device
Re: [PHP/OOP] Useful functions to create a website.
thanks for contributing waffle,
nice functions.
will help alot of beginners out there.
Re: [PHP/OOP] Useful functions to create a website.
Quote:
Originally Posted by
BGRick
I rlly dont understand it but the functions are nice.
Posted via Mobile Device
what's not to understand?
Re: [PHP/OOP] Useful functions to create a website.
Like it ^^ and hey SuperWaffle :P u come to rgz *--* Taylor here :)
Re: [PHP/OOP] Useful functions to create a website.
If your $_GET is a number use this script .. it's really simple :)
PHP Code:
if(is_numeric($_GET['xx']) && $_GET['xx' >= 1 && $_GET['xx' <=9999){
//do what you need to do.
}
else{
//Error - It's not a number.
}
Re: [PHP/OOP] Useful functions to create a website.
Quote:
Originally Posted by
PureExode
If your $_GET is a number use this script .. it's really simple :)
PHP Code:
if(is_numeric($_GET['xx']) && $_GET['xx' >= 1 && $_GET['xx'] <=9999){
//do what you need to do.
}
else{
//Error - It's not a number.
}
Yea but it's the best to use ctype_digit since is_numeric can also passes certain letters through.
'42' is numeric
'1337' is numeric
'1e4' is numeric
'not numeric' is NOT numeric
'Array' is NOT numeric
'9.1' is numeric
PHP Code:
if(ctype_digit($_GET['xx']) && $_GET['xx' >= 1 && $_GET['xx'] <=9999){
//do what you need to do.
}
else{
//Error - It's not a number.
}
Would be slightly better. :)
Re: [PHP/OOP] Useful functions to create a website.
Nice one thanks I can now use this for my custom web
Posted via Mobile Device
Re: [PHP/OOP] Useful functions to create a website.
You can use $this->function instead of classname::function to execute the function in the class, doing that you'll call the function without instancing the class again.
You're use:
sqlfunctions::checkrow0();
change to:
$this->checkrow0();
Re: [PHP/OOP] Useful functions to create a website.
Quote:
Originally Posted by
alfredao
You can use $this->function instead of classname::function to execute the function in the class, doing that you'll call the function without instancing the class again.
You're use:
sqlfunctions::checkrow0();
change to:
$this->checkrow0();
Ah forgot about that. Will update it later.