Main

November 02, 2005

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.com
2. The path to the page: /example/page.php
3. The query string: name=Bob

So how do you find it all out with your own PHP scripts?

Continue reading "How to Find the Current URL with PHP" »

November 01, 2005

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.

Continue reading "Find a visitor's IP Address with PHP" »

October 24, 2005

How to use PHP in pages with a .html extension (or any other)

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 to check for php code and execute it in files with extensions .html, .moo or .htm.

October 19, 2005

Write text on a dynamically generated image using PHP

This tutorial will tell you how to write text to a blank dynamically generated PNG image in PHP. This is fairly simple, so it will just be the first step in a series of tutorials dealing with images in PHP. The image functions require the GD library to be installed.

Continue reading "Write text on a dynamically generated image using PHP" »

Write Text on to an existing PNG image using PHP

This article will tell you how to write text on an existing PNG image using PHP using PHP's image manipulation functions. The image functions require the GD library to be installed. This article is fairly basic, however some more detail on the basic functions used is included in the article, "write text on a dynamically generated image in PHP"

Continue reading "Write Text on to an existing PNG image using PHP" »

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 the function how to format the date. You can see what formatting options are available by seeing the PHP Manual entry for date(). If you just pass it a string to format the date then it uses the current time, however if you pass a timestamp (a standard way of representing time: the number of seconds since a set time in the 1970s), then it will output that date with the given format.

What we're going to code is a function to which you can pass two integers, representing the year and the month, and have it display the calendar for that month. We'll call that function showMonth() and the parameters $month and $year.

Continue reading "Generate a Month Calendar In PHP" »

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 passed, with values "1" and "red" respectively. The question mark indicates the start of the query string and the ampersand, &, symbol seperates variable=value assignments.

The page is then able to read these variables and react according to them, for example to display them to the user.

Continue reading "How to use the query string in PHP" »

Adlinks

Creative Commons License
This weblog is licensed under a Creative Commons License.
Powered by
Movable Type 3.2