Results 1 to 25 of 93
Thread: Basics Of PHP
Hybrid View
-
11-12-2005, 09:43 PM #1Newbie
- Join Date
- Nov 2005
- Posts
- 24
Basics Of PHP
I figured it's time to make a small tutorial , by reading this tutorial you should have the basic know how to execute small script's on your php enabled servers. Note that i will not be explaining how to set up a web server + php.
What Does PHP Stand For?
PHP- Hypertext Preprocessor
Starting & Ending Tags
We start off by learning the 2 main tag's that you must never forget , that is the starting and ending tag's.
StartingCode:<?php
Code:?>
Now that you know about the starting & ending tag's , let's start with a basic script.
Code:<?php echo "This is my first php script!"; ?>
Variables
Now that you know some basic syntax let's start working on variables , variables are ton's of fun and one of the most important part's of PHP.
Code:<?php $myfirstscript = "This is my first php script!"; echo $myfirstscript; ?>
Comments
Comments are also another important thing not only in php but all languages , there used to disable any type of information inside them from actually executing with your script which ofcourse would likely cause error's.
Code://This is a comment /*This is a comment block*/
Now these are fun to play with , they are used to execute certain code on a condition.
Code:<?php $mybrowser = "Fire Fox"; if ($mybrowser == "Fire Fox") { echo " You are using firefox!"; } else { echo " You are not using firefox"; } ?>
Looping
Looping is used for many many thing's , there are more then just one loop statement, ill explain how to do the "While Loop".
Code:<?php $z = 1; while ($z <= 5) { echo $z; $z++ }
Code:while ($z <= 5)
Code:echo $z
Code:$z++
Forms
Now im assuming you have some basic understanding of html, although i will give an example of the html form but i will not be explaining it.
Code:<form action="form.php" method="post"> Name: <input type="text" name="name"> <input type="submit" value="Submit">
Code:<?php $name = $_POST["name"]; echo "Hello ". $name; ?>
Now this is the end of this small basic tutorial , you should now have the knowledge to execute simple script's on your server's.
-
05-29-2006, 02:56 AM #2Newbie
- Join Date
- May 2006
- Posts
- 11
I would suggest editing $mybrowser = "Fire Fox"; to something less browser related. There are actually people out there who might think this code determines what browser is being used!
-
05-29-2006, 03:48 AM #3Web Hosting Master
- Join Date
- May 2002
- Location
- NE USA (Almost Canada)
- Posts
- 993
Just An Extra Note:
If you would like to get the PHP information from your site:
With a plain text editor paste this in:
Code:<?php phpinfo() ?>
Figured that'd be good for folks who are just starting on the basics and if it's covered anywhere here already I'm not really sure.
KGIIIWhat Hosting Should Be
A Blog as CMS, eBay, PR, and Ads?
My personal email: KGIII <at> KGIII <dot> INFO
Microsoft MVP 2003/2006 Categories: Shell/User and Internet Explorer (G³ Solutions)
-
09-16-2006, 03:10 PM #4Newbie
- Join Date
- Sep 2006
- Posts
- 12
nice one, ive already learnt this but i havent used php in a while so its nice to refresh my memory abit, great post for people who want to get into php
-
09-17-2006, 07:38 AM #5Web Hosting Master
- Join Date
- Apr 2005
- Posts
- 1,767
Actually for a phpinfo() I would do this, since it volunteers a lot of information about your server, that you may not neccessarily want being public.
PHP Code:<?PHP
$ip = getenv("REMOTE_ADDR");
$allowed_ip = "24.211.80.102"; // change to your ip
if ($ip == $allowed_ip) {
phpinfo();
} else {
header("Location: /");
}
?>
-
10-24-2006, 10:18 PM #6Web Hosting Master
- Join Date
- Feb 2006
- Location
- Buffalo, NY
- Posts
- 1,501
Or just create the file when needed / don't name it phpinfo.php
(Or just add a constant to the index.php to show phpinfo if defined, etc)█ Cody R.
█ Hawk Host Inc. Proudly Serving websites since 2004.
█ Official Let's Encrypt Sponsor
-
10-25-2006, 01:01 AM #7New Member
- Join Date
- Oct 2006
- Posts
- 4
Is there a function in PHP that's similar to CFHTTP? I need to read the contents of one of our sites.
-
10-25-2006, 01:03 AM #8New Member
- Join Date
- Oct 2006
- Posts
- 4
Is it better to use $_request instead of $_POST or $_GET? Since it does what $_POST and $_GET do anyway. Is there a drawback to using it?
-
10-25-2006, 01:45 AM #9Web Hosting Master
- Join Date
- Feb 2003
- Location
- AR
- Posts
- 2,382
If your form is ONLY using the post method, use $_POST. Likewise for $_GET. If your form should accept both methods, use $_REQUEST.
Kevin
-
11-14-2006, 04:09 AM #10Newbie
- Join Date
- Jun 2006
- Location
- California
- Posts
- 8
Good short, tutorial, good for new people wanting to learn PHP.
Next thing functions, classes and arrays!
-
12-29-2006, 02:20 PM #11Web Hosting Master
- Join Date
- Mar 2006
- Posts
- 984
Nice block from SNC. However, I'd state this line:
PHP Code:$ip = getenv("REMOTE_ADDR");
PHP Code:$ip = (isset($_SERVER['REMOTE_ADDR'])) ? $_SERVER['REMOTE_ADDR'] : getenv("REMOTE_ADDR");
-
06-08-2012, 02:21 PM #12Junior Guru Wannabe
- Join Date
- Aug 2010
- Location
- Belgium
- Posts
- 47
You can just do $_SERVER['REMOTE_ADDR'];
isset and getenv will only slow it down, $_SERVER and getenv do just the same, the only difference is that you can do getenv('remote_addr') but function call is slower than array call (#micro optimization)
This is false as well, this enctype is default one so you don't have to specify it only if you need something different. The less text in your html the smaller so faster.
-
12-31-2006, 03:54 PM #13Junior Guru Wannabe
- Join Date
- Dec 2006
- Location
- PA
- Posts
- 99
thank u so much this is nice short tutorial
-
01-07-2007, 02:19 AM #14Newbie
- Join Date
- Oct 2005
- Posts
- 9
Nicely put togethor, well done
-
01-21-2007, 03:44 PM #15Newbie
- Join Date
- Jan 2007
- Posts
- 11
Anyone seriously looking to learn PHP should bookmark the site below. If you have any questions they can usually be answered there.
http://www.php.net/
The function reference is particularly useful.
http://www.php.net/manual/en/funcref.php
-
01-21-2007, 03:46 PM #16Big fan of RajiniKanth!!!
- Join Date
- Sep 2004
- Location
- Chennai , India
- Posts
- 4,632
Originally Posted by vkess
-
10-18-2011, 08:56 AM #17Junior Guru Wannabe
- Join Date
- Oct 2011
- Posts
- 30
Brilliant post!!
really its very awesome and useful tips for me. I do not know PHP but it seems interesting so I definitely start learning in a few days.
Thank you
-
04-23-2012, 04:13 AM #18New Member
- Join Date
- Apr 2012
- Posts
- 1
Major thanks for the article. Will read on...
-
10-10-2012, 07:37 PM #19Disabled
- Join Date
- Oct 2012
- Posts
- 25
Great tutorial you have posted and some very knowledgeable replies to go with it. Even if you know PHP, it is still nice to refresh your mind once in a while to remember everything about it. Some very good points made for sure.
-
10-16-2012, 08:02 PM #20Newbie
- Join Date
- Sep 2012
- Location
- Frankfurt
- Posts
- 22
Pretty nice topic for beginners.
-
01-31-2013, 11:59 AM #21New Member
- Join Date
- Jan 2013
- Posts
- 3
Nice, great PHP tutorial for beginners. Do you intend to create more parts of this tutorial?
-
08-25-2013, 04:48 PM #22New Member
- Join Date
- Aug 2013
- Posts
- 3
I would add, that you must not end PHP Scripts with
PHP Code:?>
-
09-24-2013, 12:03 PM #23Newbie
- Join Date
- Sep 2013
- Posts
- 5
This post is also great post. I love it because I am beginner in this feild.
-
11-08-2013, 07:46 AM #24WHT Addict
- Join Date
- May 2009
- Location
- India
- Posts
- 153
Basics Of PHP
Thanks Mr. X.
Mobile App Development Company
Mobile Programming for iOs, Android, Windows Phone, Blackberry
-
10-05-2008, 07:21 PM #25Newbie
- Join Date
- Dec 2007
- Posts
- 16