Do You Know These PHP Basics Before Starting Programming – Coding Cyber

Do You Know These PHP Basics Before Starting Programming

Before you start with PHP, you should know these few things about PHP.

PHP is a Server Side Programming Language, that means PHP code will only be executed on the server and only HTML will be rendered to the browser.

To use PHP Programming Language, you should install PHP based server like LAMP stack. LAMP stands for

L: Linux (In Windows it’s WAMP, In Mac it’s MAMP)
A: Apache
M: MySQL
P: PHP

If you are using Windows, you can setup PHP server with WAMP or XAMPP. In mac, you can setup PHP server with MAMP or XAMPP.

Other Articles in PHP Basics Section

Quickly Navigate to Other Sections in PHP Tutorials

PHP Basics
PHP Data Types
PHP Advanced Data Types
PHP Logical Statements
PHP Operators
PHP Loops
User Defined Functions in PHP
Useful PHP Functions

For Processing PHP code, you should always use PHP file. That means PHP code should be added to the files with file extension as .php.

Creating PHP File & Adding PHP Code

In this step, we will see creating a PHP File & adding your first PHP code.

Create a new file and save it with .php extension inside www directory or htdocs directory respectively if you are using WAMP or XAMPP.

You can save this file with name as basic.php

In this file add opening PHP tag <?php, after adding opening PHP tag you can start writing the PHP code.

We can add PHP code till closing PHP tag ?>

White spaces don’t matter inside PHP code, that means you can have as many white spaces.

Every statement should end with a semicolon if you are writing multiple statements this is mandatory.

You can use this PHP code inside HTML also if that file is of PHP extension.

Here is the code that you can reuse

<?php
//opening php block

// white spaces don't matter
//Every statement should end with a semicolon

//use the php code in HTML file 

//closing php block
?>

Using PHPInfo

In this step, we will see how to use phpinfo Function and adding first PHP statement. In the previous step, we have created a PHP file and added opening & closing PHP tag.

Here we will add single line statement, just add this below line

phpinfo();

After adding the above code, load the file in the browser. You should see all the configuration information of your PHP server.

Remember: Don’t use this PHP function on your server, it’s a security risk. Anyone who is having access to this file will easily know the configuration of your server.

If you add this code in HTML file, you won’t be able to see the PHP configuration.

<!DOCTYPE html>
<html>
	<head>
		<title>Basics of PHP</title>
	</head>
	<body>
		PHP won't be processed in HTML file, should use PHP file for adding PHP code.
		<?php phpinfo(); ?>
	</body>
</html>

You can learn more about this configuration in the video.

Vivek Vengala
 

Vivek Vengala is a Online Entrepreneur, Web Developer from Hyderabad India.

Click Here to Leave a Comment Below 0 comments

Leave a Reply: