当你在发送邮件时,你或许很想知道该邮件是否被对方已阅读。这里有段非常有趣的代码片段能够显示对方ip地址记录阅读的实际日期和时间。
1234567891011121314151617181920212223242526272829303132333435363738394041 | <? error_reporting (0); Header( "Content-Type: image/jpeg" ); //Get IP if (! empty ( $_SERVER [ 'HTTP_CLIENT_IP' ])) {
$ip = $_SERVER [ 'HTTP_CLIENT_IP' ]; } elseif (! empty ( $_SERVER [ 'HTTP_X_FORWARDED_FOR' ])) {
$ip = $_SERVER [ 'HTTP_X_FORWARDED_FOR' ]; } else {
$ip = $_SERVER [ 'REMOTE_ADDR' ]; } //Time $actual_time = time(); $actual_day = date ( 'Y.m.d' , $actual_time ); $actual_day_chart = date ( 'd/m/y' , $actual_time ); $actual_hour = date ( 'H:i:s' , $actual_time ); //GET Browser $browser = $_SERVER [ 'HTTP_USER_AGENT' ];
//LOG $myFile = "log.txt" ; $fh = fopen ( $myFile , 'a+' ); $stringData = $actual_day . ' ' . $actual_hour . ' ' . $ip . ' ' . $browser . ' ' . "\r\n" ; fwrite( $fh , $stringData ); fclose( $fh ); //Generate Image (Es. dimesion is 1x1) $newimage = ImageCreate(1,1); $grigio = ImageColorAllocate( $newimage ,255,255,255); ImageJPEG( $newimage ); ImageDestroy( $newimage );
?> |
源码
二、从网友中提取关键字一段伟大的代码片段能够轻松的从网页中提取关键字。
12345678910 | $meta = get_meta_tags( 'http://www.emoticode.net/' ); $keyWords = $meta [ 'keywords' ]; // Split keywords $keywords = explode ( ',' , $keywords ); // Trim them $keywords = array_map ( 'trim' , $keywords ); // Remove empty values $keywords = array_filter ( $keywords ); PRint_r( $keywords ); |
源码
三、查找页面上的所有链接使用DOM,你可以轻松从任何页面上抓取链接,代码示例如下:
1234567891011121314 | $html = file_get_contents ( 'http://www.example.com' ); $dom = new DOMDocument(); @ $dom ->loaDHTML( $html ); / |