Frontpage web hosting - 70Part IPHP: The Basicsaccomplish this, and the different

70Part IPHP: The Basicsaccomplish this, and the different techniques are a lot of what the rest of this book is about. For example, you can pass information from page to page using GETand POSTvariables(Chapter 7), store information persistently in a database (all of Part II of this book), associateit with a user s session using PHP s session mechanism (Chapter 24), or store it on a user shard disk via a cookie (Chapter 24). Functions and variable scopeExcept inside the body of a function, variable scope in PHP is quite simple: Within any givenexecution of a PHP file, just assign a variable, and its value will be there for you later. Wehaven t yet covered how to define your own functions, but it s worth a look-ahead note: Variables assigned within a function are localto that function, and unless you make a specialdeclaration in a function, that function won t have access to the global variables defined outside the function, even when they are defined in the same file. (We will discuss the scopeof variables in functions in depth when we cover function definitions in Chapter 6.) You can switch modes if you wantOne scoping question that we had the first time we saw PHP code was: Does variable scopepersist across tags? For example, we have a single file that looks like: ); ?> Should we expect our assignment to $usernameto survive through the second of the twoPHP-tagged areas? The answer is yes variables persist throughout a thread of PHP execu- tion (in other words, through the whole process of producing a Web page in response to auser s request). This is a single manifestation of a general PHP rule, which is that the onlyeffect of the tags is to let the PHP engine know whether you want your code to be interpretedas PHP or passed through untouched as HTML. You should feel free to use the tags to switchback and forth between modes whenever it is convenient. ConstantsIn addition to variables, which may be reassigned, PHP offers constants, which have a singlevalue throughout their lifetime. Constants do not have a $before their names, and by conven- tion the names of constants usually are in uppercase letters. Constants can contain onlyscalar values (numbers and string). Constants have global scope, so they are accessibleeverywhere in your scripts after they have been defined even inside functions. For example, the built-in PHP constant E_ALLrepresents a number that indicates to theerror_reporting()function that all errors and warnings should be reported. A call toerror_reporting()might look like this: error_reporting(E_ALL);
We highly recommend you visit web and email hosting services if you need stable and cheap web hosting platform for your web applications.

Leave a Reply