1
JasonMR
IP display hack
  • 2004/9/19 13:22

  • JasonMR

  • Just can't stay away

  • Posts: 655

  • Since: 2004/6/21


While replying to thishttps://xoops.org/modules/newbb/viewtopic.php?forum=7&topic_id=24674, I came across a neat solution, to display a users IP on a page, by creating an image that displays the text "Your IP is xxx.xxx.xxx.xxx", using a PHP script, which I found on a web page, supposedly belonging to a MikeVL.

1- create a file in /root/modules/contact/ and name it something like ipdisplay.php.
Place the following code into the file:
Quote:

<?php
$img_number = imagecreate(275,25);
$backcolor = imagecolorallocate($img_number,102,102,153);
$textcolor = imagecolorallocate($img_number,255,255,255);

imagefill($img_number,0,0,$backcolor);
$number = " Your IP is $_SERVER[REMOTE_ADDR]";

Imagestring($img_number,10,5,5,$number,$textcolor);

header("Content-type: image/jpeg");
imagejpeg($img_number);
?>


2- Open the following template file in an editor /root/modules/contact/templates/contact_contactusform.html;
In this file you will place an img-tag, using the ipdisplay.php file as source

Place the following in an apropriate location (though you might want to change the notification text!):
Quote:

<img src="http://yoursite.com/modules/contact/ip_image.php" alt="IP Address" /> has been logged!<br />Action will be taken on any abuse on this system.


3- Go to Sys Admin -> Moudles, and update the contact module

Et voila! You should now be able to view the result.

Making Changes to the PHP created Image

$img_number = imagecreate(275,25);

-> this pair represents the X and Y lengths

$backcolor = imagecolorallocate($img_number,102,102,153);
$textcolor = imagecolorallocate($img_number,255,255,255);

-> these tupples are hex-colors (255,255,255=white;0,0,0=black)

To create a border around the image, for a more prominent look, one just needs to add this style attribute to the img tag:
style="border:1px outset #000044; vertical-align:middle;"

I have implemented this hack with the contact+ module, but it can be applied with any module really (news, wiki, blog, forums, etc...).

Hope this might be of interest to a fellow XOOPser!

2
editor
Re: IP display hack
  • 2004/11/16 14:44

  • editor

  • Just popping in

  • Posts: 15

  • Since: 2004/2/1 7


Hi JasonMR

Very, very usefull this idea, but I try the scrip but he dont run
Is possible a setting error in my server like about images jpg, because dont show the image.

I correct the name of file to ip_image.php in your example cause is not the same in your script, the path is ok but not run. Can you help me?

3
JasonMR
Re: IP display hack
  • 2004/11/16 20:02

  • JasonMR

  • Just can't stay away

  • Posts: 655

  • Since: 2004/6/21


Your server needs to have the PHP GD library enabled.....thats all I can think of currently...

4
editor
Re: IP display hack
  • 2004/11/17 1:40

  • editor

  • Just popping in

  • Posts: 15

  • Since: 2004/2/1 7


Hummmmmmm I have a problem Houston....
My server dont have the PHP GD library enabled. The "mainframe guy of web host" say "this module have many security problem...no way. Try Neo to help you..." mdfk
What can I do without the image?

Tks for help me

5
JasonMR
Re: IP display hack
  • 2004/11/17 2:53

  • JasonMR

  • Just can't stay away

  • Posts: 655

  • Since: 2004/6/21


"...many security problems..." ???? Ah well, what ever he says....

Never the less, just use this code:

<p>Your IP address,
<? echo 
$REMOTE_ADDR ?>
has been logged</p>


...remember: the file you place this code in, must end with php, can't just place it in a template file!

If this doesn't do what you want, google for "java script display visitor ip", though this will only work if they have js enabled...

Hope this helps...

6
editor
Re: IP display hack
  • 2004/11/18 1:49

  • editor

  • Just popping in

  • Posts: 15

  • Since: 2004/2/1 7


I need learn more about PHP and how to insert in a .html template a content of a PHP or if is possible or not.
I put the code in modules/contact/index.php and the message and IP show in the wait screen (is correct that name?) when user send the form mail.



Tks

7
Cavan
Re: IP display hack
  • 2005/4/18 3:25

  • Cavan

  • Friend of XOOPS

  • Posts: 218

  • Since: 2004/11/28


This hack isn't working for me as well and I have GD Library enabled via my webhost...I still see nothing but a red x box...anyone got this working?

EDIT: Missed the error in the .php wording that's listed; one says "ipdisplay.php" and the other "ip_image.php". Fixed it and it works fine now. Thank you!

Login

Who's Online

260 user(s) are online (178 user(s) are browsing Support Forums)


Members: 0


Guests: 260


more...

Donat-O-Meter

Stats
Goal: $100.00
Due Date: Apr 30
Gross Amount: $0.00
Net Balance: $0.00
Left to go: $100.00
Make donations with PayPal!

Latest GitHub Commits