[home] [<-back] [index] [next->]




 ____________________________________________________________________
 
[12:. - [ ninja-lessons in php ]                            [tak] :. ]
                                                    [tak@b0g.org] :. ]
 ____________________________________________________________________




Hi, this is a thing we are going to be doing. It's my attempt at teaching PHP to all
you. I am no expert, however our TRESS is. I am going to start at the basics. This is
not advanced, or even for people who got a clue. This is starting out at nothing and
stuff.

First thing, you gotta have php installed. I hate when people try to run php without
php. Whoa. Php isnt like HTML, HTML IS TEXT sent to your browser that your browser
takes and makes pretty. Php is the server side stuff that makes the calls. A few
examples of this could be a bulletin board, a counter, or even a news manager ;) Once
you have php installed[php.net] you can start the shit. First thing is first, all
your php code should be inside php tags. These tags let the webserver execute the
code before sending out data. These tags are by default "{C}{C}{C}{C}" you can
optionally use  tags and also ASP style tags if they are configured in your php
configuration. Ok got it? Now with the stuff that you might want.

I have noticed that working with existing code is the easiest way to learn. Also
writing the code all over again as opposed to copy + pasting is makes it stick
better...It's harder but works.

Well as i write this, and watch tv i know its gonna suck and be a failure but
whatever you can go fuck a horse, im a ninja.

Lets set some shit strait, strings contain a value.

$string = "data";

makes $string contain the word 'data' GET IT?
so now you could make a script like



that will ECHO $string wich is 'data' so your web browser will display that elite 4
letter word.
Now alot of people ask about shit like:
http://www.domain.tld/index.php?string=data&string2=data2

That is just like saying:
$string = "data";
$string2 = "data2";

you can pile them up as much as you want, just seperate them with &'s,
next example will be
http://www.blah.tld/index.php?string=hello&string2=world

that will as you guesses[i sure fucking hope] hello world
A . combines strings so just figure it out.

Uhm im watching a show about some child whos got like 50 parents cause of sperm
mismatches and shit. SO uhm lets try to learn something new.

include and require. Include will include another script, file or whatever...it is
just like taking the file you have, cutting it in half where the include statement
is, and puts the included file in. This means all variables, and everything set
before the include will be effective in the included file, and all variables from the
file will be included in the rest of the script. This example will include a
file...thats all

1.php:


index.php:


As you see, $file2 doesnt exist in that script but uhh it does in the other thats
included, and it will pass as 'whoa' cause $file1 is 'whoa' and $file2 = $file1 so uh
yeah you get it.

if, time for if. IF will execute commands and stuff if things match up in the
statement.
ie:


see if it is tak, it does whats in the {}'s, you can also have an else, or elseif.
elseif acts just like if, but after the initial if. Else is when everything else
fails, do this shit in there.

BTW, isset($string) checks to see if $string contains a value, if it doesnt it will
go to else.

So lets look at a couple bigger examples dealing with redirecting include if thingys!

you ever see like http://www.b0g.org/index.php?sec=pr0n or something like that? well
lets show you how. Well that is the example type thing, but first ill show you
something else



That will basically check to see if $sec exists, if it does it will include it, if it
doesnt it will echo that other crap. This isnt too safe, cause php doesnt use virtual
directories... / is not DocumentRoot, it is your hard drive root. So if someone was
to index.php?sec=/etc/passwd things might get a bit tricky, but you get the idea. Now
lets look at something a little better and more complex.

For each of these examples, you need a php script or HTML page containing the data
you want. And another thing, .php scripts can contain HTML aslong as its not in php
tags. This leads to another thing, you can be in the middle of PHP and break out of
it and throw in HTML. Here is our next example:


[^-top] [next->]