Continues From Part 8
How to get IP addresses of visitors.As promised, in this refinement I'll get the IP address of the visitor and show inside a formatted division to visitors who come to the contact page. You can use the code inside any other page of your choice. First let me put the final code here for your consideration (download PHP code in Zip format here or open the code in text format here).
Look at lines (254) to (272). A function has been added that returns IP address using PHP standard methods. This is very crude implementation of PHP and those methods should be guarded, in principle, against access to any global. Nevertheless it works for now and interested individual can do better by gaining deeper knowledge of PHP.
At line (130) visitor's IP has filled variable $visitor_ip to be displayed later with an echo command. Line (131) defines a $hdshake variable to show a formatted phrase for $visitor_ip and $Email of the visitor.
If the visitor has attempted the contact form, then lines (141) to (143) display their IP and email.
Otherwise, if the visitor has just landed on the contact form page, then the page only displays his IP. This is reflected in the else phrase in lines (216) to (218).
Meanwhile note that lines (174) to (176), where you have sent the visitor's IP back for yourself for having further information to keep in your own database.
This is the snap-shot of page when visitor lands on page.
clicking here, please. In the next article we collect IP's of every visit in a text file.
Download this tutorial as PDF format here
Download part 1 to part 9 as PDF format here