Announcement

Collapse
No announcement yet.

What are Register Global Variables?

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • What are Register Global Variables?

    It is a frequent necessity to transfer variable values between pages. You may have an HTML <form> which asks for user input to named fields. These fields (as well as hidden variables) will be transferred to a PHP page for processing. This may be the same page that defines the form, or a different one. A method of either 'post' or 'get' must be given in the form tag.

    Another way to transfer variable data to another page is make an HTML link (such as with <a href="target_page.php?var_name_1=data&var_name_2=d ata">click this link</a>).This of course can be entered on the browser's address line, too. This information (the stuff after the ?, or "var_name_1=data&var_name_2=data") is known as a URL Query String ("UQS") and can be treated like a "GET" form submission.

    So, how do these variables and their data get into my PHP code?

    Once upon a time, most PHP programmers simply grabbed variables and values by using them in their code. Let's say you had two fields in a form, named "user_name" and "user_email". You could simply use $user_name and $user_email in your code (the receiving, or target, page), and they would have the values filled in by the user in the form. Life was simple, wasn't it? $user_name and $user_email were examples of a special kind of PHP variable, called a register global variable. You simply used it, and it was magically there to pull in data transferred from a form or a link on another page.


    Thanks
Working...
X