View Full Version : Show IP address using PHP!


XxJenny
04-02-2004, 12:14 PM
Say people are looking through your source code and you find that people sometimes copy your work? You'll obviously want them to stop and you want to give them a little message to them when they next look at your source?
You'll simply put something like..

<!-- please get out of my source code thanks! -->
Or something of the sort..

But sometimes people don't care. So we put something to 'scare' them away. And when they do this they won't be too sure to come back!

First off you need to understand the code.
It's only one line and it's pretty simple!

<?php print "$REMOTE_ADDR"; ?>

Let's split it up.

<?php print - simply 'prints' whatevers after it (aslong as its correct)
"$REMOTE_ADDR"; - This is what calls the IP Address
> - Ends the code

Right. Got it? Good.
So now you know what

<?php print "$REMOTE_ADDR"; ?>

Means (and does) lets see if it works.

Open up a notepad file (« or whatever editer you use to code) and paste the code in it.
Save it as test.php and upload it. (oh yeah make sure your host allows php :P)

Now preview it.

It should come up with an IP (your ip address) some numbers and some dots.. it works ;)

Now it works you can put it in your source code ..

<!--I don't like people in my source code if they mean to copy.. i have your ip address!! here it is - <?php print "$REMOTE_ADDR"; ?> -->

and guess what! they won't see the $REMOTE_ADDR code! They'll see their very own ip address!

..well if the page which you pasted that code in (above) has a file ending similiar to .php or .phtml ;)

If it's different (ex. .html) it'll show the code and it won't work..