Web Concepts in PHP | Explanation with example

Tutorialscan in This session guide you about the Web Concepts in PHP.

How PHP can provide the dynamic content according to browser type, user Input or Randomly generated numbers.
Therefore also guide about how the client browser can be redirected.

Recognize Platform And Browser

In File phpinfo.php we can see the PHP Create some useful environment variables that were used to set up the PHP environment.

HTTP_USER_AGENT environment variables set by PHP which identify the operating system and user’s browser.

PHP Function getenv() to access the value environment variables and all information gathered in the HTTP_USER_AGENT.

So environment variable we can be used to create dynamic content for the browser.

First of all, let’s see with the example how we can identify a client browser and operating system

Finally, It will produce the following result −</3>

This result is producing on my machine. This result may be different according to your computer (machine) depending on what you are using the browser, Window, version.

HTML Forms

Important thing is that to notice PHP is that any form element in an HTML page will automatically be available to your PHP scripts.

See the blew example by putting the source code in the form.php script.

Finally, Output will have come:-

Conclusion
Variable $_PHP_SELF is used for PHP Script when you click submit button then same PHP Script will be called and it will us the result

“POST” Method is used to post user data to the server script, Here we can USE “GET” Method, because of PHP GET and POST Method are used to posting data to the server script.

Randomly Images Display

Here we need to generate random number so we can use PHP rand() function, this function generates numbers within a given range.

the PHP function srand() will be used that specifies the seed number as its argument

See THE Following given example to display images each time-

Finally, the result will come −

Browser Redirection

In PHP web concepts in Browser Redirection PHP header() function supplies raw HTTP headers to the browser and it can be used to redirect to another location.

The header as the argument to the header function, the target is specified by the Location, After calling the function the exit() function can be used.

One thing noticed here the redirection script should be at the top of the page to prevent any other page from loading

Example: testrun.php (putting the source code in this testrun.php script)

Finally output-

The following above example you can use to redirect browser request to another web page.