|
|
|
|
![]() ![]() |
![]() ![]() ![]() ![]() ![]() ![]() Group: Members
Posts: 91 Joined: 20-December 04 Member No.: 2,823 |
Post
#1
Feb 24 2005, 09:20 PM
In creating a php file, you can combine HTML and PHP in one file, but you MUST save it as a .php file if it contains any PHP information. Remember, these tutorials are just for your learning and you should not just copy and paste these into notepad and call it good. You also may realize PHP is alot like the C++ programming language CODE <html> <head> <title>PHP Test</title> </head> <body> <?php echo '<p>Hello World</p>'; ?> </body> </html> What the <?php echo '<p>Hello World</p>'; ?> command does is it exports The information between the 's as raw text. So it would display as CODE <p>Hello World</p> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Now we will use the echo() command to display what browser the viewer is using, so we can put a big fat banner telling them to switch to Mozilla Firefox CODE <?php echo $_SERVER['HTTP_USER_AGENT']; ?> An output of this code would be Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1) if the user is using Mozilla. What this code does is it gets the broswer information and echos it (displays it) for the viewer. Now we could use this to our advantage and tell them which browser they are using or if they are not using Mozilla Firefox with this code... CODE <?php if (strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE') !== FALSE) { ?> <p>You are using Internet Explorer</p> <?php } else { ?> <p>You are not using Internet Explorer</p> <?php } ?> The output would be <p>You are using Internet Explorer</p> or <p>You are not using Internet Explorer</p> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ For this one, you will need two PHP files, one for the action, and one for the HTML. CODE <form action="action.php" method="post"> <p>Your name: <input type="text" name="name" /></p> <p>Your age: <input type="text" name="age" /></p> <p><input type="submit" /></p> </form> That's just simple HTML you would put on a site for a form. You would fill this out and it would display a sentence of "Hi ______, you are __ years old." And this is what we're going to do now. Create a action.php file and put this in it.... CODE Hi <?php echo $_POST['name']; ?>, You are <?php echo $_POST['age']; ?> years old. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ And that concludes the noob tutorial for PHP. I hope this has helped you create great websites as it has helped me get hosting credits >_> ++++++++++++++++ Tutorials Copyright 2005 shadow skazi ++++++++++++++++ |
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Group: Members
Posts: 661 Joined: 10-January 05 Member No.: 3,189 |
|
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Group: Members
Posts: 385 Joined: 10-August 04 From: United States Member No.: 761 |
|
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Group: Members
Posts: 535 Joined: 14-February 05 From: Oslo, Norway Member No.: 3,759 |
|
![]() Group: Members
Posts: 15 Joined: 25-February 05 From: Somewhere? LOL. Member No.: 3,988 |
Post
#5
Feb 25 2005, 10:54 PM
Hey, if any of you guys need a mail newsletter script, let me know. I got one that works beautifully and is barely a hassle. Only 3 files needed! |
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Group: Members
Posts: 421 Joined: 17-January 05 From: Somewhere over the rainbow Member No.: 3,317 |
Post
#6
Feb 25 2005, 11:03 PM
wow... this tuturial can come in handy when I feel like scripting in PHP! thanks!
|
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Group: Members
Posts: 209 Joined: 9-October 04 Member No.: 1,574 |
Post
#7
Feb 25 2005, 11:47 PM
thanks a lot for that tutorial. i am hoping to soon learn php so this is a nice little intro
|
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Group: Members
Posts: 629 Joined: 26-February 05 Member No.: 3,995 |
Post
#8
Feb 26 2005, 04:01 AM
You don't need to have two pages for a form. You could just have some HTML then PHP then finish the HTML (pretend the file is called "file.php"): CODE <HTML> <HEAD> <TITLE>Title</TITLE> <BODY> <FORM METHOD="POST" ACTION="file.php"> Name: <INPUT TYPE="text" NAME="name"> <INPUT TYPE="submit"> </FORM> <?php echo "Hello, " . $_POST['name']; ?> </BODY> </HTML> |
![]() ![]() ![]() ![]() Group: Members
Posts: 55 Joined: 26-February 05 Member No.: 3,996 |
Post
#9
Feb 26 2005, 05:17 AM
thanks...... Although it seems like every PHP tutorial online is all the same........Hello World, they show u how to get your browser and stuff blah blah......... I wish someone would write a tutorial Step by step telling how to do a certain task, and why they did it. I see too many tutorials that just tell u what to do not why you do it. Seems kinda pointless if you aren't sure why your doing something.
|
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Group: Members
Posts: 272 Joined: 10-September 04 From: (>0_0)>oooO Hadoken Member No.: 1,068 |
|
![]() ![]() |
Similar Topics
| Topic Title | Replies | Topic Starter | Views | Last Action | |||
|---|---|---|---|---|---|---|---|
![]() |
2 | Nico Robin | 298 | 25th June 2008 - 03:17 PM Last post by: Nico Robin |
|||
![]() |
2 | Saint_Michael | 1,470 | 10th August 2007 - 05:27 PM Last post by: kevlar557 |
|||
![]() |
5 | karlo | 612 | 2nd March 2005 - 02:34 PM Last post by: karlo |
|||
![]() |
2 | Wideawake | 690 | 29th June 2006 - 05:24 AM Last post by: Wideawake |
|||
![]() |
3 | AllfatherBlack | 380 | 22nd January 2006 - 06:41 AM Last post by: melicaster |
|||
![]() |
3 | Wideawake | 886 | 30th September 2007 - 12:50 AM Last post by: Trap FeedBacker |
|||
![]() |
2 | Earths Daughter | 736 | 14th March 2006 - 12:33 AM Last post by: Earths Daughter |
|||
![]() |
1 | xor_xor_xor | 916 | 5th June 2006 - 08:36 AM Last post by: jibnet |
|||
![]() |
12 | mama_soap | 2,899 | 14th July 2008 - 06:01 PM Last post by: serverph |
|||
![]() |
1 | .hack//GU | 387 | 20th May 2006 - 06:49 AM Last post by: Justin S. |
|||
|
Lo-Fi Version | Time is now: 3rd December 2008 - 08:03 PM |