• Log in or sign up for an account here: https://www.sythe.org/login

PHP Tutorial

Raid500

Forum Addict
Joined
Feb 11, 2007
Sythe Gold
0
Messages
592
PHP Tutorial
PHP Tutorial By Raid​

Background on PHP
PHP stands for PHP Hypertext Preprocessor. It is used to create programs on web pages. It can be found on almost all web pages and has many uses.

Getting started with PHP
Well to be able to start writing PHP codes, you will need to have either A) Notepad or B) A PHP IDE - I recommend Eclipse, http://www.eclipse.org/proposals/php-ide/
Note: IDEs are better because they will automatically point out your errors and shows you how to fix them.

BASICS of PHP
You will need to know some of the most basic things in PHP which are:
Code:
 <?php CODEHERE ?>
- These are the PHP tags which you wrap around your code and which it distinguishes php.
Saving as .php, if you are using notepad, you will need to do as follows:
2qs5wl5.png

Commenting is used to show what each line of code does. You can comment as follows:
//stuff here
/*stuff here*/


Actual Programming Part

Echo
Echo is used to display text on a page. It can be done many ways,
Code:
echo "text";
echo 'text';
echo ("text");
I just like to stick with the first 1, but many java programmers use the last 1 since it's similar to java.

Variables
Variables are used to hold data. All variables start with $.
Code:
$example = $_GET['example'];
$example2 = 1+1;

Operators
(symbols) They are a lot like every other language.
+ Addition
- Subtraction
* Multiplication
/ Division
For more google PHP operators

If conditionals
If conditionals are used to check if this happens then this happens. Like if your gender is male then echo Mr. $name

Code:
if(gender == male){
echo "Hello sir";
}
else {
echo "Hello mam";
}

In the above code, as you see, if the gender is male then it will say sir, else (OTHERWISE) say hello mam.

Else If:
Code:
if(number == 1){
echo "NUMBAR 1";
}
else if(number == 2){
echo "Numbar 2";
}
else{
echo "loser";

This is saying if you're number 1, then print NUMBAR 1, else, if you're number 2, print that, else (otherwise) print loser :)

Below taken from my other post: http://sythe.org/showthread.php?t=674500
What is $_GET?
$_GET is a way to get information from 1 page to another.

Lets look at an example..
Code:
<form action="login.php" method="get">
Username: <input type="text" name="username" />
Password: <input type="text" name="pass" />
<input type="submit" />
</form>
Above is a html script that would make a basic form. As you can see, the form action="login.php" is where the form will be submitted to. The url would then look something like this:
http://www.sythe.org/login.php?username=raid&pass=wonttellyoumypwlol

Then you could make a page that displays the info on login.php, as so:
Code:
<?php //php tag
$username = $_GET['username']; //variable to display the username
echo "Welcome $username"; //displays the username here
?> //php tag


What is $_POST?
$_POST displays information on another site without change the url. Basically, we can use the same code as above, but change a few things..

Code:
<form action="login.php" method="post">
Username: <input type="text" name="username" />
Password: <input type="text" name="pass" />
<input type="submit" />
</form>
Only 1 changed, the method="post" instead of get. Once you input the information the url will stay http://www.rscproject.com/login.php without the extra stuff at the end.


$_GET can be used for like an port checker like I made: http://raid.hostei.com/portcheck.html


Final words
PHP can be learned from http://php.net/ . If you wish to get more information go there.


Enjoy,
Raid


Note: report any errors to me via PM.
 
Runescape Gamblingrunescape gambling
Back
Top