PDA

View Full Version : PHP, Basics Part 1



OverlordGenocide
31st March 2005, 11:16 AM
Ok, we will start with the basics of php
You are expected to know how to upload pages, basic html, and how to find servers for webhosting, do not ask me to point you to one, these are the conditions :P
First off, PHP stands for Prehypertext Proccesing Language,
The general point of php is to make a webpage with content that has the ability to automatically change without having to keep uploading it
php is used in quite a few of the popular recruiters around.

I will try to keep things in lament's terms in my descriptions

NOTE: PHP will not work on your computer, you must have a webhost that supports php

A Few Things Explained
Html, is static, in meaning: it does not change
php is not static, meaning: it changes
Html is 'understood' by the browser
PHP is 'understood' by the server its on, before sending the understood page from the server to the browser

Part 1
First of just like in html
you need to tell the browser what code you are using and whether it needs to be understood by the browser first or the server
so in html's case this is:

<html>
Content
</html>
so in the above case, the page is sent straight to the browser because there is nothing special in it
in php's case its sent to the server to be understood before sending the understood page to the browser
NOTE:
<?php starts the understanding of the content
and
?> ends it

<?php
CONTENT
?>


Creating: Our First PHP Page
We are going to create a basic page with php telling the server to say:
this is my webpage
to the browser


<html>
<head>
<title>My First PHP Page</title>
</head>
<body>
<?php
echo 'this is my webpage';
?>
</body>
</html>
Thats it, thats your first php page!
now what you have done is not anything special, its just the same as doing


<html>
<head>
<title>My First PHP Page</title>
</head>
<body>
this is my webpage
</body>
</html>

however php can be used for more than that obviously :fireworks

Continuing on with variables

however, the echo command can be used to print variables
variables, are wildcards that can be used to store information
a variable is stored like this

$variable = 'SOMETHING';

so SOMETHING is defined in the variable $variable
so if we where to do this:


<html>
<head>
<title>My First PHP Page</title>
</head>
<body>
<?php
echo $variable;
?>
</body>
</html>
it would tell the server to get some information from the variable $variable and then tell the browser what is contained in $variable which in this case is:
SOMETHING

this can be very useful, if you wanted to affect the entire content of a site, just by changing one thing in the page

lets say i wanted to create a page with changeable content affected by a variable
i could have the variables in an entirely different page to the page they are using this is done like this:
Create a page called config.php for example
and enter inside it

<?php
$variableone = 'WHAT I WANT HERE';
?>
save it
now create another page for example named: index.php
and enter

<html>
<head>
<title>My 2nd PHP Page</title>
</head>
<body>
<?php
include 'config.php';
echo $variableone;
?>
</body>
</html>

Ok, what we have done here is stored a variable named $variableone in config.php and told the server to
include that page config.php, just incase i want to request (ask for/grab) a variable from it, which i did, i told the server to tell the browser what was stored inside $variableone, which was stored in another file named config.php
which then told them
WHAT I WANT HERE

Ok, i will continue the rest of the tutorial later, that should keep some of you busy for now

Azrael
31st March 2005, 01:08 PM
Nice little tutorial genocide. If people are looking for more indepth help I would suggest www.webmonkey.com or buying any o'really book on PHP (especially the In A Nutshell series, also for a excellent PHP function refrence Core PHP is top notch).

Also as note you can actually install PHP and have it running on your computer *fairly* easly. Check out the php website (http://www.php.net) and download the precompiled win32 binaries (I'm assuming if you need to read this your running windoze) and just follow the install and readme instructions to get it working. Heck you can even install a copy of MySQL (http://www.mysql.com) if you want to get a copy of PHP-Nuke or something with a database backend working on your personal comp.

OverlordGenocide
31st March 2005, 01:16 PM
I would also like to add that the
Print command is the same as echo
and can be used for the same things as in the tutorial above

print 'WHAT YOU WANT HERE';

whirlwind
3rd April 2005, 09:06 AM
Just Something you might want to add with your include, its often better to use this instead:



<?php
require_once("config.php");
?>


reason for this being, if you include it in another file, it will cause an error in the page, and also you can set it to end the page if you do not include the file, for example, if you need the contents of the file for the page to work, and the file is used using include() and it doesnt include, it will cause security problems. Using require() will end the page output.

Pegasus
19th April 2005, 12:57 PM
its a good learning part but it can be better

If you have suggestions on how to make it better then by all means post them, otherwise this type of post really isn't helping anyone. ~Flocito