Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New Coder
    Join Date
    Jan 2010
    Posts
    36
    Thanks
    0
    Thanked 0 Times in 0 Posts

    code for getting IP address and system time

    in my php page i have added code for getting IP

    PHP Code:
      if (!empty($_SERVER['HTTP_CLIENT_IP']))   //check ip from share internet
        
    {
          
    $ip=$_SERVER['HTTP_CLIENT_IP'];
        }
        elseif (!empty(
    $_SERVER['HTTP_X_FORWARDED_FOR']))   //to check ip is pass from proxy
        
    {
          
    $ip=$_SERVER['HTTP_X_FORWARDED_FOR'];
        }
        else
        {
          
    $ip=$_SERVER['REMOTE_ADDR'];
        } 
    but i am not getting the real IP . HOW TO GET THE REAL IP ??
    give me a solution..

    i have got one more problem..
    to get the system date and time .added the following

    PHP Code:
    $date date(' d/m/Y h:i:s A'); 
    but the time am getting is 3 hours behind the system time , i need to get the system time , how??
    suggestions plz...thank u..

  • #2
    Regular Coder
    Join Date
    Mar 2006
    Posts
    238
    Thanks
    3
    Thanked 37 Times in 37 Posts
    Just a few notes:

    $_SERVER['HTTP_CLIENT_IP'] contains the "Client-Ip" HTTP header and could be forged.

    $_SERVER['HTTP_X_FORWARDED_FOR'] contains "X-Forwarded-For" header and could be forged.

    One could send any of these 2 headers e.g. with header(). Both $_SERVER['HTTP_CLIENT_IP'] and $_SERVER['HTTP_X_FORWARDED_FOR'] are not really reliable.

    As to the date() function, you could need to set the time zone in the way it could be necessary. For PHP5 date_default_timezone_set() could be used.
    Last edited by SKDevelopment; 02-21-2010 at 01:10 PM. Reason: corrected function name

  • #3
    Regular Coder
    Join Date
    Dec 2008
    Posts
    133
    Thanks
    15
    Thanked 0 Times in 0 Posts
    I normally use:

    PHP Code:
    $user_ip $_SERVER['REMOTE_ADDR']; 
    for user IP

    and

    PHP Code:
    $date date('m/d/Y')." at ".date('g:i.s')." ".date('a'); 
    For a Timestamp with date and time.

    Hope this helps!

  • #4
    New Coder
    Join Date
    Jan 2010
    Posts
    36
    Thanks
    0
    Thanked 0 Times in 0 Posts
    thank you for the suggestions , it worked ,
    Thanks a lot.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •