LIGHTENING YOUR WORKLOAD (Cheap web hosting) WITH INCLUDES permitted in variable

LIGHTENING YOUR WORKLOAD WITH INCLUDES permitted in variable names, this is one of the cases where you could omit the curly braces. However, their presence makes the code easier to read. 5. Save footer.inc.php and reload index.php in a browser. Experiment by changing the value of $startYear and alternating between uppercase and lowercase y in the date() function to see the different output, as shown in the following image. These values and the name of the copyright owner are the only things you need to change, and you have a fully automated copyright notice. The finished code for the footer include file is in footer.inc02.php. PHP Solution 4-6: Displaying a random image Displaying a random image is very easy. All you need is a list of available images, which you store in an indexed array (see Creating arrays in Chapter 3). Since indexed arrays are numbered from 0, you can select one of the images by generating a random number between 0 and one less than the length of the array. All accomplished in a few lines of code . . . Continue using the same files. Alternatively, use index03.php from the download files and rename it index.php. Since index03.php uses menu.inc.php, title.inc.php, and footer.inc.php, make sure all three files are in your includes folder. The images are already in the images folder. 1. Create a blank PHP page in the includes folder and name it random_image.php. Insert the following code (it s also in includes/random_image01.php in the download files): This is the complete script: an array of image names minus the .jpg filename extension (there s no need to repeat shared information they re all JPEG), a random number generator, and a string that builds the correct pathname for the selected file. To generate a random number within a range, you pass the minimum and maximum numbers as arguments to the function rand(). Since there are eight images in the array, you need a number between 0 and 7. The simple way to do this would be to use rand(0, 7). Simple, but inefficient . . . Every time you change the $images array, you need to count how many elements it contains and change the maximum 105
You need excellent and relaible webhost company to host your web applications? Then pay a visit to Inexpensive Web Hosting services.

Leave a Reply