Google Filter By Usage Rights
« October 2005 | Main | December 2005 »
A new version of Thunderbird, the e-mail client from the Mozilla Foundation (home to Firefox), was released earlier this week. The first release candidate of the next major release of Thunderbird has many new features:
Torrent Finder is a Bittorrent search site which allows you to search up to 31 different torrent search engines at once. Some of the sites it searches include the Pirate Bay, Mininova and IsoHunt. It shows the results from each site seperately, within tabs or frames on its site.
There's a new Firefox extension that allows you to easily save files which are embedded in a webpage, such as windows media files.
Download Embedded does exactly what it sounds like it does. It adds a right-click context menu entry to download all embedded files on a webpage. Its great for grabbing embedded flash animations, movies, music, etc., and a lot easier than digging through the page source or through Firefox's Page Info.
Download Embedded makes the process simple. My previous technique was to find the URL for the embedded media in the Adblock extension's 'Blockable Items' list.
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?
All of the information we need is stored in the $_SERVER array, which is accessible from anywhere in your PHP script (and as such is called a superglobal variable), it works like a normal array and the keys we wish to retrieve the values of are 'HTTP_HOST', 'SCRIPT_NAME' and 'QUERY_STRING' for the three different parts of the url. Alternatively, if we don't need to have the path to the page and the query string seperate, we can use 'REQUEST_URI'.
The following code should let you find it:
<?php // find out the domain: $domain = $_SERVER['HTTP_HOST']; // find out the path to the current file: $path = $_SERVER['SCRIPT_NAME']; // find out the QueryString: $queryString = $_SERVER['QUERY_STRING']; // put it all together: $url = "http://" . $domain . $path . "?" . $queryString; echo "The current URL is: " . $url . "<br />"; // An alternative way is to use REQUEST_URI instead of both // SCRIPT_NAME and QUERY_STRING, if you don't need them seperate: $url2 = "http://" . $domain . $_SERVER['REQUEST_URI']; echo "The alternative way: " . $url2; ?>
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 user through the server variables array, which is contains information about the user and the server environment and is accessible from anywhere in your PHP script. To do this, you use the code $_SERVER['REMOTE_ADDR']. It works like a normal array, where REMOTE_ADDR is the key, and the IP address of the visitor is the value associated with that key.
Display The IP Address
So, if you want to display the IP Address to the user then the following page will suffice:
<?php echo "Hello! Your IP Address is: " . $_SERVER['REMOTE_ADDR']; ?>
Exploring the $_SERVER array
You might be wondering what other information you can get from $_SERVER, well you can find out with the following script which displays all the variables in it along with their values if set, in a HTML table:
<table border="1">
<tr><th>Variable</th><th>Value</th></tr>
<?
foreach( $_SERVER as $key => $value )
{
echo "<tr><td>" . $key . "</td>";
echo "<td>" . $value . "</td></tr>";
}
?>
</table>Finally, the following code works harder to find the true IP of the user by checking for proxies:
function userIP()
{
//This returns the True IP of the client calling the requested page
// Checks to see if HTTP_X_FORWARDED_FOR
// has a value then the client is operating via a proxy
$userIP = $_SERVER['HTTP_X_FORWARDED_FOR'];
if($userIP == "")
{
$userIP = $_SERVER['REMOTE_ADDR'];
}
// return the IP we've figured out:
return $userIP;
}