here is a very simple
<?php echo "Hello world!"; ?>the echo is what it will show in your browser!
code 2:
now we will do something a little trickier but not much!
<?php if( $lang == 1 ) { echo "Hello World!"; } ?>This code tells php that if the variables (The $ sign means it will be a variable) are $lang == 1 to show Hello World! so in the browser you would type index.php?lang=1
code 3:
now this is a very useful in php if you dont always want to keep puting new pages on the web you can make a whole bunch of pages in just one file!
Ok now we start writing the script, I will wright the full thing out then do it in parts and tell you a little about them.
<?php if(!$lang){ echo "Hello World"; } if($lang == hello){ echo "hello"; } ?>There is a very simple one because sometimes there are many of thoughts thing over and over.
<?php ?>first start off with your tages. Put the code that I show you below into thoughs tages.
if(!$lang){this first part of the code is telling php that if its the variable lang then that will be the main part such as just index.php because it has that exclamation mark before the set variables.
echo "Hello World";This is just telling what you want it to say when you are on that page, you can use eather " " or ' ' but when Im writing something like just text I use " " because if you are using ' ' and you need to write something like Can't (if you spell it right) then where the ' in cant is that would close that part and the wrest wouldn't be shown. If your writing code such as html in the php tags I use ' ' because in a lot of html there will be " so if you use ' ' then " wont close the script you are wrighting. Remember to always close with ;
}after your are done the echo then hit ender which will bright you down a level and put } this shows that that part is done!
now for the ? mark part when you are in the browser!
if($lang == hello){ok the if means if the statement in the brackets is true cary out the next part of the script. As you may notice there is no exclamation mark that is because we do not want this to be on the same page as the main one. Also you need to put the first part, lang (or what ever you set it as) the same every where on that page because if you don't then the text will show up on all the same pages. after the dobble equil sign the hello part is the part that will be after the equil sign in the browser so if you are having a whole bunch of pages in one you need to change it otherwise there will be a problem.
echo "hello"; }the rest of this is the same as the first part.
ok now save it as index.php and put it on the web, then when you go to index.php it will say hello world, and when you put index.php?lang=hello it will say hello
code 4:
ok another good script and very simple is if you want to have a header and footer in different pages like phpbb does you can do this!
<?php include ("header.tpl"); ?> <div align="center"> <?php echo "main text"; ?> <?php include ("footer.tpl"); ?>ok first things first you DONT need them to be .tpl they can be any type of web file or even a website.
code 5:
If you want to show someones IP adress you can use this script!
<?php echo 'Your IP adress is: '; echo $_SERVER["REMOTE_ADDR"]; ?>
Part 2 - A little harder
Code 1
Here is another useful script so you do not have to make more pages. This script willl start off like the other one you would put ?lang=hello but with this script it will make it so you can make ?lang=hello&id=1
<?php if(!$lang){ echo 'this is with nothing typed in'; } if($lang == hello && $id == 1) { echo 'This is hello and id 1'; } elseif($lang == hello){ echo 'This is just going to be hello'; } ?>You notice how I put the:
elseif($lang == hello){ echo 'This is just going to be hello'; }after the:
if($lang == hello && $id == 1) { echo 'This is hello and id 1'; }This is because if I put it first, the second one would read off of the $lang variable then it would say something like "This is just going to be helloThis is hello and id 1" but if we put it second it does not think of the $lang as the variable to show that it reads off of the id=1 this is a help full script if you want th keep everything in the same category such, as say you were making a tutorial thing and you have php and html you could just have it ?lang=php&id=1 and ?lang=html&id=1 instead of getting them all mixed together.
dEcade