.########...######..########..########

.##.....##.##....##.##.....##.##......

.##.....##.##.......##.....##.##......

.########...######..########..######..

.##.....##.......##.##...##...##......

.##.....##.##....##.##....##..##......

.########...######..##.....##.##......

http://blacksun.box.sk/
Lecturer & Converter: AZTEK
Lecture: PHP Basics





<marie> Don't drop any missile on Africa, Cyberwolf!
<Guy_SJS> haha
<Cyberwolf> nah i wont :)
* Guy_SJS bombs Saudi Arabia
<Cyberwolf> k, i have a little announcement to make
<Guy_SJS> you getting laid?
<Cyberwolf> everyone pay attention please
<FatalCure> Raise your hand if your going to DefCon
<Cyberwolf> Guy: not yet :)
<Guy_SJS> lol
* chiken will be going next year
<Cyberwolf> AZTEK is going to give an improvised lecture on PHP
<Cyberwolf> so everyone pay attention and start logging :)
<AZTEK> ok sup ppl
<bluehaze> woop
<Serial_Killer> sup
<chiken> yay
* bluehaze wants voice :-)
*** Cyberwolf sets mode: +v AZTEK
<Serial_Killer> me too
<Serial_Killer> ?
<AZTEK> does anyone have any prior experiance in php
<Serial_Killer> :)
<Serial_Killer> ynot really
<Serial_Killer> not*
<bluehaze> not much
<bluehaze> but..  a tiny tiny bit
<AZTEK> if you look around the web now you see the extentions .php3 and .php and .php4 alot more now
<AZTEK> even on box
<Cyberwolf> in rare occasions .phtml also
<AZTEK> yes
* bluehaze sees .asp more
<AZTEK> that to
<bluehaze> :-)
<AZTEK> what php is is a scripting language inseted into html documents
<marie> php when looking for things on altavista.
*** Ghost_Rider has quit IRC (Quit: "You may stop this individual, but you can't stop us all... after all, we're all alike." -)
<AZTEK> when the server gets a request for a .php or .php3 document
<AZTEK> it starts up the php module(engin)
<Serial_Killer> btw what PHP stands for
<Serial_Killer> ?
<AZTEK> the module strips out all of the php tags an leaves their return values in their place
*** bluehaze has quit IRC (Quit: good users don't use colored quits)
<AZTEK> PHP: HyperText Preprocessor
<AZTEK> thatnks for the ? i almost forgot
<Serial_Killer> np
<Serial_Killer> but why P comes first
<AZTEK> thought i have also seen Personal Homepage Preprocessor
<Serial_Killer> oks
<AZTEK> PHP tags are started <?php and ended ?>
<HardW1r3> ok in someones opinion what is the best book to learn perl from?
<AZTEK> anything in those tages is attemted to be executed by the module
<Serial_Killer> PErl by example
<Serial_Killer> great book
<HardW1r3> cool
<AZTEK> Perl : Black Book
<HardW1r3> thx
<HardW1r3> ok
<AZTEK> now on to php
<AZTEK> you can also use <? to start and ?> to end (not good if you use xml
<AZTEK> or the <% %> asp tags are also accepted in some casses
<AZTEK> any comments in php can be given the c type comment which is eyerthing between /* and */
<AZTEK> the C++ type comments which is everything on the line after the //
<AZTEK> and also the unix shell comments which is every thing on the line after the #
* Serial_Killer does not know C++
<AZTEK> its alright
<AZTEK> now to run php scripts you need access to a server that runs the php module
<AZTEK> some people(inculding me) have set up test servers on their computers
<AZTEK> everyone got this so far
*** DockAlfer has joined #bsrf
<Cyberwolf> yup
<Serial_Killer> not really
<Serial_Killer> :)
<AZTEK> its ok
<Cyberwolf> damn, i gotta go, plz send me the logs at: cyberwolf@urgent-urgent-urgent.com
<Serial_Killer> hehe
<Cyberwolf> bye all
*** Cyberwolf has quit IRC (Quit: Life without risk is no life at all)
<AZTEK> i will cyberwolf
<Serial_Killer> too late
<_medved-> where am I?
<AZTEK> now as most programmers know usully the first thing you learn to do is output the text Hello, World
<AZTEK> iNPROV php lecture
<AZTEK> so here is the line that would do this
<AZTEK> <?php
<AZTEK> echo "hello world";
<AZTEK> ?>
<AZTEK> as i have said the <?php tells the engin to start executing the code after it
<AZTEK> the echo command simply outputs the text to the screen
<AZTEK> every stament as in other anguages is ended with a ; (simicoln)
<AZTEK> the the code is ended with a ?>
<AZTEK> to tell the engin to stop executing
<AZTEK> everyone following along
*** DockAlfer is now known as DockAl[shower]
<Serial_Killer> yeahh
<FatalCure> uh huh
<AZTEK> no seriously if you arnt tell me
<AZTEK> i will go back
<AZTEK> can anyone tell me the difference between php and perl
<HardW1r3> ive heard that it is better somehow but im not sure how
<HardW1r3> i dunno
*** bomb8595 has joined #bsrf
*** GhostDog has quit IRC (Quit: The surest sign that intelligent life exists elsewhere in the universe is that it has neve)
<HardW1r3> hey bomb
<AZTEK> perl is better in the sence it has been around longer and has more librarys
<bomb8595> hi
<HardW1r3> ah
<HardW1r3> k
<FatalCure> perls engine is started by #!/usr/bin perl
*** Mikkkeee has joined #bsrf
*** ChanServ sets mode: +o Mikkkeee
<HardW1r3> hey mikkkeee
<AZTEK> php on the other hand is faster(in some retrospect), and is easyer to insert into html
<AZTEK> hi mikkkeee
<Paya> hi mikkkeee
<Serial_Killer> AZTEK what u think which one is better
<Serial_Killer> ?
<Mikkkeee> hey guys
<AZTEK> i personally like php better
<Serial_Killer> any reasons for that
<AZTEK> it is easy to learn and was specifficly desinged for cgi work
<Serial_Killer> o.k
<AZTEK> while perl was designed for exracting and listing text files
<AZTEK> quote the name pratical extraction and reporting language
<Mikkkeee> yahoooooooooooo a php lecture
<AZTEK> but dont let php fool you it is extreamly prowerful
<Mikkkeee> want to make it a real one aztek?
<Paya> yes, sure
<Mikkkeee> k
<AZTEK> its best advantage is its ability to interacte with databasses
<AZTEK> sure
*** Mikkkeee sets mode: +m
*** Mikkkeee sets mode: +v Balle[away]
*** Mikkkeee sets mode: +v bomb8595
*** Mikkkeee sets mode: +v Casper[WORK]
*** Mikkkeee sets mode: +v chiken
*** Mikkkeee sets mode: +v Crash_Gnome
*** Mikkkeee sets mode: +v EliteLamer
*** Mikkkeee sets mode: +v FatalCure
*** Mikkkeee sets mode: +v Grendel
*** Mikkkeee sets mode: +v DockAl[shower]
*** Mikkkeee sets mode: +v HardW1r3
*** Mikkkeee sets mode: +v Kage
*** Mikkkeee sets mode: +v Liquid
*** Mikkkeee sets mode: +v marie
*** Mikkkeee sets mode: +v Serial_Killer
*** Paya sets mode: +v _medved-
*** BootError has joined #Bsrf
*** Paya sets mode: +v _MikeStevens-
*** Mikkkeee sets mode: +v BootError
*** Mikkkeee sets mode: +o AZTEK
<AZTEK> php4 now has built in mysql capability
<bomb8595> mikkkee: meeting?
<Mikkkeee> aztek hold a bit
<Mikkkeee> okay lets start
<AZTEK> to make a short list php can interact with orcale,mysqu,msql,mssql,access,and many more dtabasses
<Mikkkeee> ______  _______  ______ _______
<Mikkkeee> |_____] |______ |_____/ |______
<Mikkkeee> |_____] ______| |    \_ |
<Mikkkeee>
<Mikkkeee> okay php lecture time
<Mikkkeee> lecturer=AZTEK
<BootError> Woot!
<HardW1r3> go aztek go
* BootError boos
<AZTEK> thanx
<BootError> No problemo
<Serial_Killer> np
<BootError> :))
<Mikkkeee> its all yours
<AZTEK> now anyone with any programming know how knows that programs are no good without variables
<AZTEK> well php uses the $ (us dollar) sign to decalre a variable
* Balle[away] 0,12 Away 0,1 Balle 15is not here 11(0Im sleeping.. goddamit..11) (022:09:38 11)
<Paya> like in Perl
<AZTEK> yes like in perl
<AZTEK> but php does it little different
<AZTEK> for an array
<AZTEK> perl would use the @ sign
<AZTEK> well in php their is no special sign
<Paya> ?
<AZTEK> an array is defined as $hello[0]
<AZTEK> as wih in perl it would be @hello
<AZTEK> php like perl defines the variable type for you
<FatalCure> so an array in php is deffined the same way a variable would be in perl, as in $hello["1", "2", "3"]
<Mikkkeee> is it?
<AZTEK> so you dont have to define a variable as a interger or a string explictly
<BootError> kool
<FatalCure> aahhh
<Mikkkeee> k
<AZTEK> no in php you cant define multiple cells at once
<AZTEK> as far as i know
<AZTEK> so like $hello[0]="Hello"
<AZTEK> $hello[1]=12
<Paya> how do u mean "can't define multiple cells", then PHP is a crap
<AZTEK> and $hello[2]="12" all work
<AZTEK> its a downfall
<AZTEK> you can define multiple cells
<AZTEK> just not at once
<Paya> great
<AZTEK> not like you had it
<Mikkkeee> hey aztek if u got time at the end, get out some precoded scripts and explain the code in each?
<AZTEK> ok
<AZTEK> like the one for you
*** bomb8595 has quit IRC (Quit: )
<AZTEK> so
*** bomb8595 has joined #bsrf
*** DockAl[shower] is now known as DockAlfer
<AZTEK> <?php
<AZTEK> $hello="Hello";
<AZTEK> echo $hello;
<AZTEK> ?>
<AZTEK> gives us Hello
<AZTEK> out to the screen
<BootError> PHP reminds me of C, DOS batch file programing and Basic
*** MANOWAR^ has joined #bsrf
<AZTEK> exactly
<AZTEK> now has anyone had any past experiance with Java,Javascript,C/C++
*** Mikkkeee sets mode: +v bomb8595
<AZTEK> Javascript is especially good
* BootError has
*** Mikkkeee sets mode: +v MrJezus|Gaming
*** Mikkkeee sets mode: +v MANOWAR^
<Paya> me, with C/C++
<AZTEK> good
*** chiken has quit IRC (Quit: If I told you I was lieing, would you believe me?)
<MANOWAR^> -v plz
<Paya> Perl...
*** Mikkkeee sets mode: -v MANOWAR^
<BootError> BASIC and C
<AZTEK> because as you will notice the syntax looks alot like C/C++,Javascript,Java
<AZTEK> and perl
<Paya> hehe
<AZTEK> if your server uses Apache (almost everyone does) their are predefined variables you can work with
<AZTEK> like $REMOTE_ADDR will give you the clients ip address
<Mikkkeee> back to the lecture plz
<AZTEK> yes it has to be caps
<Paya> u mean %ENV arrays
*** DreaMeR has joined #bsrf
<AZTEK> yes the same thing
<AZTEK> as it is in perl
<Paya> $QUEARY_STRING...
<Paya> *$QUERY
<AZTEK> now to output a variable in php
<AZTEK> same thing
*** Canticle has joined #bsrf
<AZTEK> you can use the echo command
*** IriSh-IrO has joined #bsrf
*** IriSh-IrO has quit IRC (Client exited)
<AZTEK> so echo $hello;
<AZTEK> would out put the the contents of $hello
*** _newbie- has joined #bsrf
<AZTEK> you can also use variable in strings
<AZTEK> like in $hello="Hello, $world";
<Paya> like in Perl print "Your age is: $age\n";
<AZTEK> the string would consist of the words Hello, and whatever is in the variable $world
<AZTEK> yes
<AZTEK> thanks Paya
*** Paya sets mode: +v _newbie-
<AZTEK> now a thing that makes php great and gives it an advantage over perl is
<AZTEK> the valuse passed to your php script
<AZTEK> via an html from are made into variable themselves imdiatly
<_newbie-> does IIS support php?
<_newbie-> i mean, is there a plugin
<AZTEK> so <input type="text" name="hi">
<AZTEK> yes it does
<_newbie-> ah ok
<Mikkkeee> aztek will u got into db's?
<_newbie-> continue, i wanna learn php too hehe
<AZTEK> when sent to your programm the variable $hi will have the value of that text fiels
<AZTEK> *field
<AZTEK> not today
<AZTEK> maybe in a follow up tut
<Mikkkeee> yup
<_newbie-> ok
<AZTEK> does everyone understand the basics of php variable
<Paya> yes, continue
<_newbie-> yep
<FatalCure> uh huh]
<AZTEK> now another thing a script/programm can not be without is flow control
<AZTEK> the ifs, elseifs, and elses
<marie> No, but it's alright. I need to go, goodbye.
*** marie has quit IRC (Quit: )
<AZTEK> a if statment is the exact same as if it were in a C programm
<AZTEK> the syntax for a if stament is
<AZTEK> if (condention) {
<AZTEK> BLOCK of code;
<AZTEK> }
<AZTEK> if the condention exicutes to be true then the code inside the brakets is executed
<AZTEK> example
*** _newbie- has left #bsrf
*** DreaMeR has quit IRC (Client exited)
<AZTEK> if($hello="Hi") {
<AZTEK> echo $hello;
<AZTEK> }
*** vanished has joined #BSRF
<FatalCure> can you set a verable to recive keystrokes and then use that in an if statment?like STDIN w/ perl?
*** Mikkkeee sets mode: +v vanished
<AZTEK> you can add ifelse to
<AZTEK> no
<vanished> thanks
<AZTEK> php is strictly a cgi language
<AZTEK> ell not anymore but i will get to that later
<AZTEK> so
<AZTEK> if($hello="Hi") {
<AZTEK> echo $hello;
<AZTEK> } else {
<AZTEK> echo "No Hello";
<AZTEK> }
<AZTEK> is an example of flow control
<AZTEK> if the value of th variable $hello is not the string Hi the the code in the else stament is executed
<AZTEK> everyone got this so far
<vanished> ya
*** Paya sets mode: +v Canticle
<HardW1r3> yup
<AZTEK> you can have as many ifs anf ifelses as you need but you can only have one else
<AZTEK> or the engin will get confused
<Canticle> ya.. when php code runs is it something like mod_perl? Im a php newbie but Ive used mod_perl and perl
*** Kazzuyo has joined #bsrf
<AZTEK> now i will go onto loops so those of you who don't understand please speak up
*** Mikkkeee sets mode: +v Kazzuyo
<Kazzuyo> hi
<AZTEK> it can be a module in apache or an external program that parsses the script and returns it
<Kazzuyo> brb
<Canticle> so like perl?
*** Kazzuyo has left #bsrf
<AZTEK> yes
*** wishmaster has joined #bsrf
*** ChanServ sets mode: +v wishmaster
<Canticle> thanks
<wishmaster> yo all
<wishmaster> wasssup guys>?
<AZTEK> only the program or module has to be defined in the apache conf files
<Paya> we're in the middle of the lecture
<AZTEK> unless you wan to add #!/usr/bin/php
*** Kazzuyo has joined #bsrf
* Canticle nods
*** _052_ has quit IRC (Ping timeout)
<AZTEK> or whatever you php executalbe is and make it like perl
<AZTEK> which is not recomended
<AZTEK> the for loop
<Mikkkeee> yo wish its a php lecture
*** Mikkkeee sets mode: +v Kazzuyo
<AZTEK> anyone with a C/C++,Java(script) background know theis next few
<AZTEK> the for loop follows the syntax
<_medved-> YO to wishmaster
<Mikkkeee> heh
*** Paya sets mode: -v _medved-
<vanished> ya
<AZTEK> for (starting variable ; lopp unstill this is false ; the increcment) {
<AZTEK> }
<vanished> for (i=0; i<10; i++)
<Kazzuyo> cool.....
<AZTEK> theis are very good for arrays
<Paya> just like in Perl
<AZTEK> you need the $ before the variables
<AZTEK> yep
<vanished> ya
<vanished> oops
<AZTEK> so
*** Sigma has joined #bsrf
<Canticle> php have all the same variables that are in perl? string,hash,array?
*** Mikkkeee sets mode: +v Sigma
<AZTEK> for ($i=0;$i<10;$i++)
<AZTEK> {
<Sigma> Thanks Mike
<AZTEK> echo "hello";
<AZTEK> }
<AZTEK> print aout hello untill the variable $i is ten
<Sigma> php doesn't have a seperate data structure for associative arrays (hashes). They just let you use strings as keys on any array
<AZTEK> yes php has all the same variable
<AZTEK> thats correct
<Sigma> So, @array could be a normal array, or a hash
<vanished> php is glorified perl basically
<Canticle> I see ok
<AZTEK> scice everytime the code is run the $i++ runs at the end
<Sigma> vanished: I agree, but it handles variables and input so well =)
<AZTEK> the for loop will end after 10 times
<vanished> ya
<Canticle> from what Ive heard php is basicaly streamlined for serving content that perl does but faster
<Canticle> for web pages
<vanished> php is also a lot more secure :)
<AZTEK> yes
<AZTEK> not so much
<AZTEK> i might get to that later
<Canticle> flexability = insecure :)
<vanished> true
*** Duff19 has joined #bsrf
<vanished> better than straight perl though
<AZTEK> it also handles out put better
<vanished> right
<Sigma> It's not all that hard to output with perl
<vanished> no
<AZTEK> instead of having to use ssi includes or writing your whole page in perl
<Sigma> SSI is slow =\
<AZTEK> you can just insert the php tags
<AZTEK> example
*** Mikkkeee sets mode: +v Duff19
<AZTEK> <title><?php echo $title; ?></title>
<Canticle> curious tho for that page tho where would $title  be defined?
<AZTEK> the would put between the html title tags the value of the variable $title
<AZTEK> in an external file
<AZTEK> i will get to that later
<Canticle> ah cool
<Sigma> Canticle, it might've been in a file, or input from another webpage
<Canticle> I see, variables in php pages are persistant from one to another?
<AZTEK> now from the for loop to the while loop
<Mikkkeee> so whats the output of the <title> a normal html title?
<Canticle> sorry :) I got off topic back to loop
* Sigma is afk
*** Sigma is now known as Sigma[a]
<AZTEK> <title>Your title</title>
<AZTEK> now from the for loop to the while loop
<vanished> gotta do homework
<AZTEK> the while loop folows the syntax of
<vanished> bbl
*** vanished is now known as vanished[homework]
<AZTEK> while(this is true) {
<AZTEK> do this
<AZTEK> }
<AZTEK> so
*** Duff19 has quit IRC (Quit: Leaving)
<AZTEK> while($hello="Hi") {
<AZTEK> echo "Loop";
<AZTEK> }
<AZTEK> this will of course never end
<AZTEK> and will crash the browser eventully
<AZTEK> which is bad
<AZTEK> the do is esentilly the same it is
<AZTEK> do {
<AZTEK> always do this once
<AZTEK> } while (do it agian if this is true)
<AZTEK> i forgot the ; after the while
<AZTEK> so
<AZTEK> do {
<AZTEK> echo "Hello";
*** Kazzuyo has quit IRC (Quit: K2K)
<AZTEK> } while($hello1<4);
<AZTEK> this will run once and then run untill the while statment is false
<AZTEK> everyone got it
<Canticle> I know you did the if/else.. is there a case statement as well? Case is usualy easier for me to read if there are 3+ choices
<AZTEK> yes
<AZTEK>  i belive
<AZTEK> its is
<AZTEK> switch($varable) {
<AZTEK> case :
<AZTEK> default :
<AZTEK> }
<AZTEK> you know how is goes
<Canticle> ok cool. :)
<AZTEK> now i am going to my final and bigest section
<AZTEK> drum roll please
<AZTEK> dudududududud
<AZTEK> file input/output
<AZTEK> this is probly the biggest difference between php and perl
<Paya> finaly
<AZTEK> to open files in php you use the fopen command
<AZTEK> so
<AZTEK> the syntax is
<Mikkkeee> finally
<Paya> k
*** _052_ has joined #bsrf
<AZTEK> $filehandle=fopen("filename","");
<AZTEK> sorry i had to get through the other stuff
*** voodoochild has joined #bsrf
*** Mikkkeee sets mode: +v voodoochild
<AZTEK> the variable $filehandle contans the memory address of the open file for easy access
<AZTEK> the filename is of course the filename
<AZTEK> where the double quotes are
<AZTEK> in their there should be one of the following
<AZTEK> 'r' - Open for reading only; place the file pointer at the beginning of the file.
<AZTEK> 'r+' - Open for reading and writing; place the file pointer at the beginning of the file.
<AZTEK> 'w' - Open for writing only; place the file pointer at the beginning of the file and truncate the file to zero length. If the file does not exist, attempt to create it.
<AZTEK> 'w+' - Open for reading and writing; place the file pointer at the beginning of the file and truncate the file to zero length. If the file does not exist, attempt to create it.
<AZTEK> 'a' - Open for writing only; place the file pointer at the end of the file. If the file does not exist, attempt to create it.
<AZTEK> 'a+' - Open for reading and writing; place the file pointer at the end of the file. If the file does not exist, attempt to create it.
*** Canticle has left #bsrf
<AZTEK> so example
<AZTEK> $fh=fopen("hello.txt","r");
<AZTEK> would open the file hello.txt for reading
<AZTEK> to get the data from that file you use the fread command
<AZTEK> the synatx for that is
<AZTEK> $store=fread($filehandle,lenght to read to);
*** vanished[homework] is now known as vanished
<vanished> back
<AZTEK> the $store varible is the varible to store the read value in
*** wishmaster has quit IRC (Quit: )
<AZTEK> the file handle is what we defined when we opened the file
<AZTEK> now the length is special
<AZTEK> to read the entire file you would put
<AZTEK> filesize("hello.txt")
<AZTEK> you CAN NOT put the file handle or it wont work
* Mikkkeee says is everyone awake?
<AZTEK> so
<AZTEK> $hello=fread($fh, filesize("hello.txt"));
<AZTEK> reads the entire file hello.txt into the varible $hello
<AZTEK> now reading is no fun if we cant write to a file
<AZTEK> but first we have to close the file as to not take pressious ram memory
<AZTEK> so we use fclose
<AZTEK> the sytax is fclose($filehandle);
<AZTEK> simple
*** MANOWAR^ has quit IRC (Quit: Ping timeout)
*** Mikkkeee has left #bsrf
*** Mikkkeee has joined #bsrf
*** ChanServ sets mode: +o Mikkkeee
*** N0S01uti0n has joined #bsrf
<AZTEK> now that we have the old file closed we can open the same file for writing
*** Mikkkeee sets mode: +v N0S01uti0n
<AZTEK> so we
<N0S01uti0n> hey i need a short naritive about drugs/narcotics for my health class... anyone know where i can get one
<N0S01uti0n> thanks mike
<AZTEK> $fh=fopen("hello.txt","w");
*** DockAlfer has quit IRC (Quit: Good night.)
*** Paya sets mode: +v _medved-
*** Mikkkeee sets mode: +v _052_
*** BootError has quit IRC (Quit: BootError Bot 6.0 Gamma (Shutdown code 3.2 Beta))
<AZTEK> then we use the fwrite command
*** G0lD has joined #bsrf
*** Mikkkeee sets mode: +v G0lD
<AZTEK> the syntax is fwrite($fh,string to write to file,optional value of the length to write);
<AZTEK> so
<AZTEK> fwrite=($fh,"Hello");
* Balle[away] 0,12 Away 0,1 Balle 15is not here 11(0Im sleeping.. goddamit..11) (022:09:38 11)
<AZTEK> now some people can see how you could write the contents of an html form to a file
<G0lD> does someone in here understand run levels ?
<HardW1r3> shhhhh lecture
<AZTEK> now i am going to write a short followup tut with code example and i will cover more file i/o
<AZTEK> but after you are done writing make sure to close the file
<AZTEK> with fclose($fh);
<AZTEK> and that basicly condludes the php lecture
<AZTEK> any questions
<Mikkkeee> damn, i need the whole log
*** Serial_Killer has quit IRC (Quit: ALL FOR ONE,ONE FOR ALL!!!!!!!)
<AZTEK> i will write the follow up in a few days
<Paya> I have it
<AZTEK> i got one
<Mikkkeee> okay who will mail me the log
<Mikkkeee> the complete one
*** Mikkkeee sets mode: -m
<Mikkkeee> okay cut log here

<--------------End of lecture------------>