Heya, dunce1000.
In a nutshell, here's how the web works:
When you type an address into your web browser's address bar, your computer sends out a request. Long story short, the server located at that 'address' receives the request an processes it.
So for example, when you type:
-
http://www.google.com/search?q=hello,+world
-
You are sending a request for '/search?q=hello,+world' to the 'www' server located at 'google.com'.
Incidentally, as part of that request, your browser also sends your IP address with the request so that (in this case) Google knows where to send the response.
Now then. In order to perform the search, Google has to run a program to access its massive database. Because it is executing this code on the server, and not in your browser at home, this is known as 'server-side' code.
Once the search program finishes executing, Google takes the results and turns it into an HTML page and sends it back to your computer.
Your computer evaluates the HTML and displays the pretty webpage with the goofy Google logo... and your search results.
While your browser is parsing the HTML, it also evaluates JavaScript and other 'client-side' scripts (that is, anything that your browser runs instead of the server).
In order to capture the IP address of requests to your website, you need to be able to write to some kind of file *on the server* so that you can keep track of them (if you were to try to save a record of the IP address on the User's browser, how would you retrieve it later to generate a report of all the IP addresses that accessed your site?).
Hence, you'll need to use a 'server-side' language.
Server-side scripts, such as index.php or contact_us.asp are files on the server just like title.html or wellImSureYouGetTheIdea.txt.
When you request an '.html' or '.txt' file, the server takes whatever's in that file and sends it directly to your browser.
On the other hand, when your browser sends a request to a server for a '.php' or '.asp' file, the server first runs the script through a special interpreter, and then it sends *the result* to your browser instead.
Here's a very basic example.
Let's say you had a file on the server called 'hello.txt'. It contains a single line:
When the server receives a request for hello.txt, it loads the content of that file ('Hello, World!') and sends it to the browser.
Now let's look at a simple PHP file, called 'hello.php':
-
<?php echo 'Hello, World!'; ?>
-
When the server receives a request for hello.php, it loads the content of that file, and then
it runs that code through the PHP interpreter and then it passes the result (which happens to also be 'Hello, World!') to the browser.
With that in mind, the general flow of development for an IP address logger would be:
- Configure your server to execute PHP scripts. In the case of professional hosting, this step may already be done. In the case of using your own computer, you may have to install and set up PHP yourself (but we'll be happy to help you out ^_^).
- Create a PHP script that logs the IP address.
- Turn your HTML pages into PHP scripts so that you can include the script that logs the User's IP address at the top of them.
To solve step #1, we first need to know your server setup. Is your website on the internet now? Do you have your own server? Is it professionally hosted (i.e., are you paying some company on the west coast to host your site, or is your friend hosting the site from a computer in his basement)?