Getting Started with PHP

  • PHP is a Open Source Server Side Scripting Language, and a powerful tool for making dynamic and interactive Web pages.
  • PHP is the acronym for “Hypertext Preprocessor”
  • PHP scripts are executed on the web server like Apache, Tomcat etc.,
  • PHP file extension is .php
  • Latest stable version of PHP is PHP 7.3.9
  • We can use web server solution stacks like XAMPP, WampServer etc for development machine to run PHP programs

Before starting working on PHP, let’s install XAMPP in our development machine.

What is XAMPP?

  • XAMPP is a free and open-source cross-platform web server solution stack package developed by Apache Friends, consisting mainly of the Apache HTTP Server, MariaDB database, and interpreters for scripts written in the PHP and Perl programming languages.
  • XAMPP is not meant for production use but only for development environments.
  • XAMPP is configured to be open as possible to allow the developer anything he/she wants.

XAMPP Installation

Download XAMPP from Apache XAMPP and the run the set up file.

Once XAMPP is installed in local development machine. Go to the xampp folder path and navigate to htdocs, i.e., C:\xampp\htdocs\, here create the project folder and create php files inside this folder. Here I have created two PHP files index.php and welcome.php

Make sure Apache Server is started from the XAMP Control panel like shown in the below screenshot. Once Apache Server is started then you can run the php files from the localhost where the Apache Server port is configured i.e., http://localhost:80/myphpproject/index.php

Now create the index.php file and write the below shown code. Here I have used simple bootstrap stacked form with name and designation input text fields.

<html>
<head>
  <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css">
  
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js" integrity="sha384-JjSmVgyd0p3pXB1rRibZUAYoIIy6OrQ6VrjIEaFf/nJGzIxFDsf4x0xIM+B07jRM" crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.bundle.min.js" integrity="sha384-xrRywqdh3PHs8keKZN+8zzc5TX0GRTLCcmivcbNJWm2rs5C8PRhcEn3czEjhAO9o" crossorigin="anonymous"></script>

</head>
<body>

<div class="container">
<form action="welcome.php"  method="get">
<br/>
  <div class="form-group">
    <label for="name">Name:</label>
    <input type="text" class="form-control" id="name" name="name">
  </div>
  <div class="form-group">
    <label for="designation">Designation:</label>
    <input type="text" class="form-control" id="designation" name="designation">
  </div>
  
  <button type="submit" class="btn btn-primary">Submit</button>
</form>
</div>
</body>
</html>

Now go to browser and type http://localhost/myphpproject/index.php , Here myphpproject is the project folder name and index.php is the php file name.

Now let’s create welcome.php page and write the below code.

<html>
<head>
  <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css">
  
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js" integrity="sha384-JjSmVgyd0p3pXB1rRibZUAYoIIy6OrQ6VrjIEaFf/nJGzIxFDsf4x0xIM+B07jRM" crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.bundle.min.js" integrity="sha384-xrRywqdh3PHs8keKZN+8zzc5TX0GRTLCcmivcbNJWm2rs5C8PRhcEn3czEjhAO9o" crossorigin="anonymous"></script>
</head>
<body>
 
<div class="container">
<br/>
<p>  <h1  class="text-primary">Welcome <?php echo $_GET["name"]; ?></h1> </p>
<p><h1  class="text-primary">Your Designation is: <?php echo $_GET["designation"]; ?></h1></p>

</div>
</body>
</html>

Now go to browser and type http://localhost/myphpproject/index.php , and enter Name and Designation and press Submit button. It will navigate to the welcome.php page and will display the supplied values in the index.php page.

Above example is a simple application to understand the basic getting started feature of PHP with navigation of pages. You can do any kind of enhancements to these pages like validations, adding more fields, sessions etc., features.

References

  • https://www.apachefriends.org/faq_windows.html
  • https://www.php.net/manual/en/

Learn more about PHP features in our upcoming PHP blog articles.

Happy Learning!