www.webdeveloper.com
Page 1 of 2 12 LastLast
Results 1 to 15 of 17

Thread: Capturing IP Address

  1. #1
    Join Date
    Dec 2007
    Posts
    129

    Capturing IP Address

    We use:

    PHP Code:
    $ipadd $_SERVER[REMOTE_ADDR]; 
    to capture the ip address of the customer and everything worked great.

    We just added an SSL certificate to make the site more secure and our order page is showing as HTTPS as supposed to HTTP. Now all the orders we receive have the same ip address. I checked the ip address and it is host.

    I have no idea how to start troubleshooting. If this is a server problem or the SSL, or wrong php code.

    Any help is appreciated.

    Thanks
    Lisa

  2. #2
    Join Date
    Jun 2008
    Location
    Europe
    Posts
    1,086
    There is probably a better way to do it, but I am a terrible PHP troubleshooter so look for the fast & easy way.

    Here is a hack that you can try:

    Put your PHP code inside of an iFrame on the page that is 1px X 1px. You can then have it capture the ipAddresses and be invisible. The iFrame 'content' can be http


  3. #3
    Join Date
    Dec 2007
    Posts
    129


    Omg, are you talking in latin? Show me an example. I do not understand a word you said. I am not a programmer, lol.

  4. #4
    Join Date
    Jun 2008
    Location
    Europe
    Posts
    1,086
    Sorry...

    An iframe is simply like a little window that another page can appear inside of. All of the code on that page will run.

    So you should put your PHP code that captures the IP address on its own page. Name that page something like: ipcapture.php

    Then, simply put it on your https page like this:

    HTML Code:
    <iframe width="1" height="1" src="ipcapture.php">You need a frames capable browser to see this content.</iframe>
    That should do it... it's a hack, but it's worth a try.
    Hope that helps.

  5. #5
    Join Date
    Dec 2007
    Posts
    129
    I sent an email to our host and this is what they said: "I am sorry to hear that you were experiencing issues with your secure page. All https requests to our Hosting Packages go through a Proxy server. This is necessary because your Hosting Package does not have a dedicated IP address. If you need a true dedicated IP address, you would need a Virtual Private Server (VPS)."


    VPS will cost us $40 a month as supposed to $160 a year on shared hosting. lmaooooooo! Is there really no other way to capture the user's ip w/o having our own VPS?

    Thanks

  6. #6
    Join Date
    Apr 2003
    Location
    Netherlands
    Posts
    21,654
    Try this: http://roshanbh.com.np/2007/12/getti...ss-in-php.html
    The 'HTTP_X_FORWARDED_FOR' can contain a comma delimited list!
    At least 98% of internet users' DNA is identical to that of chimpanzees

  7. #7
    Join Date
    Dec 2007
    Posts
    129
    Wow Fang, thanks. Right now, I am doing it this way:


    PHP Code:
    $ipaddy $_SERVER[REMOTE_ADDR]; 

    Problem is, how do I call the function or where do I place the code? I am not a programmer

  8. #8
    Join Date
    Apr 2003
    Location
    Netherlands
    Posts
    21,654
    Code:
    $ipaddy = getRealIpAddr();
    At least 98% of internet users' DNA is identical to that of chimpanzees

  9. #9
    Join Date
    Dec 2007
    Posts
    129
    PHP Code:
    $ipaddy getRealIpAddr();
    function 
    getRealIpAddr()
    {
        if (!empty(
    $_SERVER['HTTP_CLIENT_IP']))   //check ip from share internet
        
    {
          
    $ipaddy=$_SERVER['HTTP_CLIENT_IP'];
        }
        elseif (!empty(
    $_SERVER['HTTP_X_FORWARDED_FOR']))   //to check ip is pass from proxy
        
    {
          
    $ipaddy=$_SERVER['HTTP_X_FORWARDED_FOR'];
        }
        else
        {
          
    $ipaddy=$_SERVER['REMOTE_ADDR'];
        }
        return 
    $ipaddy;

    I placed the function right after the variable was declared and it did not work I am so frustrated. Should the function be in the html section of the page?

  10. #10
    Join Date
    Apr 2003
    Location
    Netherlands
    Posts
    21,654
    First the function then the variable
    At least 98% of internet users' DNA is identical to that of chimpanzees

  11. #11
    Join Date
    Dec 2007
    Posts
    129
    Arrrg, did not work either! I wonder if has something to do with how we gather the information and how they are being sent. Below is what we use:

    in php:
    PHP Code:
        if(strlen($messages)==0): 
            
    $mailheaders 'Content-Type: text/plain;'.$lterm
            
    $mailheaders .= 'X-Mailer: PHP;'.$lterm
            
    $mailheaders .= 'X-MSMail-Priority: High;'.$lterm
            
    $mailheaders .= 'X-Priority: 1;'.$lterm
            
    $mailheaders .= 'Return-path: '.$mailfrom.$lterm
            
    $mailheaders .= 'Sender: '.$mailfrom.$lterm
            
    $mailheaders .= 'From: '.$mailfrom.$lterm
            if (isset(
    $mailcopy
            && !empty(
    $mailcopy)): 
                
    $mailheaders .= 'Cc: '.$mailcopy.$lterm
            endif;
            
    $mailbody "email body
    IP Address:  
    $ipaddy.$lterm
            
    ini_set(sendmail_from$mailfrom); 
            if (
    mail($emailadr$mailsubj$mailbody$mailheaders"-f $mailfrom")): 
                
    ini_restore(sendmail_from); 
                
    header('Location: http://'.$_SERVER['HTTP_HOST'
                                          .
    dirname($_SERVER['PHP_SELF']) 
                                          .
    $thankyou);
                exit; 
            endif; 
            
    ini_restore(sendmail_from); 
            
    $messages 'Failed to send email!'
        endif; 

    in html:
    HTML Code:
    <form action="<?=basename($_SERVER['PHP_SELF'])?>" method="post">

  12. #12
    Join Date
    Nov 2007
    Posts
    140
    Quote Originally Posted by xoxLISAxox View Post
    I sent an email to our host and this is what they said: "I am sorry to hear that you were experiencing issues with your secure page. All https requests to our Hosting Packages go through a Proxy server. This is necessary because your Hosting Package does not have a dedicated IP address. If you need a true dedicated IP address, you would need a Virtual Private Server (VPS)."
    You don't need to buy a VPS just to get a private ip. Every shared host that doesn't suck offers private ip addresses for 2-3 extra dollars per month.

  13. #13
    Join Date
    Dec 2007
    Posts
    129
    I just called our provider. Unfortunately they do not offer a private ip address without switching to a Private Virtual Network that cost $40 a month


    I was wondering if Javascript can capture it and send it to php? I was doing a search using javascript and I think I found one that worked. Just don't know how to incorporate it to php which what we already use.

  14. #14
    Join Date
    Nov 2007
    Posts
    140
    You may want to consider changing hosts. I have an https server setup with hawkhost.com for $6 / month + $2 for the private ip which I just checked and the $_SERVER['REMOTE_ADDR'] value is set correctly to my ip address. If that's too much trouble then you may just snag the users ip via http as previously suggested.

    Chances are you already have an opportunity to store the customers ip before they get to the secure server. You can probably just store the customers ip in their session at that point.

    Note that your hosts http and https servers may not share the same session store by default but if they're both running on the same machine you may be able to use session_save_path() to resolve this issue.

    As for javascript... why bother... at that point the address would be so easy to tamper with that I can't see how it would of be of any use.

    Personally I wouldn't stay with a host that tried to upsell me a VPS for the sake of a private ip address.

  15. #15
    Join Date
    Dec 2007
    Posts
    129
    Unfortunately, we have a one year contract w/o a refund And will also require to rewrite the entire site because we are using their templates.


    Quote Originally Posted by tfk11 View Post
    If that's too much trouble then you may just snag the users ip via http as previously suggested.
    If you are talking about the iframe html workaround, I couldn't get it to work as part of the email message we are receiving using php. Please show me an example.

    Thanks
    Lisa

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles