Somewhat Useful PHP Snippets

Banana
Loyal Member
Joined
Feb 15, 2009
Messages
1,011
Reaction score
867
I took some snippets from my CMS Osa flyff website, and decided to release some useful PHP codes that would be somewhat useful for admins who want ease of access through their website rather than going through their tables/database. You should at least have an understanding of the PHP syntax before reading this. I won't be telling you how to use these snippets because you should make your own, I didn't make this for thieves or lazy leechers.

Most of these the PHP regulars and pro's know, but these aren't for you, they're for beginners. So please don't say "Haha noob coding," even though it's true, I'm relatively new to it, I just want to tell people some things I struggled to find out long ago when I was a private server newbie.

Configuration
Code:
<?php
if(stristr($_SERVER['PHP_SELF'], "config.php"))die('Access Denied.');
$dbms = 'mysql';
$dbport = '3306';
$dbhost = 'localhost';
$dbuser = 'root';
$dbpass = 'pass';
$dbname = 'rhisis';
mysql_connect($dbhost, $dbuser, $dbpass)or die(mysql_error());
mysql_select_db($dbname)or die(mysql_error());
?>

PHP code usually needs to connect to the database using your MySQL user name and password. The form above can be used for that with just simple alterations.

Echo Table/Row Info
Code:
<php?
$XXX = mysql_query("SELECT * FROM XXX WHERE XXX X 'XXX' ");
echo mysql_num_rows($XXX);
unset ($XXX);
?>

This snippet can be used to echo a number count of any table or row, such as an item's refine count, the amount of perin, the count of banned players, and if you have a forum, the forum member, post, et cetera count, which you could use to display it on a server statistic table on a front page.

Include
Code:
<?php
require("XXX.php");
?>

If you want to keep your page cleaner, or if there's a long chunk of code you want to hold elsewhere or for ease of access, you can use this to include it in your index page or whatever. Say you have several tables that display information, and you had code written for server statistics. You could add the code to XXX.php, then insert the PHP snippet into the table, and whatever content is inside XXX.php should show up under most circumstances.

Random Echo Snippets

Time:
Code:
echo date("F d, Y l h:i",time());
IP Address
Code:
echo $_SERVER["REMOTE_ADDR"];

Mathematics

Say you want "thing one" to equal "thing two." Easy, right? Well there's many ways to do math in PHP.

Add: +
Subtract: -
Multiply: *
Divide: /
And: &&
Or: ||
Not: !
Increment: ++
Decrement: --
Equal to: ==
Inequal to: !=
Greater Than: >
Greater Than or Equal to: >=
Less Than: <
Less Than or Equal to: <=

I hope this helps some people in a way.
 
I took some snippets from my CMS Osa flyff website, and decided to release some useful PHP codes that would be somewhat useful for admins who want ease of access through their website rather than going through their tables/database. You should at least have an understanding of the PHP syntax before reading this. I won't be telling you how to use these snippets because you should make your own, I didn't make this for thieves or lazy leechers.

Most of these the PHP regulars and pro's know, but these aren't for you, they're for beginners. So please don't say "Haha noob coding," even though it's true, I'm relatively new to it, I just want to tell people some things I struggled to find out long ago when I was a private server newbie.

Configuration
Code:
<?php
if(stristr($_SERVER['PHP_SELF'], "config.php"))die('Access Denied.');
$dbms = 'mysql';
$dbport = '3306';
$dbhost = 'localhost';
$dbuser = 'root';
$dbpass = 'pass';
$dbname = 'rhisis';
mysql_connect($dbhost, $dbuser, $dbpass)or die(mysql_error());
mysql_select_db($dbname)or die(mysql_error());
?>

PHP code usually needs to connect to the database using your MySQL user name and password. The form above can be used for that with just simple alterations.

Echo Table/Row Info
Code:
<php?
$XXX = mysql_query("SELECT * FROM XXX WHERE XXX X 'XXX' ");
echo mysql_num_rows($XXX);
unset ($XXX);
?>

This snippet can be used to echo a number count of any table or row, such as an item's refine count, the amount of perin, the count of banned players, and if you have a forum, the forum member, post, et cetera count, which you could use to display it on a server statistic table on a front page.

Include
Code:
<?php
require("XXX.php");
?>

If you want to keep your page cleaner, or if there's a long chunk of code you want to hold elsewhere or for ease of access, you can use this to include it in your index page or whatever. Say you have several tables that display information, and you had code written for server statistics. You could add the code to XXX.php, then insert the PHP snippet into the table, and whatever content is inside XXX.php should show up under most circumstances.

Random Echo Snippets

Time:
Code:
echo date("F d, Y l h:i",time());
IP Address
Code:
echo $_SERVER["REMOTE_ADDR"];

Mathematics

Say you want "thing one" to equal "thing two." Easy, right? Well there's many ways to do math in PHP.

Add: +
Subtract: -
Multiply: *
Divide: /
And: &&
Or: ||
Not: !
Increment: ++
Decrement: --
Equal to: ==
Inequal to: !=
Greater Than: >
Greater Than or Equal to: >=
Less Than: <
Less Than or Equal to: <=

I hope this helps some people in a way.
The basics, very nice. Well explained too.
 
Thanks :P
Although most leechers don't know PHP, this is for people who have a small understanding of PHP's syntax and are struggling to learn it or in the process of it
 
PHP is pretty easy after you get the basics (if you have no coding skills else it'll be instant learning).
I get amazed everyday I'm coding and discover something new that can be made with PHP. But meh, I'm learning Ajax now so I can get some sexy-good looking sites :p
 
PHP is pretty easy after you get the basics (if you have no coding skills else it'll be instant learning).
I get amazed everyday I'm coding and discover something new that can be made with PHP. But meh, I'm learning Ajax now so I can get some sexy-good looking sites :p

Ajax is really fancy xD I made a lot of neat features for my registration page with it.
PHP is one of those languages that's beyond easy and powerful once you learn it, but it takes time to do so
 
Back