Home
Help
Search
Calendar
Login
Register
Please
login
or
register
.
1 Hour
1 Day
1 Week
1 Month
Forever
Login with username, password and session length
News:
New forum theme up and running!
Charas-Project
»
Off-Topic
»
Archive
»
Really Old Stuff
»
PHP
(Moderator:
De KoFfieŠ
) »
Php: Lesson 1
« previous
next »
Print
Pages: [
1
]
Author
Topic: Php: Lesson 1 (Read 7075 times)
Alex
I am the MASTER!
Administrator
Exemplar
Posts: 1,130
Php: Lesson 1
«
on:
September 10, 2003, 11:32:42 PM »
I'm opening this because i think it can be helpful for everyone.
The discussion begins with SereneRose, asking how to start with php.
Well, first of all here is what you should know:
1) Some html knowledge, meant as pages written with notepad, not Frontpage or similar.
2) Basic knowledge of the form and input tags.
3) a little of javascript doesn't hurt!
Now, let's start.
First of all, what is PHP? It is, in the words of
, a widely-used general-purpose scripting language that is especially suited for Web development and can be embedded into HTML.
What does it mean?
Simple!
Imagine a simple html page as this:
<html>
<head>
<title>My page</title>
</head>
<body>
Hello world!
</body>
</html>
This is just a text file, nothing more.
What makes it looks like we expect is our browser.
So, the server who "served" us this page simply send us that few lines of code.
The resulting layout has nothing to do with the server, it is shown by our browser in our machine.
To say it in other words, it is executed in
client side
.
The client, obviously, is our machine.
Php is a
server side
language: it generates the final code to be sent to us on the server.
This is why you cannot view a php file simply by opening it in your browser: you need a server behind to process the php code, first.
Note that it's not needed that the server is over the internet: you can also have something installed on your PC (as PWS, Personal Web Server) and all is fine anyhow. Simply you have to tell your server that files with .php extension have to be parsed with the PHP executable before being sent to the client.
Anyhow, if you have a free host on the net which provide php support, you dont need a local server (as PWS is).
So from now i will consider you have a php enabled host where you can upload and test your scripts.
Now: what the hell means "it generates the final code to be sent to us on the server"???
Answer with a simple example.
Consider the simple html page written before and give a look to this variation (call it test.php):
<html>
<head>
<title>My page</title>
</head>
<body>
<?php
print "Hello world!";
?>
</body>
</html>
if you try to open it locally (i mean without a server, as a local file), the layout you'll see in the body will be:
<?php
print "Hello world!";
?>
If you open this from a php enabled server (for example, calling in your browser lycos.com/users/myname/test.php), the layout will be simply:
Hello world!
It's simple to understand what happens: the <?php and ?> tags delimits the php code. Only what is writeen inside these tags will be parsed by php, the rest of the code will be sent to the client without modifications.
So that
print "Hello world!";
line is our first line of php code!
As expected, print is simply a... print command.
What is enclosed in the quotes is the string that will be printed out.
And finally, remember that the ; at the end is required. If you'll not put that, you'll see a beautiful "PARSE ERROR!" instead of the expected Hello world.
Also, remember that in a php file can be present multiple php tags.
For example, this is good too:
<html>
<head>
<title>My page</title>
</head>
<body>
<?php
print "Hello world!";
?>
<?php
print "Hello world Again!";
?>
</body>
</html>
Now, if you try to open this file, you already know what you'll see.
But now, after loading this, try to use the "view source" command of your browser: what you'll see is this:
<html>
<head>
<title>My page</title>
</head>
<body>
Hello world!
Hello world Again!
</body>
</html>
This should clear definitively the difference between
client
and
server
side.
The server reads and parse everything written between the php tags, the client will see only the resulting code.
So you cannot use php to act as a local language: for example, you cannot use php to delete a file into the client hard disk.
Ok, i think that's enought, right now.
Sorry if a bit long, but better be sure you really understand this, before going over.
If there are question or something which is not clear, ask.
Better asking now than when it's too late!
Logged
SereneRose
Member
Initiate
Posts: 39
Nothing to say.
(No subject)
«
Reply #1 on:
September 11, 2003, 12:58:07 AM »
Hey perhaps you would know of some free servers who support php?? That could be useful lol and thanks it cleared up some and made easier to understand...
Logged
http://www.everseeingrpg.tk
~Psh ^_^ Pretty new Intro on my page Heh~
Alex
I am the MASTER!
Administrator
Exemplar
Posts: 1,130
(No subject)
«
Reply #2 on:
September 11, 2003, 01:06:13 AM »
Hey hey... first rule of the good "student": read and search as much as you can, before asking!
Anyhow, this is the first lesson, i will be smiley and calm...
In this forum:
Forum host?
About searching: just try a simple "free php hosting" in google
Logged
SereneRose
Member
Initiate
Posts: 39
Nothing to say.
(No subject)
«
Reply #3 on:
September 11, 2003, 01:13:59 AM »
Maybe that's why i was never that GOOD of a student... LoL ok i'll search.. ~grumble homework~
Logged
http://www.everseeingrpg.tk
~Psh ^_^ Pretty new Intro on my page Heh~
SereneRose
Member
Initiate
Posts: 39
Nothing to say.
(No subject)
«
Reply #4 on:
September 11, 2003, 04:21:25 AM »
If i was able to read and understand other languages i would be set... every page i went to for it well couldnt understand what they said. But yeah i am getting the hang of it, i'll have to add it to my web notebook.. has some html codes and color codes and such so i can have some easy look up if i need to recall somthing lol. but thanks
Helpful indeed.. So whats next teach?? ~_^
Logged
http://www.everseeingrpg.tk
~Psh ^_^ Pretty new Intro on my page Heh~
Alex
I am the MASTER!
Administrator
Exemplar
Posts: 1,130
(No subject)
«
Reply #5 on:
September 11, 2003, 11:15:17 AM »
Uhm, so you think what i say is CLEAR?
Ok, then!
Leave this topic (anyone who have question on this part can still post here) and go over for
Lesson 2
!!!
Logged
whitewolf
The Tyrant
Associate
Posts: 180
(No subject)
«
Reply #6 on:
September 11, 2003, 03:41:00 PM »
Hey where can I get a personal web server? my net is not so fast so I need something Local and good job Alex.
Logged
whitewolf
The Tyrant
Associate
Posts: 180
Curious
«
Reply #7 on:
September 11, 2003, 03:45:02 PM »
Oh and does it work in Word pad? I know that HTml is mostly done in Notepad but i don't know about PHP.
You know sometimes when u open a file it sez
"File is too large. Do u want Word Pad to open it"?
Logged
Alex
I am the MASTER!
Administrator
Exemplar
Posts: 1,130
(No subject)
«
Reply #8 on:
September 11, 2003, 04:32:35 PM »
Well, notepad or wordpad is the same.
With wordpad, just remember to save the file as plain text.
Anyhow, you will never have many problems about file size: both html and php are text files, personally i never had to use wordpad instead of notepad!
About a personal web server: it depends.
If you're running win95/98/NT, then give a look here:
http://coveryourasp.com/PWS.asp
If Win2000/XP: they have IIS included. Go to Control Panel, Add/remove programs, Windows components and you'll see an IIS checkbox.
If Linux (or any windows), you can install Apache (and this is THE BEST). But be prepared to read some docs too: it's not difficult, but nor super-easy.
http://httpd.apache.org/
After the http server (yeah, all of these are http servers), you need to check if they're already php enabled. PWS and IIS are probably not.
So the next step is installing and configure php (
http://www.php.net
).
Go and download your needed distribuition.
If on windows, i suggest the zip bynary one (last version now is the PHP 4.3.3 zip package). The readme/install file is very clear, with explanation for every of the server presented here.
You should'nt have problems.
Logged
Print
Pages: [
1
]
« previous
next »
Charas-Project
»
Off-Topic
»
Archive
»
Really Old Stuff
»
PHP
(Moderator:
De KoFfieŠ
) »
Php: Lesson 1