- PHP Basics
- PHP Home
- PHP Environment Setup
- PHP Getting Started
- PHP Basic Syntax
- PHP echo
- PHP print
- PHP echo Vs print
- PHP Comments
- PHP Data Types
- PHP Variables
- PHP Variable Scope
- PHP gettype()
- PHP Constants
- PHP Operators
- PHP Program Control
- PHP Decision Making
- PHP if-elseif-else
- PHP switch
- PHP Loops
- PHP for Loop
- PHP while Loop
- PHP do-while Loop
- PHP foreach Loop
- PHP break & continue
- PHP Popular Topics
- PHP Arrays
- PHP print_r()
- PHP Strings
- PHP Functions
- PHP References
- PHP Object Oriented
- PHP Object Oriented
- PHP Classes & Objects
- PHP Member Variable
- PHP Member Function
- PHP Encapsulation
- PHP Data Abstraction
- PHP Inheritance
- PHP Constructor Destructor
- PHP Polymorphism
- PHP Web Developments
- PHP Web Developments
- PHP GET & POST
- PHP Read Requested Data
- PHP File Handling (I/O)
- PHP File Handling (I/O)
- PHP fopen() | Open File
- PHP Create a File
- PHP fwrite() | Write to File
- PHP fread() | Read File
- PHP feof()
- PHP fgetc()
- PHP fgets()
- PHP fclose() | Close File
- PHP unlink() | Delete File
- PHP Append to File
- PHP copy() | Copy File
- PHP file_get_contents()
- PHP file_put_contents()
- PHP file_exists()
- PHP filesize()
- PHP rename() | Rename File
- PHP fseek()
- PHP ftell()
- PHP rewind()
- PHP disk_free_space()
- PHP disk_total_space()
- PHP mkdir() | Create Directory
- PHP rmdir() | Remove Directory
- PHP glob() | Get Files/Directories
- PHP basename() | Get filename
- PHP dirname() | Get Path
- PHP filemtime()
- PHP file()
- PHP Advanced
- PHP Cookies
- PHP Sessions
- PHP Send Emails
- PHP Serialization
- PHP Namespaces
- PHP File Upload
- PHP Date and Time
- PHP Image Processing
- PHP Regular Expression
- PHP Predefined Variables
- PHP Error Handling
- PHP Debugging
- PHP and MySQLi Tutorial
- PHP and MySQLi Home
- PHP MySQLi Setup
- PHP MySQLi Create DB
- PHP MySQLi Create Table
- PHP MySQLi Connect to DB
- PHP MySQLi Insert Record
- PHP MySQLi Fetch Record
- PHP MySQLi Update Record
- PHP MySQLi Delete Record
- PHP MySQLi SignUp Page
- PHP MySQLi LogIn Page
- PHP MySQLi Store User Data
- PHP MySQLi Close Connection
- PHP connect_errno
- PHP connect_error
- PHP query()
- PHP fetch_row()
- PHP fetch_assoc()
- PHP fetch_array()
- PHP free_result()
- PHP error
- PHP prepare()
- PHP bind_param()
- PHP execute()
- PHP fetch()
- PHP store_result()
- PHP num_rows
- PHP bind_result()
- PHP get_result()
- PHP mysqli_result Class
- PHP Error Constants
- PHP mysqli_driver()
- PHP Misc
- PHP error_reporting()
- PHP Escape Special Characters
- PHP htmlspecialchars()
- PHP new
- PHP header()
- PHP getallheaders()
- PHP empty()
- PHP isset()
- PHP unset()
- PHP exit()
- PHP exit Vs break
- PHP include()
- PHP require()
- PHP include() Vs require()
- PHP AJAX & XML
- PHP AJAX
- PHP XML
- PHP File Handling Functions
- PHP abs()
- PHP Test
- PHP Online Test
- Give Online Test
- All Test List
PHP Web Developments
PHP is a popular programming language and plays a huge role in web development.
You can dynamically develop your web pages or even whole websites using PHP.
PHP supports more variety of databases. It means you can use more databases to connect and use in your website with the help of PHP. In all those databases, MySQL is most popular database used with PHP in web developments.
Why PHP in Web Developments
If you want to develop your web pages or websites dynamically, or database driven, then you can go for PHP.
PHP helps web developer to develop dynamic and database driven websites.
Benefits of PHP in Web Developments
There are much more benefits of using PHP in web developments. Here are the list of most common uses of PHP in web developments.
You can use PHP to
- develop an E-commerce website like Amazon
- build an online community website
- build question and answer forums
- develop a social networking website like facebook
- generate PDF files
- build mailing list program
- develop an image processing and generation system
- create content management system
- create dynamic websites
- develop user-interaction pages like feedback
- and many more
How PHP can be used in Web Developments
In these days, the uses of PHP in developing websites increases day by day.
Today, almost every web developer wants to develop database-driven website just to make his/her website more attractive to users point of view.
Here is an example shows how PHP can be used in developing web pages and web sites.
First create a file named codescracker.php and place the following code inside it, and then save that file inside the directory C:\xampp\htdocs\.
<!DOCTYPE html> <html> <head> <title>About my current position</title> </head> <body> <?php echo "<h2>My Current Position</h2>"; include("dynamic.php"); ?> </body> </html>
As you can see from the above PHP code, dynamic.php is another PHP file contains some PHP code and content inside that file, you can call this file as dynamic file.
Dynamic file means when you change the content inside it, that is, dynamic.php, then the whole output produced by the file codescracker.php will also be changed .
The dynamic.php file contains the following content inside it.
<?php echo "<p>I am reading the technical topics in PHP.</p>"; echo "<p>Right now, i am learning about web developments using PHP.</p>"; echo "<p>I love reading PHP right now as it is the language that i was looking for to increase my knowledge about developing websites and webpages dynamically and sometime database-driven.</p>"; echo "<p>I am planning to design a public forum of questions and answers, where anyone can ask their required question and answered by the public.</p>"; echo "<p>And without PHP, i think it can not be possible to develop question and answer forum.</p>"; ?>
After creating dynamic.php file and putting the above content inside it, run the above file, named codescracker.php. You will see the following output.

Now if you change the content of file dynamic.php, then the whole output of codescracker.php will also be changed. Now put the following content inside dynamic.php and save it.
<?php echo "<p>Now i am feeling something better than previous after learning about web developments using PHP</P>"; echo "<p>Now i am going to learn next topics of PHP.</p>"; echo "<p>I will learn each and every topics of PHP here.</p>"; ?>
After changing the content of file dynamic.php, refresh the page or type localhost/codescracker.php again in the browser, you will see the following output which is not as of previous one.

This is just a simple example that shows how to use PHP in web developments.
You will learn a lot more topics later to develop dynamic websites or database-driven websites using PHP.
How to Identify Browser Name and Version using PHP
You can find or identify the name of your browser along with its version using PHP. Here is an example that shows how to identify browser name and browser version using PHP.
<!DOCTYPE html> <html> <head> <title>How to identify browser with version using PHP ?</title> <style> table th, td{padding:5px;border:1px solid black;} </style> </head> <body> <h2>My Browser Name and Version</h2> <?php function myBrowserName() { $userAgt = $_SERVER['HTTP_USER_AGENT']; $myBrowserNm = 'Unknown'; $myBrowserVersion= ""; if(preg_match('/MSIE/i',$userAgt) && !preg_match('/Opera/i',$userAgt)) { $myBrowserNm = 'Internet Explorer'; $ub = "MSIE"; } elseif(preg_match('/Firefox/i',$userAgt)) { $myBrowserNm = 'Mozilla Firefox'; $ub = "Firefox"; } elseif(preg_match('/Chrome/i',$userAgt)) { $myBrowserNm = 'Google Chrome'; $ub = "Chrome"; } elseif(preg_match('/Safari/i',$userAgt)) { $myBrowserNm = 'Apple Safari'; $ub = "Safari"; } elseif(preg_match('/Opera/i',$userAgt)) { $myBrowserNm = 'Opera'; $ub = "Opera"; } elseif(preg_match('/Netscape/i',$userAgt)) { $myBrowserNm = 'Netscape'; $ub = "Netscape"; } $known = array('Version', $ub, 'other'); $pattern = '#(?<browser>' . join('|', $known) . ')[/ ]+(?<version>[0-9.|a-zA-Z.]*)#'; if(!preg_match_all($pattern, $userAgt, $matches)) { } $i = count($matches['browser']); if($i != 1) { if(strripos($userAgt,"Version") < strripos($userAgt,$ub)) { $myBrowserVersion= $matches['version'][0]; } else { $myBrowserVersion= $matches['version'][1]; } } else { $myBrowserVersion= $matches['version'][0]; } if($myBrowserVersion==null || $myBrowserVersion=="") {$myBrowserVersion="?";} return array ( 'userAgent' => $userAgt, 'name' => $myBrowserNm, 'version' => $myBrowserVersion, 'pattern' => $pattern ); } $ua=myBrowserName(); echo "<table>"; echo "<tr>"; echo "<th>Browser Name</th>"; echo "<th>Browser Version</th>"; echo "</tr>"; echo "<tr>"; echo "<td>".$ua['name']."</td>"; echo "<td>".$ua['version']."</td>"; echo "</tr>"; echo "</table>"; ?> </body> </html>
Here is the sample output produced by the above browser identification example code using PHP.

You are seeing the above output, as i am using the 5.1.7th version of Safari browser.
How to Identify Platform/OS using PHP
You can also use PHP, to find or identify what platform or operating system you are using right now. Here is an example shows how to identify operating system or platform using PHP code.
<!DOCTYPE html> <html> <head> <title>How to identify Platform/OS using PHP ?</title> </head> <body> <h2>My Platform/OS Name</h2> <?php function myPlatformName() { $userAgt = $_SERVER['HTTP_USER_AGENT']; $platformNm = 'Unknown'; if(preg_match('/linux/i', $userAgt)) { $platformNm = 'linux'; } elseif(preg_match('/macintosh|mac os x/i', $userAgt)) { $platformNm = 'mac'; } elseif(preg_match('/windows|win32/i', $userAgt)) { $platformNm = 'windows'; } return array ( 'platform' => $platformNm ); } $ua=myPlatformName(); echo "My Platform/OS Name = ".ucfirst($ua['platform']); ?> </body> </html>
The above example code on identifying platform or operating system using PHP will produce the following output:

As the above program run on windows operating system, therefore the output produced is Windows.
Browser Redirection Code in PHP
You can create browser redirection code using PHP. Browser redirection comes in many form. Browser redirection means your will be redirected to another web page.
Here is a simple example of browser redirection using PHP. In this example, instead of redirecting to another web page in the same browser window, you will be redirected to another web page but in another browser window.
<?php // below code will check, if user submitted // the data or not if(isset($_POST["redirectURL"])) { // below code will get the location url $location = $_POST["redirectURL"]; // below code will redirect user to // the choosen url present in $location variable header("Location: $location"); // below code will skip executing the below code // after it exit(); } ?> <html> <head> <title>Browser Redirection Code in PHP</title> </head> <body> <p>What you like to learn ?</p> <form method="POST" target="_blank"> <select name="redirectURL"> <option value="">Choose to Learn</option> <option value="https://codescracker.com/html"> HTML Tutorial </option> <option value="https://codescracker.com/java"> Java Tutorial </option> <option value="https://codescracker.com/c"> C Tutorial </option> <option value="https://codescracker.com/cpp"> C++ Tutorial </option> <option value="https://codescracker.com/js"> JavaScript Tutorial </option> <option value="https://codescracker.com/sql"> SQL Tutorial </option> </select> <input type="submit" /> </form> </body> </html>
Here is the sample output produced by the above browser redirection example code in PHP.

Now to check how you will be redirected using browser redirection in PHP, just select any tutorial from the drop-down menu say C++ Tutorial and click on the Submit button, then you will be redirected to that page in another window as shown in the figure given below, this is the page you will see after selecting C++ and clicking on the Submit button.

« Previous Tutorial Next Tutorial »
Follow/Like Us on Facebook
Subscribe Us on YouTube