-------owned-------
Guru

** copied from my application **
PHP5 tutorial (Personal home page, now known as hypertext pre-processor)
Want to learn PHP5? Then this is the tutorial for you =)
lets start out with FAQ =P
Why use PHP?
Because it can easy connect to MySQL databases, and most servers support it (ASP only supports at Windows) and is much more easier to learn then Perl.
What can I do with php?
Create online shops, forums, user registrations etc. However, this tutorial will NOT show you the most advanced stuff.
part 1
PHP syntax.
a php-script looks like this:
You can configure your php-ini file, and then you can use this:
<?
?>
or asp tags:
<%
%>.
Your first PHP-script:
EVERY php tag SHALL end with ;.
Explanation:
The command echo outputs characters.
The caracters in the quotes (hello world!) will be the result on the page.
If you right-click and press view-source, only HTML code will be there. That's how php work. On windows,
php.exe returns values as HTML. That's why all webbrowsers supports php.
<br> is for a new row.
Part 2
variables
If you're familiar to other programming languages, skip this part, only note that php vars defines with $.
What is variables?
Variables is a kind of file, that stores values. You can later re-use the variable.
When "echoing" a variable, skip the quotes and write var-name (var is for varialbe).
example:
This saves alot of time, if you need to re-use variable.
How to pass variables through pages?
Thats simple
We're going to use sessions
Syntax:
on next page, you can use:
cookies
Cookies saves in the visitors computer (usefull for auto-logging in etc)
Note: a cookie is just a text-file.
Syntax:
for example:
This is self-explanation =P
Re-using cookie script:
This 1 is simple. You simply check if cookie is set, and if it is, the script "echos" the value.
Part 3
Classes and date
To echo date on website, use:
Classes
What is classes?
For example, if we have the class computer, the objects can be:
keyboard, mouse, screen etc.
How do I use classes in PHP?
Syntax:
This is good if you want to create more then 5 properties.
Post values
Ever wondered how sites can "know" your ip adress?
The answer is:
post values!
As you said above, we used $_COOKIE which I call a post value. For example,
look at HTML forms, we need to use that data. Open notepad.
type this:
Save this as nameform.html
Now, save this as postvalue.php:
Now, start your web-server and go to http://localhost/nameform.html
When you get to the page, fill in your name and press submit. Isn't this scary, hah? The webbrowser knows your name ;O. To do this with ip, type the following:
This is what I call post values. The php-program saves IP in the variable ip. In postvalue.php, you can change post to get, but change
$name = $_POST['name']; to $name = $_GET['name']. But a reminder is too always use post when you send data, because get can only handle 4kb, and for safety. If you wanted a register.php and used get, you can see password in url. Hope you liked my basic php tutorial
Hope you all will join me scripting soon
PHP5 tutorial (Personal home page, now known as hypertext pre-processor)
Want to learn PHP5? Then this is the tutorial for you =)
lets start out with FAQ =P
Why use PHP?
Because it can easy connect to MySQL databases, and most servers support it (ASP only supports at Windows) and is much more easier to learn then Perl.
What can I do with php?
Create online shops, forums, user registrations etc. However, this tutorial will NOT show you the most advanced stuff.
part 1
PHP syntax.
a php-script looks like this:
Code:
<?php
code here
?>
<?
?>
or asp tags:
<%
%>.
Your first PHP-script:
Code:
<?php
echo "Hello world!<br>";
?>
Explanation:
The command echo outputs characters.
The caracters in the quotes (hello world!) will be the result on the page.
If you right-click and press view-source, only HTML code will be there. That's how php work. On windows,
php.exe returns values as HTML. That's why all webbrowsers supports php.
<br> is for a new row.
Part 2
variables
If you're familiar to other programming languages, skip this part, only note that php vars defines with $.
What is variables?
Variables is a kind of file, that stores values. You can later re-use the variable.
When "echoing" a variable, skip the quotes and write var-name (var is for varialbe).
example:
Code:
<?php
$name = "Alexander Terry";
echo $name;
?>
How to pass variables through pages?
Thats simple
We're going to use sessions
Syntax:
Code:
<?php
session_start(); //(session register first time)
$_SESSION['name'] = "Alexander Terry";
echo $_SESSION['name'];
session_unset();
session_destroy():
?>
Code:
<?php
session_start();
echo $_SESSION['name'];
session_unset();
session_destroy();
?>
cookies
Cookies saves in the visitors computer (usefull for auto-logging in etc)
Note: a cookie is just a text-file.
Syntax:
Code:
<?php
setcookie(cookiename,value);
?>
Code:
<?php
setcookie("name","-------owned-------");
?>
Re-using cookie script:
Code:
<?php
if(isset($_COOKIE['name'])) {
echo $_COOKIE['name'];
}
?>
Part 3
Classes and date
To echo date on website, use:
Code:
<?php
echo date("ymd");
?>
What is classes?
For example, if we have the class computer, the objects can be:
keyboard, mouse, screen etc.
How do I use classes in PHP?
Syntax:
Code:
<?php
class Person {
var $age;
}
$alex = new Person;
alex->age="25";
echo $alex->age;
?>
Post values
Ever wondered how sites can "know" your ip adress?
The answer is:
post values!
As you said above, we used $_COOKIE which I call a post value. For example,
look at HTML forms, we need to use that data. Open notepad.
type this:
Code:
<form action="postvalue.php" method="POST">
<input type="text" name="name">
<input type="submit" value="Submit name!">
<input type="reset" value="reset field">
</form>
Now, save this as postvalue.php:
Code:
<?php
$name = $_POST['name'];
echo $name;
?>
When you get to the page, fill in your name and press submit. Isn't this scary, hah? The webbrowser knows your name ;O. To do this with ip, type the following:
Code:
<?php
$ip = $_SERVER['remote_addr'];
echo $ip;
?>
$name = $_POST['name']; to $name = $_GET['name']. But a reminder is too always use post when you send data, because get can only handle 4kb, and for safety. If you wanted a register.php and used get, you can see password in url. Hope you liked my basic php tutorial
Hope you all will join me scripting soon

