Archive for the 'Basics' Category



To be able to use php code on a page with an extension other than .php, you need a server which supports .htaccess files.
To add an extension to be parsed for php, create or edit a file called .htaccess (with the dot first) containing the following line:
AddType application/x-httpd-php .html .moo .htm
This tells the server […]

The Difference Between require() and include()

The key difference between require() and include() is that if you require() a file that can't be loaded (eg if it isn't there) then it generates a fatal error which will halt the execution of the page completely, and no more output will be generated. On the other hand, if you include() a file that [...]

Finding Items in an Array with PHP

The problem: we have an array of items in PHP and we want to find out if a specific item is in the array. In code we can define the array as:

IE we have an array called $fruitBasket which contains 5 strings, each of which is the name of a fruit. We want to find [...]

Generating Random Numbers in PHP

To create random numbers in PHP, you can use the rand() function call, which takes either zero or, optionally, two parameters determining the minimum and maximum random numbers (inclusive) that you'd like. If you don't specify a maximum then it will default to a value, RAND_MAX, set in the PHP configuration. The function returns an [...]

How to Find the Current URL with PHP

The full URL to a page comes in three parts: The domain name, the path to the file then the filename, and the query string. For example, take the URL http://www.example.com/example/page.php?name=Bob. The three parts of this are:
1. The domain name: www.example.com2. The path to the page: /example/page.php3. The query string: name=Bob
So how do you find [...]

Find a visitor’s IP Address with PHP

Do you want to know the IP address of a visitor? This can be useful for many reasons, such as tracking site usage or blocking access to specific people. Here's how you can find it using PHP.
In a PHP page, within the PHP tags, <?php ... ?>, you can retrieve the IP address of a [...]

Generate a Month Calendar In PHP

This article shows you how to display a calendar for a given month, mainly using PHP's date() function.
The date() function
The date() function displays the date in your desired format, at a given time. It works by accepting one or two parameters, the first is a string with the format, the letters in the string tell [...]

How to use the query string in PHP

This article tells you how to pass variables to a PHP page using the query string, and how to access them from that page.
Introduction
Have you ever seen a URL which looked like "www.example.com/page.php?mode=1&style=red"? Well, this page is being passed variables and their values through the query string, here the variables "mode" and "style" are being [...]




About

You are currently browsing the DiscoMoose weblog archives for the 'Basics' category.

Longer entries are truncated. Click the headline of an entry to read it in its entirety.

Categories

Categories