[Tutorial] Showing someone's IP address

Example of PHP code.

Moderator: Moderators

[Tutorial] Showing someone's IP address

Postby Greg on Sun Feb 27, 2005 7:43 pm

EDIT: Read last post first

Hey,

Many people ask on forums how to show someone’s IP address, just use this code:

Code: Select all
<?php
echo "Your IP: $_SERVER[’REMOTE_ADDR’]";
?>


Very Simple.

PS Lot’s of sites use $REMOTE_ADDR but they should take a look in manual on register_globals :wink:

Greg

This work is licensed under a Creative Commons License
Last edited by Greg on Sun Feb 27, 2005 9:14 pm, edited 2 times in total.
User avatar
Greg
Registered User
Registered User
 
Posts: 651
Joined: Wed Jul 07, 2004 3:20 pm
Location: Yorkshire, United Kingdom

Postby PostBot on Sun Feb 27, 2005 7:47 pm

It won't work. You are trying to output variable that is inside single quoted string. Variables are parsed only inside double quoted strings.

Also you should always check if variable exists by using isset() or empty() - in case if someone runs your script from command line or server has non-standard configuration.
Do NOT pm me, I don't visit this forum anymore, don't own it, don't provide any support and don't moderate.
User avatar
PostBot
Moderator
Moderator
 
Posts: 10659
Joined: Sat Aug 02, 2003 3:52 pm
Location: Mars

Postby Greg on Sun Feb 27, 2005 7:51 pm

:roll: Woops. I changed it now, I used double quotes but I saw someone post the opposite somewhere and they told me to use single quotes :?

Thanks for the information though.
Greg
User avatar
Greg
Registered User
Registered User
 
Posts: 651
Joined: Wed Jul 07, 2004 3:20 pm
Location: Yorkshire, United Kingdom

Postby PostBot on Sun Feb 27, 2005 9:10 pm

It won't work ether. When using array variables inside double quoted string you should not use single quotes or use {}.

Valid versions:
Code: Select all
echo "Your IP: {$_SERVER['REMOTE_ADDR']}"; // added {} for variable
echo "Your IP: $_SERVER[REMOTE_ADDR]"; // removed single quotes
echo 'Your IP: ', $_SERVER[’REMOTE_ADDR’]; // don't use double quotes at all.

Last version is the fastest because double quotes are processed awfully slowly. And when using that method don't use dot in echo() to put all in one string and instead use comma to separate strings as different parameters - it works faster.
Do NOT pm me, I don't visit this forum anymore, don't own it, don't provide any support and don't moderate.
User avatar
PostBot
Moderator
Moderator
 
Posts: 10659
Joined: Sat Aug 02, 2003 3:52 pm
Location: Mars

Postby Cyberpawz on Thu Mar 03, 2005 3:17 pm

How do you add color to the script? :) I want to get a little flashy and want to do something with it to make a small animation.
Cyberpawz
Registered User
Registered User
 
Posts: 3
Joined: Fri Jan 14, 2005 5:31 pm

Postby Shifty31 on Fri Mar 04, 2005 1:13 pm

thanks greg for the help

Regards Shifty :D
User avatar
Shifty31
Registered User
Registered User
 
Posts: 51
Joined: Wed Feb 23, 2005 7:08 am

Re: [Tutorial] Showing someone's IP address

Postby texacoon on Sat Apr 09, 2005 4:01 am

Code: Select all
<?php
echo "Your IP: $_SERVER[’REMOTE_ADDR’]";
?>


Hi Greg,
I am not sure what file this is suppose to be installed in ??? Would you please direct me on this? ...
Thanks
Doug
texacoon
Registered User
Registered User
 
Posts: 8
Joined: Sat Apr 09, 2005 3:55 am

Postby pentapenguin on Sat Apr 09, 2005 4:55 am

You can put that in any .php file, or if you have eXtreme Styles installed, you can put it in any .tpl file in your forum.
User avatar
pentapenguin
Moderator
Moderator
 
Posts: 1466
Joined: Tue Sep 14, 2004 4:15 pm
Location: Georgia, USA

Postby texacoon on Sat Apr 09, 2005 2:30 pm

[quote user="pentapenguin" post="27736"]You can put that in any .php file, or if you have eXtreme Styles installed, you can put it in any .tpl file in your forum.[/quote]

Thanks pentapenguin!

I will give it a shot and see how it works for my site.... Have the standard version of PHPBB ... Not sure if I need to move to the eXtreme yet ...

Thanks Again!
Doug
texacoon
Registered User
Registered User
 
Posts: 8
Joined: Sat Apr 09, 2005 3:55 am

Postby texacoon on Sat Apr 09, 2005 6:17 pm

I added the code above to my memberslist.php .... I do not see anything that helps me as an admin to help me identify anyones IP Address.

What would be nice for folks like me (administrator) is to have a column installed in the EMAIL list that would include members IP Address.
This way it would be hidden from the public and other members yet would be beneficial for admin to copy the IP Address and ban them from the site.

Maybe this should be written in the mods there again there may already be one available that I can not locate.
texacoon
Registered User
Registered User
 
Posts: 8
Joined: Sat Apr 09, 2005 3:55 am

Postby pentapenguin on Sat Apr 09, 2005 6:48 pm

texacoon, that code above shows *your* IP address.

My Advanced IP Tools Pack doesn't add the IP address in the memberlist, but it does add it to the view profile page. ;)

And be sure to use XS, if used for nothing else, it speeds up your site and is about the easiest MOD anywhere to install. :)
User avatar
pentapenguin
Moderator
Moderator
 
Posts: 1466
Joined: Tue Sep 14, 2004 4:15 pm
Location: Georgia, USA

Postby texacoon on Sat Apr 09, 2005 8:56 pm

Thanks pentapenguin!

I will give it a go and us the XS .... After I install the MOD and test it, I will certainly report back to this site and give you my results.

Thanks again!
Doug
texacoon
Registered User
Registered User
 
Posts: 8
Joined: Sat Apr 09, 2005 3:55 am

Postby texacoon on Sun Apr 10, 2005 3:24 am

[quote user="texacoon" post="27809"]Thanks pentapenguin!

I will give it a go and us the XS .... After I install the MOD and test it, I will certainly report back to this site and give you my results.

Thanks again!
Doug[/quote]


pentapenguin,
Seems to work well for users who have made a post (messages) and their IP Address.
What about those who haven'tt? When there is a new register, should the MOD show their IP Address as well?
OR
Shouldn't I see something in their profile?
texacoon
Registered User
Registered User
 
Posts: 8
Joined: Sat Apr 09, 2005 3:55 am

Postby pentapenguin on Sun Apr 10, 2005 4:43 am

Since phpBB by default doesn't record IPs on signup, there's no previous record, and so my MOD only affects new signups.
If you have any more questions, feel free to start a new thread on my board since we don't want this thread to go way off topic. ;)
User avatar
pentapenguin
Moderator
Moderator
 
Posts: 1466
Joined: Tue Sep 14, 2004 4:15 pm
Location: Georgia, USA

Does the dog know the proverb too

Postby gohome on Thu Apr 16, 2009 8:00 am

Does the dog know the proverb, too?

A little boy did not like the look of the barking dog.

"It's all right." said a gentleman. " Don't be afraid. Don't you know the proverb. 'Barking dogs don't bite'?"

"Ah, yes." answered the little boy. " I know the proverb, but does the dog know the proverb, too?"

Progress is the activity of today and the assurance of tomorrow .(Emerson, American thinker )
More Games,joke,
Warhammer Gold and famous. Click http://www.ygscn.net You will get more.
gohome
Registered User
Registered User
 
Posts: 18
Joined: Thu Apr 16, 2009 2:27 am


Return to PHP Tutorials

Who is online

Users browsing this forum: No registered users and 1 guest

cron