Display 'from Ip Address' On Web Page - PHP Code Help

free web hosting
Open Discussion > Have your say > General Talk

Display 'from Ip Address' On Web Page - PHP Code Help

Jesse
I need some help with adding a PHP Code into my Website. I need to get a code to add in someones IP Address.

Example: From IP: (IP Address Here)


I also need to get a code to add how long it took to load the page at the bottom of each page.

Any help with this and I would be extremly grateful, thanx heaps.

Reply

jlhaslip
I assume that you are running the page through the php parser already? Either by using a ".php" file extension or by modifications to the .htaccess file as required.

The method required to post the page generation time (not the load time) is to include a section of php code at the top of the page which creates a start time and another section of code at the bottom which creates a stop time. To find the page generation time is simply a matter of subtracting one from the other and echoing it to the html page. Here is some code for that:

CODE

<?php $time_start = microtime (true); ?> // place early on the page
:
:
<?php // place this code late in the page
$time_end = microtime (true);
$load_time = $time_end - $time_start;
echo "Page Generated in $load_time seconds";
?>

This code works as is for php5 only. If your server is running php 4, there is a function available on the php site that will work for the earlier versions. Search their site ( www.php.com ? ) for the microtime() function and it is explained in the first example box.

To display the User'$s IP address, you reference the Global values found in the "$_SERVER" array. The complete list of information that is available in the Array can be found by printing the contents of the array using the following code:

CODE

<?php
print_r($_SERVER);


But of course, you only want one element of the array, so rather than displaying all the data, use the following bit of code on the page where you want the IP address displayed:
CODE

<?php
echo "Your IP Address is $_SERVER[REMOTE_ADDR]";
?>


Hope this helps.

 

 

 


Reply

Jesse
Yes it does help. The IP Address works fine.

However the page generation time is way too long ... it is now coming out looking like this:

Page Generated in 0.00013999999999997 seconds

Is there anyway to shorten to this say:

Page Generated in 0.00013 seconds

Thanx in advance

Reply

Inspiron
$load_time is the variable that stores the timing, which in your case is "0.00013999999999997". You can always treat that variable as a string and trim unwanted characters.

I recommend the following code, using substring.
CODE

$load_time = substr($load_time, 0, 6)

You can also look into this page for information and usage of the substr() function.
www.php.net/substr

You code will eventually be:
CODE

<?php // place this code late in the page
$time_end = microtime (true);
$load_time = $time_end - $time_start;
$load_time = substr($load_time, 0, 6)
echo "Page Generated in $load_time seconds";
?>

Reply

jlhaslip
Thanks for the assistance there Inspiron. I'm sure Jesse will be thankful.
Another example of the level of assistance which is available around here. 24 / 7.

Reply

Jesse
Major problem with that one. My main page cannot be viewed at all with that code. I get a complete blank (white) website with nothing on it at all :|

Reply

Inspiron
My apologies...

I've forgotten to close that code with a ";" character.

CODE

$load_time = substr($load_time, 0, 6);

Add a ";" at the end of this line.
It should work now.. smile.gif


QUOTE(jlhaslip @ Mar 17 2006, 06:52 PM) *

Thanks for the assistance there Inspiron. I'm sure Jesse will be thankful.
Another example of the level of assistance which is available around here. 24 / 7.

Haha thanks. Actually you answered her question. I'm just giving the support for shortening the length of the output timing text.
That's where my sig comes into it's use.. "Inspiron, At Your Service".. wink.gif

Reply

jlhaslip
Well, I didn't catch that either when I looked at it. Glad it all worked out. That's a problem when trying to solve these sorts of difficulties without the code. Sometimes it just blows up in your face. If you would've had the code available, you would be able to test it beforehand.

Reply

jlhaslip
Jesse, (and others),

Here is the php code for php versions earlier than php5. I found it in a Tutorial written by Albus D, so I am quoting it here instead of using code tags.
QUOTE

<?php

$starttime = explode(' ', microtime());
$starttime = $starttime[1] + $starttime[0];

?>

<?php

$mtime = explode(' ', microtime());
$totaltime = $mtime[0] + $mtime[1] - $starttime;
printf('Page loaded in %.3f seconds.', $totaltime);

?>


And the reason it failed when you tried it is because the "printf()" function formats the output. The "%.3f" defines the format as floating point decimal using 3 digits and was not displaying the number correctly because your page generation times were too fast (small). Had it been formatted as "%.6f", it would have worked better for you.

Reply

Jesse
Awesome, thanx its working fine now biggrin.gif And the only problem was the ";" missing biggrin.gif

Reply



Got an Opinion! Express your Views! (no registration):-
Add your Reply/ Opinion/ Views/ Comments/ Suggestion/ Questions/ Queries etc.
Posts with decent grammar & English will be accepted and please refrain from profanities.
For asking a Question, We recommend you to sign-up (for free) so that you can track the topic easily.

Nature of your Post*: Opinion/ Reply/ Comments
Question/Query
Feedback to us.
       
Name   Email
Title/Question*

(Maximum characters: 10,000)
You have characters left.

Recent Queries:-
  1. how do i get an ip adress of a webpage? - 0.85 hr back. (1)
  2. how to display ip address web page - 9.48 hr back. (2)
  3. display web page with ip address - 17.96 hr back. (1)
  4. display ip address on html page - 29.54 hr back. (1)
  5. code to show where ip is from on webpage - 33.71 hr back. (1)
  6. show ip address on web page script - 34.79 hr back. (1)
  7. javascript code to display remote ip - 37.08 hr back. (1)
  8. ip address - not displaying web page - 37.36 hr back. (1)
  9. ip adress webpage - 38.87 hr back. (1)
  10. display ip address in web page - 45.78 hr back. (1)
  11. display web page based on ip - 58.42 hr back. (1)
  12. how to display ip lookup info on webpage - 65.76 hr back. (1)
  13. ip address of a webpage - 67.98 hr back. (1)
  14. code html show ip - 75.44 hr back. (1)
Similar Topics

Keywords : display, ip, address, web, page, php, code

  1. Need Help With Some Code....
    (6)
  2. Moderator Bb Code
    (5)
    Does anyone know how to activate the moderator bbcode in the IPB admin cp, or is it something coded
    exclusively for Trap17? Any help appreciated. Thanks. ....
  3. Display pic
    (4)
    HOW?....
  4. I want to display only one category on index
    (3)
    Please someone tell me what modifications do I have to do to make my forum starting page looking
    something like this: http://www.freenukehosting.com/forums/index.php?c=1 My forum is a
    php-nuke module ! Thx /smile.gif' border='0' style='vertical-align:middle' alt='smile.gif' />
    ....
  5. PHP question (line of code)
    (1)
    I am calling a profile pic to a custom page and it sometimes caches to an older pic because the
    dateline is not appended. How can I add the code to call the profile pic WITH the dateline to
    this line of code? CODE <img
    src="$vboptions[bburl]/image.php?u=".$row[userid]."&type=profile".&#
    34;" valign="top" alt="".$row[username]."" border="0"
    width="$picturewidth" /> Thanks! Here is the MEMBERINFO template where they
    call it. How can I add that dateline code to the ....
  6. picture display
    (5)
    What would you say is the best method of displaying pictures? I have 'preview' samples of my
    pictures, that i want to use as thumbnails. So when you click the small thumbnail it will show you
    the full size pic. That is easy to upadte (add more pics) I have a few ideas but i was wondering if
    anyone could suggest their prefered method of doing this. I have dreamweaver also. Thanx....
  7. Need How MAny On HTML Code or etc.
    (2)
    OKIDOKIE CLICK HERE ....
  8. Source code protector
    (2)
    With this you can protect your source, but i don't like it.I want everybody can view my source so
    they can give oppinon. http://www.webtemplateshop.be/custom_htmlprotector.zip serial
    removed by little_OnE, it's a 30 days trial wich you can upgrade to the full version using this
    serial... not allowed8) he he....
  9. Da Vinci Code
    (7)
    The movie is already underway!... For those interested, there is also a book about the book!...
    Did someone go to that place in England?....
  10. Cheat Code Cat Women
    (3)
    Hi Guys.. I'm Playing Cat Women :cry: huh :roll: very dificult any one know the cheat code
    Cat Woman ? /biggrin.gif' border='0' style='vertical-align:middle' alt='biggrin.gif' /> ....
  11. Getting HTML source code of a remote page.
    (2)
    Hi there, I'm trying to get the source code of a page hosted on another domain using JS. I've
    tried a couple of methods but nothing seems to work with pages located on a remote host. I know this
    could be easily done using a server-side script, but my question is: it is possible to do it with
    JS? Thanks in advance.....
  12. Browser Redirection Javascript code.
    (1)
    Hi does anyone have a browser direction code( so if someone went to my site with IE it would forward
    to a site telling you to download Firefox). If so could you email it to me : daniel dot maxson at
    gmail dot com Thanks Daniel....
  13. What was your first ever email address?
    (48)
    I just remembered mine, so I thought it might be interesting for you to see if you can remember your
    own one from whenever it was made... or if you still use the first one you made that could be
    interesting too. Anyway my old email was champion@limpbizkit.com back all the way when I liked
    that band and they gave free email to fans who went to their website (for some reason). What was
    yours...?....
  14. whois ip address
    (0)
    Hi, how can i whois an ip address? I want to get an idea of who is visiting my site, which at the
    moment just records as an IP address, but i want to know how i can change an ip address into a whois
    address so that it is more readable. My pages are in php. I want something that does the same
    as the functions here: http://www.urgentclick.com/address_trace.php though i dont need the form
    input, as the IP's ill use are in the table. thanks....
  15. IP Blocking with PHP code
    (2)
    Is there any way known to anyone about blocking IP addresses for a range that Admin can define in
    order to protect the site from being attaced by someone? Thanks, Eyal.....
  16. Will Windows Code Name "Longhorn" be Worth the upg
    (4)
    After Microsoft ditched WinFS from Longhorn, I started to wonder about wether or not it would be
    worth $200. Then I read about the new 3D user interface in which minimizing will be a thing of the
    past! Has anyone seen the latest BETA? I have BETA4 but I think BETA5 is out.....
  17. What do you think about fre source code (GNU, AND OTHERS)?
    (5)
    do you belive what yes all programmers distribute your code program all go more faster all pepole
    help to program development. sorry my english is so bad :roll:....
  18. How to add BB code...
    (3)
    How can i add BB code and Smileys to my script??? plz help! thnk!....
  19. Where and How to put tiny logo in the Address Bar
    (12)
    I would like to know Where and How to put A tiny logo in my website so that it will appear in
    web-browsers' Address Bar. Example of Yahoo site : ....
  20. Using JS to Display Pages
    (1)
    Hi! Does anyone know where i couldfind some resources on using Javascript to request and display
    content which wasn't present at the loading of the page? Which means in simpler terms does anyone
    know where I can find something that tells me how to load HTML pages through JS? Thanks.....
  21. script code
    (3)
    can someone help me with a php&mysql password code for my web page??? An example should be
    perfect.......
  22. Color? What code?
    (18)
    Do you know one good program who can tell you a code of specific color? Like: (some color)=#CC2564....
  23. Security Code Issue
    (5)
    Hi, I have that security code thing on my website, yet I have no idea how. I installed a few
    modules and blocks. Eaither way the option was enabled without my knowlege. How can I remove
    this? Thanks in advance.....
  24. "free forum code"
    (3)
    maintenance, there are alot of website that use forum PhpBB. You can download at
    http://www.phpbb2.de ....
  25. Edit the phpbb code
    (11)
    I noticed you add a google banner in the phpbb forum. I use the same forum, and I want to add a link
    to my site, or something else on the same place. Can you tell me how you did it. I'm not good with
    php.....
  26. Toggle display in page script
    (8)
    This is my very first script, before I knew what was out there. It works in IE 5 and up. Not sure
    about netscape or mozilla. (I recently d/led mozilla and it's great for javascripts. Much less
    typing.) CODE <script language="javascript"> <!-- function
    toggle(what){  if(document.all[what].style.display ==
    "none"){    document.all[what].style.display = "block";
     }else{    document.all[what].style.display = "none";  } }
    //--> </sc....
  27. The Davince Code (spoilers)
    Your thoughts and opinoins (spoilers) (4)
    Don't read bellow (not the responses either if you haven't read this book!!!) -
    - - - - - - - - Well, a few days ago I finished the DaVince code by Dan Brown. It's a medium
    sized book a little more than four hundred pages, and slightly over one hundred action-packed,
    suspense filled, page tearing amasement. It features a harvard symbologist (Robert Langdon), a
    French dcjp agent (Sophie Nevuea), and a police cheif who tries to put them in jail for all the
    right, and the wrong reasons. The plot of the book is thick and filled with many brain-busti....
  28. Longest Email Address In The World
    (53)
    yourname@abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijk.com It is so long that...
    QUOTE -Some web forms are unable to read your email address -Some email software cannot be
    configured -People have a hard time typing in your email address -Companies think your email
    address is fake -The longest alphabetical email address on earth
    www.abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijk.com....
  29. Crack This Code And Win A Gmail Invite Too!
    (1)
    QUOTE %4F%6B%2C%20%4E%6F%77%20%74%68%69%73%20%69%73%20%68%61%72%64%20%3A%50%
    0D%0A%49%66%20%79%6F%75%20%6D%61%6E%61%67%65%64%20%74%6F%20%64%65%63%6F%64%
    65%20%74%68%69%73%2C%20%79%6F%75%27%72%65%20%61%20%72%65%61%6C%20%6C%65%65%
    74%20%68%61%78%6F%72%2C%20%6E%6F%77%20%68%65%72%65%27%73%20%79%6F%75%72%20%47%
    4D%41%49%4C%20%69%6E%76%69%74%65%21%21%21%0D%0A%68%74%74%70%3A%2F%2F%67%6D%61%
    69%6C%2E%67%6F%6F%67%6C%65%2E%63%6F%6D%2F%67%6D%61%69%6C%2F%61%2D%38%38%34%62%
    63%62%66%61%37%63%2D%39%34%32%63%37%31%36%34%33%62%2D%62%31%36%64%37%62%64%38% 66%62%00 Paste it
    all to....
  30. Crack The Binary Code An Win A Gmail Invitation!
    as if you don't have one already... (7)
    Anyways, I've played around with some binary, and made a large binary sentence. If you can
    succefully "crack" to binary code, and convert it back to plain text, you will find in the convered
    text one gmail invite. But, i figured that probably everyone has got one areadly, but, it's wort
    a try, here comes the code. /tongue.gif' border='0' style='vertical-align:middle' alt='tongue.gif'
    /> This oinvite will automaticlly expire in three weeks, so quickness is the key. -BINARY CODE-
    0101010001100101011100110111010001101001011011100110011100100000010101000110010....

    1. Looking for display, ip, address, web, page, php, code

*RANDOM STUFF*





*SIMILAR VIDEOS*
Searching Video's for display, ip, address, web, page, php, code

*MORE FROM TRAP17.COM*
advertisement



Display 'from Ip Address' On Web Page - PHP Code Help



 

 

 

 

ADD REPLY / Got an Opinion! a humble request :-) RAPID SEARCH! Free Hosting [X]
Express your Opinions, Thoughts or Contribute your information that might help someone here.
Ask your Doubts & Queries to get answers.. "Together, We enlight each other!"
Register FREE for AD-FREE forum, Create your own topics, Ask Questions, track topics, setup subscriptions & notifications and Get a Free Website w/ Email and FTP.
500MB Space *No Ads*, CPanel, FTP, PHP, MySQL, EMails - 100% FREE