PHP Tutorial: Reading Data in Web Pages
How to read data from the Web pages?

PHP Tutorial: Reading Data in Web Pages

Hello my all PHP Programmers, again, your most welcome in this domain (www.bittutech.com). From here, you can learn various programming languages, as well as Android, Windows, Linux tricks/tips. Today, we are going to learn one more interesting topic, that is – How to read data in Web pages through your PHP script? This article is going to indicate that How PHP Script works for reading the data from web pages or from the client’s computer.

All of the methods and properties that is useful for reading the data from web pages will be described here. You must read carefully all the methods and properties that is useful.

Do you want to read the web page data or form data through your PHP Script? If, Yes!!. This article only for you. this article teach you, which functions can be used to read the data in PHP? is it pre-defined functions or user-manually functions. All things will clear, when you read this article till the end.

Two main points are recommended to remember is that PHP is a server-side language, which means, you have to submit your HTML form element data and sent to the intended Webpage.

Second point is that, if your PHP script is on remote machine, you have to send your html form data with location or hostname of remote machine.

Ok, I hope you must have cleared some basic points in PHP. Then, we are going to know about how html form element data sent to the intended destination(PHP Script).

Client-Server Model (Request and response model)

According to the figure, the Get method and Post method both sends your form data, but both of the own limitations and mechanisms to send data on the Server. both Get and Post method is own consequences, GET method sends your data through the URL(Uniform Resource Locator) and the POST method sends your data through the HTTP headers.

Setting up Web pages to communicate with PHP

Encapsulation mechanisms are used there to send the data to the Server or destination. All of the data that you want to send must be in the form format and encapsulated within the particular form. What is form?

The Form is an HTML element that is used to create various forms like – Entry form, Signup form, login form, e.t.c., and sent back to the Server to validate User information. The forms are only to provide extra information to the user on the particular Server.

Ok, let’s see an example based upon How to send the form data to the intended webpage or Servers.

<!DOCTYPE html>
<html>
<head>
<title>
ReadingForm
</title>
</head>
<body bgcolor="Skyblue">
<h1>Submit the Entry Form</h1>
<form name="entry_form" method="post"
 enctpye="multipart/form-data" action="read_user_form.php">
 Full Name : <input type="text" name="user_name"
 placeholder="Full Name"></br></br>
Email-Address : <input type="email" name="email_address"
 placeholder="Enter the E-mail address"></br></br>
Create Password : <input type="password" name="user_password"
 placeholder="Enter password"></br></br>
Re-enter Password : <input type="password"
 name="user_re_password" placeholder="Re-enter password"></br></br>
Qualifications:</br></br>
10th<input type="checkbox" name="high_school" value="10th">
12th<input type="checkbox" name="intermediate" value="12th">
Graduate<input type="checkbox" name="graduated"
 value="Graduate"></br></br>
Sex:</br></br>
Male<input type="radio" name="radio1" value="male">
Female<input type="radio" name="radio2" value="female"></br></br>
Choosing Subjects: <select name="subjects[]" multiple>
 <option>Physics</option>
 <option>Chemistry</option>
  <option>Maths</option>
<option>Biology</option>
 </select>
</br></br>
 Upload Aadhar Card : <input type="file" name="adhaar"></br></br>
<input type="submit" name="submit" value="Submit">
</form>
 </body>
 </html>

Result Output

Please fill the form and submit the data to check how to send the data to the Server.

So now, it’s time to read the file from the PHP script.

We have to create an php file to read the user’s send data.

file name- ReadData.php

<!DOCTYPE html>
<html>
<head>
<title>
Read User Data
</title>
</head>
<body>
    <h1>Read User Data.....</h1>
    <h3>Check Your Filling Data without validation</h3>
    <?php
    $uname=$_REQUEST["user_name"];
    $email=$_REQUEST["email_address"];
    $password=$_REQUEST["user_password"];
    echo "<b>User Name -:</b>".$uname."</br></br>";
    echo "<b>User Email Address -:</b>".$email."</br></br>";
    echo "<b>Password -:</b>".$password."</br></br>";
    echo "<b>QUALIFICATION</b></br></br>".$_REQUEST["high_school"]."</br></br>".$_REQUEST["intermediate"]."</br></br>".$_REQUEST["graduated"]."</br>";
    if(isset($_REQUEST["radio1"]))
    {
    echo "<b>Gender:--</b> ".$_REQUEST["radio1"]."</br></br>";
    }
    else
    {
        echo "<b>Gender:--</b> ".$_REQUEST["radio2"]."</br></br>";
    }
        echo "<b>Your Subjects--</b></br></br>";
       foreach($_REQUEST["subjects"] as $subject)
       {
         echo $subject."</br>";
       }
       echo "</br>End of the Script";
    ?>
    </body>
</html>

Last Words: So my all dear visitors, this is it for now, we will meet very soon with a next PHP article. Join us on social network to get the latest updates, and stay tuned with us as always.


Share post

Prajjwal Singh

Tech Blogger || Web developer || Computer Networking Enthusiast || Microsoft SQL Database Management Expert || Software Debugger || Learned DOS OS Structure

Leave a Reply