Nov 8, 2009

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

free web hosting
Open Discussion > xisT-O-Rama > Life Talk > 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.

Comment/Reply (w/o sign-up)

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.

 

 

 


Comment/Reply (w/o sign-up)

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

Comment/Reply (w/o sign-up)

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";
?>

Comment/Reply (w/o sign-up)

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.

Comment/Reply (w/o sign-up)

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 :|

Comment/Reply (w/o sign-up)

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

Comment/Reply (w/o sign-up)

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.

Comment/Reply (w/o sign-up)

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.

Comment/Reply (w/o sign-up)

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

Comment/Reply (w/o sign-up)



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*

This textarea will convert to Rich-Text automatically (IE, Firefox, Chrome)

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 Thanks! Here is the MEMBERINFO template where they call
    it. How can I add that dateline code to the above code. All I want is the above edited to include
    the dateline. CODE $vbphrase " border="0" style="border:1px solid $stylevar " /> ....
  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.
    (3)
    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. 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.....
  14. 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.....
  15. 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:....
  16. How to add BB code...
    (3)
    How can i add BB code and Smileys to my script??? plz help! thnk!....
  17. 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.....
  18. script code
    (3)
    can someone help me with a php&mysql password code for my web page??? An example should be
    perfect.......
  19. Color? What code?
    (18)
    Do you know one good program who can tell you a code of specific color? Like: (some color)=#CC2564....
  20. 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.....
  21. "free forum code"
    (3)
    maintenance, there are alot of website that use forum PhpBB. You can download at
    http://www.phpbb2.de ....
  22. who'll release new PHP code about IBF forum
    (9)
    I like this, who'll share one? Thanks....
  23. 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.....
  24. 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 function toggle(what){  if(document.all .style.display == "none"){  
     document.all .style.display = "block";  }else{    document.all .style.display = "none";  } }
    //--> Toggle  Some Text... Blah Blah Blah.... This is what I can remember.....
  25. 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-busting riddles t....
  26. Crack The Binary Code...
    and win an account with 50 Gmail Invites (-1)
  27. 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....
  28. Crack The Binary Code An Win A Gmail Invitation!
    as if you don't have one already... (9)
    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

Searching Video's for display, ip, address, web, page, php, code
See Also,
advertisement


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

Affordable Web Hosting, Low cost Web Hosting - ComputingHost.com