<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: Using php to display visitor / user information such as their IP address</title>
	<atom:link href="http://www.theblog.ca/php-ip/feed" rel="self" type="application/rss+xml" />
	<link>http://www.theblog.ca/php-ip</link>
	<description>Useful tips on Canada, cell phones, banking, technology, WordPress, PHP and more</description>
	<lastBuildDate>Sat, 04 Feb 2012 03:38:13 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.1.2</generator>
	<item>
		<title>By: John</title>
		<link>http://www.theblog.ca/php-ip/comment-page-1#comment-16677</link>
		<dc:creator>John</dc:creator>
		<pubDate>Fri, 07 Oct 2011 20:55:22 +0000</pubDate>
		<guid isPermaLink="false">http://www.theblog.ca/?p=23#comment-16677</guid>
		<description>Thanks for the help. Works great...</description>
		<content:encoded><![CDATA[<p>Thanks for the help. Works great&#8230;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: John</title>
		<link>http://www.theblog.ca/php-ip/comment-page-1#comment-16639</link>
		<dc:creator>John</dc:creator>
		<pubDate>Thu, 29 Sep 2011 19:45:08 +0000</pubDate>
		<guid isPermaLink="false">http://www.theblog.ca/?p=23#comment-16639</guid>
		<description>Peter, 
Back in Oct. 2008 you replied to a user named Helen with the following script...


Hi Helen, here’s some code I use on a very low-traffic website:
 
&lt;?php
 
$filename = &quot;ips.txt&quot;;
 $handle = fopen($filename, &quot;a&quot;);
 fwrite($handle, $_SERVER[&#039;REMOTE_ADDR&#039;] . &quot;\n&quot;);
 fclose($handle);
 
// Rest of code
 ?&gt;
 
Basically, it inserts a line into a text file with the visitor’s IP address whenever the page is accessed. Of course, you might want to add other information depending on what you’re looking for. Your server logs should also contain some good information on every single visit.

The script works really good, but I have been trying to add an entry so that along with the IP Address it will also record the Date. So far I have been unsuccessful as I am somewhat new to PHP. Any help you can offer would be greatly appreciated.

Thank you

John

&lt;strong&gt;Reply from Peter: You could replace the &quot;fwrite&quot; line with something like:&lt;/strong&gt;

$content =  &quot;[&quot; . date( &#039;F j, Y, g:i a&#039; ) .  &quot;] &quot; . $_SERVER[&#039;REMOTE_ADDR&#039;];
fwrite($handle, $content . &quot;\n&quot;);

&lt;strong&gt;See the manual for the &lt;a href=&quot;http://php.net/function.date.php&quot; rel=&quot;nofollow&quot;&gt;date function&lt;/a&gt; for date formatting possibilities.
&lt;/strong&gt;</description>
		<content:encoded><![CDATA[<p>Peter,<br />
Back in Oct. 2008 you replied to a user named Helen with the following script&#8230;</p>
<p>Hi Helen, here’s some code I use on a very low-traffic website:</p>
<p>&lt;?php</p>
<p>$filename = &quot;ips.txt&quot;;<br />
 $handle = fopen($filename, &quot;a&quot;);<br />
 fwrite($handle, $_SERVER['REMOTE_ADDR'] . &quot;\n&quot;);<br />
 fclose($handle);</p>
<p>// Rest of code<br />
 ?&gt;</p>
<p>Basically, it inserts a line into a text file with the visitor’s IP address whenever the page is accessed. Of course, you might want to add other information depending on what you’re looking for. Your server logs should also contain some good information on every single visit.</p>
<p>The script works really good, but I have been trying to add an entry so that along with the IP Address it will also record the Date. So far I have been unsuccessful as I am somewhat new to PHP. Any help you can offer would be greatly appreciated.</p>
<p>Thank you</p>
<p>John</p>
<p><strong>Reply from Peter: You could replace the &#8220;fwrite&#8221; line with something like:</strong></p>
<p>$content =  &quot;[&quot; . date( 'F j, Y, g:i a' ) .  &quot;] &quot; . $_SERVER['REMOTE_ADDR'];<br />
fwrite($handle, $content . &quot;\n&quot;);</p>
<p><strong>See the manual for the <a href="http://php.net/function.date.php" rel="nofollow">date function</a> for date formatting possibilities.<br />
</strong></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Roberto Lunelli</title>
		<link>http://www.theblog.ca/php-ip/comment-page-1#comment-15574</link>
		<dc:creator>Roberto Lunelli</dc:creator>
		<pubDate>Wed, 16 Mar 2011 01:21:40 +0000</pubDate>
		<guid isPermaLink="false">http://www.theblog.ca/?p=23#comment-15574</guid>
		<description>The access can come from a proxy server and ip may be false.
To get the IP&#039;s better this way:

&lt;?php

function getIp()
{

    if (!empty($_SERVER[&#039;HTTP_CLIENT_IP&#039;]))
    {

        $ip = $_SERVER[&#039;HTTP_CLIENT_IP&#039;];

    }
    elseif (!empty($_SERVER[&#039;HTTP_X_FORWARDED_FOR&#039;]))
    {

        $ip = $_SERVER[&#039;HTTP_X_FORWARDED_FOR&#039;];

    }
    else{

        $ip = $_SERVER[&#039;REMOTE_ADDR&#039;];

    }

    return $ip;

}

?&gt;

sorry my english sucks</description>
		<content:encoded><![CDATA[<p>The access can come from a proxy server and ip may be false.<br />
To get the IP&#8217;s better this way:</p>
<p>&lt;?php</p>
<p>function getIp()<br />
{</p>
<p>    if (!empty($_SERVER['HTTP_CLIENT_IP']))<br />
    {</p>
<p>        $ip = $_SERVER['HTTP_CLIENT_IP'];</p>
<p>    }<br />
    elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR']))<br />
    {</p>
<p>        $ip = $_SERVER['HTTP_X_FORWARDED_FOR'];</p>
<p>    }<br />
    else{</p>
<p>        $ip = $_SERVER['REMOTE_ADDR'];</p>
<p>    }</p>
<p>    return $ip;</p>
<p>}</p>
<p>?&gt;</p>
<p>sorry my english sucks</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: NonSmoker</title>
		<link>http://www.theblog.ca/php-ip/comment-page-1#comment-15485</link>
		<dc:creator>NonSmoker</dc:creator>
		<pubDate>Sat, 26 Feb 2011 22:09:40 +0000</pubDate>
		<guid isPermaLink="false">http://www.theblog.ca/?p=23#comment-15485</guid>
		<description>Hi there. 
It is pretty practical, isn&#039;t it?
Do you also have a way to find out the visitors&#039; screen resolution? 

Thanks anyway,  
NonSmoker

&lt;strong&gt;Reply from Peter: This can be done with JavaScript -- there are probably a lot of example solutions if you Google for that.&lt;/strong&gt;</description>
		<content:encoded><![CDATA[<p>Hi there.<br />
It is pretty practical, isn&#8217;t it?<br />
Do you also have a way to find out the visitors&#8217; screen resolution? </p>
<p>Thanks anyway,<br />
NonSmoker</p>
<p><strong>Reply from Peter: This can be done with JavaScript &#8212; there are probably a lot of example solutions if you Google for that.</strong></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Joseph McCullough</title>
		<link>http://www.theblog.ca/php-ip/comment-page-1#comment-15184</link>
		<dc:creator>Joseph McCullough</dc:creator>
		<pubDate>Wed, 12 Jan 2011 06:51:08 +0000</pubDate>
		<guid isPermaLink="false">http://www.theblog.ca/?p=23#comment-15184</guid>
		<description>Quick and easy, thanks a lot.</description>
		<content:encoded><![CDATA[<p>Quick and easy, thanks a lot.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: newphpblogger</title>
		<link>http://www.theblog.ca/php-ip/comment-page-1#comment-14077</link>
		<dc:creator>newphpblogger</dc:creator>
		<pubDate>Mon, 23 Aug 2010 05:31:38 +0000</pubDate>
		<guid isPermaLink="false">http://www.theblog.ca/?p=23#comment-14077</guid>
		<description>can I create an php script, not using &quot;.php&quot; as the file format but using &quot;jpg&quot; or other image&#039;s name, so that I can insert it into my blogger? 

I ask this question is, some blogger administration only allow image to be inserted in blog. I want to insert the script in my blog.

&lt;strong&gt;Reply from Peter: Not the way you describe it.  If you have your own host, you could run PHP scripts on that server and embed the output elsewhere via iframes, images, or other output.&lt;/strong&gt;</description>
		<content:encoded><![CDATA[<p>can I create an php script, not using &quot;.php&quot; as the file format but using &quot;jpg&quot; or other image&#8217;s name, so that I can insert it into my blogger? </p>
<p>I ask this question is, some blogger administration only allow image to be inserted in blog. I want to insert the script in my blog.</p>
<p><strong>Reply from Peter: Not the way you describe it.  If you have your own host, you could run PHP scripts on that server and embed the output elsewhere via iframes, images, or other output.</strong></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: muhu</title>
		<link>http://www.theblog.ca/php-ip/comment-page-1#comment-12259</link>
		<dc:creator>muhu</dc:creator>
		<pubDate>Thu, 14 Jan 2010 21:40:41 +0000</pubDate>
		<guid isPermaLink="false">http://www.theblog.ca/?p=23#comment-12259</guid>
		<description>Hi, 

How can I make the server to write the visitors date and time in the ips.txt file for the visitors.

I followed your instructions and that is writing the ip address of the visitors but how can I make the server to write the date and time of the visit. what would be the code for that. 

Thank you

Mr Muhu

&lt;strong&gt;Reply from Peter: Check the &lt;a href=&quot;http://php.net/manual/en/function.date.php&quot; rel=&quot;nofollow&quot;&gt;PHP documentation for date&lt;/a&gt;&lt;/strong&gt;</description>
		<content:encoded><![CDATA[<p>Hi, </p>
<p>How can I make the server to write the visitors date and time in the ips.txt file for the visitors.</p>
<p>I followed your instructions and that is writing the ip address of the visitors but how can I make the server to write the date and time of the visit. what would be the code for that. </p>
<p>Thank you</p>
<p>Mr Muhu</p>
<p><strong>Reply from Peter: Check the <a href="http://php.net/manual/en/function.date.php" rel="nofollow">PHP documentation for date</a></strong></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Will Knot B. Revealed Snr.</title>
		<link>http://www.theblog.ca/php-ip/comment-page-1#comment-12226</link>
		<dc:creator>Will Knot B. Revealed Snr.</dc:creator>
		<pubDate>Sun, 10 Jan 2010 12:48:45 +0000</pubDate>
		<guid isPermaLink="false">http://www.theblog.ca/?p=23#comment-12226</guid>
		<description>Thanks. :)</description>
		<content:encoded><![CDATA[<p>Thanks. <img src='http://www.theblog.ca/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
	</item>
	<item>
		<title>By: THE MAN</title>
		<link>http://www.theblog.ca/php-ip/comment-page-1#comment-12108</link>
		<dc:creator>THE MAN</dc:creator>
		<pubDate>Wed, 23 Dec 2009 14:35:14 +0000</pubDate>
		<guid isPermaLink="false">http://www.theblog.ca/?p=23#comment-12108</guid>
		<description>THANKS A LOT OF THIS!!!!!!!!!!!!!!!!!!!!!!!!</description>
		<content:encoded><![CDATA[<p>THANKS A LOT OF THIS!!!!!!!!!!!!!!!!!!!!!!!!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: solow</title>
		<link>http://www.theblog.ca/php-ip/comment-page-1#comment-11903</link>
		<dc:creator>solow</dc:creator>
		<pubDate>Fri, 27 Nov 2009 08:13:26 +0000</pubDate>
		<guid isPermaLink="false">http://www.theblog.ca/?p=23#comment-11903</guid>
		<description>&quot;Benjamin says:

Are you freaking kidding? Next, are you going to ask if there&#039;s a way to record people&#039;s keypresses using php! F*** off!&quot;

Dude, there is. Using javascript you can record key presses using keycode.

&quot;Vasim Padhiyar says:

hello all,
is there any function in php or javascript that
gives me the details of user&#039;s local computer harddrive info also with all folder and files in that drive .&quot;

Yes there is. But is depends, what do you want to achieve? if you want to upload, it&#039;s quite simple, else yes, you need to create some sort of add on, to browse trough your files. like a toolbar or sum.

&quot;Eric says:

Great job, now i only need to know how to read other settings from the browser!&quot;

Interesting.
Ok, some code for yah.

$_SERVER[&#039;HTTP_USER_AGENT&#039;] Get the users browser. Now this alone is boring don&#039;t you think? So why not try adding this one: 
$browserInfo= get_browser(null, true);
print_r($browserInfo);

This&#039;ll print the users browser, and what it is capable of. also, using this echo: echo $browserInfo[&#039;browser&#039;];  You won&#039;t get this weird browser name, like, Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.7) Gecko/20040803 Firefox/0.9.3. You&#039;ll simply get: Firefox. Piece of cake. ?But using the print_r on that one&#039;ll show you what it has.

&quot;What is Name ? says:

Hello all ,
Issue 1.
is there any way to restrict user from entering some fix word using java script.

Issue 2.
How to Make Word Limit for textarea. Remember Word Limit not character limit.&quot;

Interesting.

Issue 1: Yes there is. But it&#039;s quite disturbing to use. Each and every keyup, do a regular expression on these fixed words. best would be to use the php, asp, or whatever language it is you use to filter out these words. But this will be done after posting. so maybe fire up the javascript after pressing the submit button, so that the user doesn&#039;t lose it&#039;s text. also, please people, remember, filtering using javascript alone is NOT enough. Javascript can easily be turned off by the browser, and can be directly edited using tools such as firebug. Javascript is to enhance &#039;Graphics&#039; and other pretty moving stuff, because people like pretty moving stuf... like woman love shiny stuff.

Issue 2: Yes there is a way. You&#039;ll be using javascript on this one, onsubmit of course. Now what you&#039;ll do is split on spaces, this&#039;ll give you the amount of words used. also, check if the last character is a space, because if it is, this doesn&#039;t count as a word now does it ;) Then simply check, if necessary report back to the user and return false, else return true. But again, check this in your php as well. 

If my english sucks, sorry. I&#039;m from Amsterdam The Netherlands :)</description>
		<content:encoded><![CDATA[<p>&quot;Benjamin says:</p>
<p>Are you freaking kidding? Next, are you going to ask if there&#8217;s a way to record people&#8217;s keypresses using php! F*** off!&quot;</p>
<p>Dude, there is. Using javascript you can record key presses using keycode.</p>
<p>&quot;Vasim Padhiyar says:</p>
<p>hello all,<br />
is there any function in php or javascript that<br />
gives me the details of user&#8217;s local computer harddrive info also with all folder and files in that drive .&quot;</p>
<p>Yes there is. But is depends, what do you want to achieve? if you want to upload, it&#8217;s quite simple, else yes, you need to create some sort of add on, to browse trough your files. like a toolbar or sum.</p>
<p>&quot;Eric says:</p>
<p>Great job, now i only need to know how to read other settings from the browser!&quot;</p>
<p>Interesting.<br />
Ok, some code for yah.</p>
<p>$_SERVER['HTTP_USER_AGENT'] Get the users browser. Now this alone is boring don&#8217;t you think? So why not try adding this one:<br />
$browserInfo= get_browser(null, true);<br />
print_r($browserInfo);</p>
<p>This&#8217;ll print the users browser, and what it is capable of. also, using this echo: echo $browserInfo['browser'];  You won&#8217;t get this weird browser name, like, Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.7) Gecko/20040803 Firefox/0.9.3. You&#8217;ll simply get: Firefox. Piece of cake. ?But using the print_r on that one&#8217;ll show you what it has.</p>
<p>&quot;What is Name ? says:</p>
<p>Hello all ,<br />
Issue 1.<br />
is there any way to restrict user from entering some fix word using java script.</p>
<p>Issue 2.<br />
How to Make Word Limit for textarea. Remember Word Limit not character limit.&quot;</p>
<p>Interesting.</p>
<p>Issue 1: Yes there is. But it&#8217;s quite disturbing to use. Each and every keyup, do a regular expression on these fixed words. best would be to use the php, asp, or whatever language it is you use to filter out these words. But this will be done after posting. so maybe fire up the javascript after pressing the submit button, so that the user doesn&#8217;t lose it&#8217;s text. also, please people, remember, filtering using javascript alone is NOT enough. Javascript can easily be turned off by the browser, and can be directly edited using tools such as firebug. Javascript is to enhance &#8216;Graphics&#8217; and other pretty moving stuff, because people like pretty moving stuf&#8230; like woman love shiny stuff.</p>
<p>Issue 2: Yes there is a way. You&#8217;ll be using javascript on this one, onsubmit of course. Now what you&#8217;ll do is split on spaces, this&#8217;ll give you the amount of words used. also, check if the last character is a space, because if it is, this doesn&#8217;t count as a word now does it <img src='http://www.theblog.ca/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' />  Then simply check, if necessary report back to the user and return false, else return true. But again, check this in your php as well. </p>
<p>If my english sucks, sorry. I&#8217;m from Amsterdam The Netherlands <img src='http://www.theblog.ca/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
	</item>
</channel>
</rss>

