Welcome, Guest. Please login or register.

Login with username, password and session length
 
Pages: [1]
  Print  
Author Topic: PHP for beginners  (Read 284 times)
Kael
3rd Chair
***
Posts: 220


Zanpakutou: Seishin Seigyoki


Email
« on: November 04, 2007, 09:55:09 AM »

Hey!

This is for people who wants to learn/understand PHP.

I recommend Macromedia/Adobe Dreamweaver as an editor. If you don't have it or if you don't want to get it, Notepad should be enough. Smiley


What is PHP?

PHP means "Personal Home Page Tools". It's a really easy to learn script language which is mainly used for homepages.
It's better if you know the basics of HTML, before you start learning PHP. You can find a very good tut by Itz Blood [here].

PHP is a server-sided language, that means, the server executes the script and it sends you the executed HTML code. Your browser interprets this code and you see the homepage.
PHP is used for dynamic homepages. For example, the most feedback forms, logins and this forum are written in PHP. ".php" is the file extension for PHP files.


How do I use PHP?

Before I said that PHP is a server-sided language. That means, your browser can't interpret these files that easily.
You have got two options:

  • 1. You use a server which supports PHP.
  • 2. You install a local server.

For option 1, you need to google for a host. The host must support PHP. If he does not, you won't be able to execute your PHP files. The better hosts cost money, but there are also free-hosters which support PHP. Usually, free-hosters have some downsides, for example bad speed, low traffic etc. But if you just want to test your scripts, free-hosters will be enough.

In option 2, you can install a server on your own pc. I recommend the XAMPP-Lite package. You can download it for several os here: http://www.apachefriends.org/en/xampp.html.

This package installs the newest version of Apache (a popular server), PHP interpreter and several other useful things.

Important note: Apache Server needs port 80, if it's used or blocked Apache won't work until it's free. Further install information is on the XAMPP-site. If you think XAMPP is installed and started, you can type "localhost" in your browser. If it works, you will see it. Your documents are saved in "\xampp\htdocs".

However, this was the most complicated step. If you have any questions, feel free to ask. It's really hard to install PHP on some systems.


The language "PHP"

I can tell you that it won't work if you write something like that: "Hey PHP! Please give me a guestbook with a lot of cool and crazy smilies! If you don't I will tell your daddy (Rasmus Lerdorf) !!!!11oneoneeleven".  Wink

Nope, we have to be much more... polite. Here i will explain the basics of PHP.

The Structure:

You know, the basic structure of HTML is:
Code:
<html>
<head><title></title></head>
<body>

</body>
</html>

At first, you can place PHP code whereever you want. A dynamic title? Sure. Script in the beginning of the file? No problem. This is a big pro, and the most languages don't support this.

But you have to tell the PHP interpreter that you write in PHP. You can do it like that:
Code:
<?php
// any PHP-code
?>

All the code you write between the tags "<?php" and "?>" will be interpreted as PHP code.

Second, there are comments. The interpreter won't interpret them. They can make the code more clearly, but if you use them wrong they can confuse you too. Comments are initialized with "//".

Example:
Code:
<?php
// This won't cause an error.
?>

Third
, there are variables. What are variables? Well, they are containers of data. If you have any data you want to use later, you should use variables. Variables can be words, sentences or numbers. They are initializes with "$".

Important: You have do embed character strings with a apostroph. Numbers are written without it.

Example:
Code:
<?php
// Example 1:
$string1 'Hello';
$string2 'World';
$string3 '$string1 $string2';
// $string3 will be "Hello World".

// Example 2:
$number1 2;
$number2 3;
$number3 $number1 $number2;
// $number3 will be 5.
?>

Basic commands:

It would be quite useless if the only thing PHP is able to was to tell the interpreter that there will come PHP code.

One thing: Most commands are ended with a ";". If you don't do this, you will get an error.

Of course there are a great many commands. Here a few:

echo:

The echo command is responsible for outputs. If you want to display a text, use "echo".

Example:
Code:
<?php
// Example 1:

echo ('Hello World!');
// you will get: "Hello World!"

// Example 2:
$string 'World';

echo (
'Hello $string!');
// you will get: "Hello World!"
?>

if-else-structures:

If-structures mark conditions. If you want to phrase a condition, you can do it like that:
Code:
<?php
// Example:

$name 'Aizen'
// let's establish a relationship to Bleach xD

if ($name == 'Aizen') { 
   
// if name is Aizen, do something (the double "=" (->"==") is important, it means "Is Equal To"!)
   
echo ('Welcome home, Aizen-sama!');
} else {  
// else do something
   
echo ('Welcome to this homepage, stranger!');
}
?>

After the "{" and "}" isn't a ";"!


What can I do now?

You know...
  • ...what PHP is.
  • ...how to use PHP.
  • ...what variables are.
  • ...a few structures and commands.

Of course, you can't program great homepages with this, but this are the basics, and you will use them very often if you use PHP.

More may come later.

Kael
« Last Edit: November 04, 2007, 11:28:12 AM by Kael » Logged

Aizen
Hougyoku Master
Captain Commander
*
Posts: 1736


Kyouka Suigetsu

ollienorth9@hotmail.com
Email
« Reply #1 on: November 04, 2007, 09:58:56 AM »

Great for teh beginners,thanks a bunch.

Between edit this part
Quote
In option 2, you can install a server on your own pc. I recommend the XAMPP-Lite package. You can download it for several os here: http://www.apachefriends.org/en/xampp.html[/b]]http://www.apachefriends.org/en/xampp.html.
Logged

Kael
3rd Chair
***
Posts: 220


Zanpakutou: Seishin Seigyoki


Email
« Reply #2 on: November 04, 2007, 10:02:10 AM »

thanks, looks like i'm already tired  :cheesy2:
Logged

Aizen
Hougyoku Master
Captain Commander
*
Posts: 1736


Kyouka Suigetsu

ollienorth9@hotmail.com
Email
« Reply #3 on: November 04, 2007, 10:02:59 AM »

No problem Kael,here to help.  police
Logged

Itz Blood
Moderator
Captain
*****
Posts: 939

Bankai: Tensa Zangetsu

battleman021@hotmail.com Itz+Blood
Email
« Reply #4 on: November 04, 2007, 10:24:10 AM »

Nice tutorial dude, I just have to edit that today most phishers are made out of php. Tongue
Logged

-Itz Blood-
I'm Back :cheesy2:!!!


Kael
3rd Chair
***
Posts: 220


Zanpakutou: Seishin Seigyoki


Email
« Reply #5 on: November 04, 2007, 10:39:48 AM »

that's PHP abuse  police
Logged

Itz Blood
Moderator
Captain
*****
Posts: 939

Bankai: Tensa Zangetsu

battleman021@hotmail.com Itz+Blood
Email
« Reply #6 on: November 04, 2007, 11:10:38 AM »

Not really it's just a log script.
Logged

-Itz Blood-
I'm Back :cheesy2:!!!


Kael
3rd Chair
***
Posts: 220


Zanpakutou: Seishin Seigyoki


Email
« Reply #7 on: November 04, 2007, 11:14:06 AM »

yes, but the kind of use is abuse.

it's just like nuclear power: nuclear power station = good use, atomic bomb = veeeery bad use

ok, it might be exaggerated  Grin
Logged

Aizen
Hougyoku Master
Captain Commander
*
Posts: 1736


Kyouka Suigetsu

ollienorth9@hotmail.com
Email
« Reply #8 on: November 04, 2007, 11:25:28 AM »

Yep,we see lot of php used these times.
Logged

Pages: [1]
  Print  
 
Jump to:  




Powered by SMF 1.1.4 | SMF © 2006-2007, Simple Machines LLC
Seo4Smf v0.2 © Webmaster's Talks

Enterprise design by Bloc