php伪造ip 【转-未测试】

作者:互联网观察 发布时间:Nov 29, 2009 分类:互联网观察

PHP代码
  1. <?php   
  2. $address = 'http://www.xmcase.com/dd.php';//地址,必须有http://之类   
  3. $myip = '.210.3210.34.0.13';   
  4.   
  5. ob_start();   
  6. $mtime = explode(' ', microtime());   
  7. $starttime = $mtime[1] + $mtime[0];   
  8.   
  9. $onoff = (function_exists('ini_get')) ? ini_get('register_globals') : get_cfg_var('register_globals');   
  10.   
  11. if($onoff != 1) {   
  12.         @extract($_POST, EXTR_SKIP);   
  13.         @extract($_GET, EXTR_SKIP);   
  14. }   
  15.   
  16. $self = $_SERVER['PHP_SELF'];   
  17. $myaddress = 'http://'.$_SERVER['HTTP_HOST'].$self;   
  18.   
  19. $comm = '';   
  20.   
  21. if(isset($url) && $url) {   
  22.         $url = str_replace($address, '', $url);   
  23. }   
  24. /*  
  25. foreach($_POST as $key => $val) {  
  26.         if($comm == '') {  
  27.                 $comm = $key.'='.rawurlencode($val);  
  28.         } else {  
  29.                 $comm = $comm.'&'.$key.'='.rawurlencode($val);  
  30.         }  
  31. }  
  32. */  
  33. $pcomm = '';   
  34. foreach($_POST as $key => $val) {   
  35.         if($pcomm == '') {   
  36.                 $pcomm .= $key.''.urlencode($val);   
  37.         } else {   
  38.                 $pcomm .= $pcomm.'&'.$key.'='.urlencode($val);   
  39.         }   
  40. }   
  41.   
  42. foreach($_GET as $key => $val) {   
  43.         if($key != 'url') {   
  44.                 if($comm == '') {   
  45.                         $comm = $key.'='.rawurlencode($val);   
  46.                 } else {   
  47.                         $comm = $comm.'&'.$key.'='.rawurlencode($val);   
  48.                 }   
  49.         }   
  50. }   
  51.   
  52. if(!$url) {   
  53.         $url = $address;   
  54. } else {   
  55.         $url = $address.$url;   
  56.         if($comm) {   
  57.                 if(strstr($url,'?')) {   
  58.                         $url = $url.'&'.$comm;   
  59.                 } else {   
  60.                         $url = $url.'?'.$comm;   
  61.                 }   
  62.         }   
  63. }   
  64.   
  65. if($url) {   
  66.         $cookies= '';   
  67.         if(count($_COOKIE)) {   
  68.                 foreach($_COOKIE as $cookie_name => $cookie_var) {   
  69.                         $cookies .= $cookies != '' ? '; '.$cookie_name.'='.$cookie_var : $cookie_name.'='.$cookie_var;   
  70.                 }   
  71.         }   
  72.   
  73.         $temp = @parse_url($url);   
  74.         $temp['port'] = isset($temp['port']) ? $temp['port'] : 80;   
  75.         $temp['path'] = isset($temp['path']) ? $temp['path'] : '/';   
  76.         $temp['file'] = substr($temp['path'], strrpos($temp['path'], '/')+1);   
  77.         $temp['dir'] = substr($temp['path'], 0, strrpos($temp['path'], '/'));   
  78.         $temp['base'] = $temp['scheme'].'://'.$temp['host'].($temp['port'] != 80 ? ':'.$temp['port'] : '').$temp['dir'];   
  79.         $temp['prev_dir'] = $temp['path'] != '/' ? substr($temp['base'], 0, strrpos($temp['base'], '/')+1) : $temp['base'].'/';   
  80.         $fp = @fsockopen($temp['host'], $temp['port'], $errno, $errstr, 30);    
  81.         if($fp) {   
  82.                 if($_SERVER['REQUEST_METHOD'] != 'POST') {   
  83.                         @fputs($fp, "GET $temp[path]?$temp[query] HTTP/1.1\r\n");   
  84.                 } else {   
  85.                         @fputs($fp, "POST $temp[path]?$temp[query] HTTP/1.1\r\n");   
  86.                 }   
  87.                 @fputs($fp, "Host: $temp[host]\r\n");    
  88.                 @fputs($fp, "Accept: */*\r\n");    
  89.                   @fputs($fp, "Referer: [url]http://$temp[url][host]/\r\n");   
  90.                 @fputs($fp, "Cookie: $cookies\r\n");    
  91.                 @fputs($fp, "User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1)\r\n");    
  92.                 @fputs($fp, "via: 1.1 JEJE1:80 (squid/2.5.STABLE4-NT-CVS)\r\n");   
  93.                 @fputs($fp, "X-Forwarded-For: $myip\r\n");   
  94.                 if($_SERVER['REQUEST_METHOD'] == 'POST') {   
  95.                         @fputs($fp, "Content-Type: application/x-www-form-urlencoded\r\n");   
  96.                         @fputs($fp, "Content-Length: ".strlen($pcomm)."\r\n\r\n");   
  97.                         @fputs($fp, $pcomm);   
  98.                 }   
  99.                 @fputs($fp, "Connection: Close\r\n\r\n");   
  100.   
  101.                 while($str = @fread($fp, 4096)) {   
  102.   
  103.                         if($str != "\r\n" && preg_match_all("#set-cookie:([^\r\n]*)#i", $str, $matches)) {   
  104.                                 foreach($matches[1] as $cookie_info) {   
  105.                                         preg_match('#^\s*([^=;,\s]*)=?([^;,\s]*)#', $cookie_info, $match) && list(, $name, $value) = $match;   
  106.                                         preg_match('#;\s*expires\s*=([^;]*)#i', $cookie_info, $match) && list(, $expires) = $match;   
  107.                                         $expires = isset($expires) ? strtotime($expires) : false;   
  108.                                         $expires = (!is_numeric($expires) || time() > $expires) ? false : $expires;   
  109.                                         setcookie($name, $value, $expires);   
  110.                                 }   
  111.                                 $str = str_replace($matches[0], '', $str);   
  112.                         }   
  113.                            
  114.                         $Content .= $str;   
  115.                 }   
  116.                 @fclose($fp);   
  117.                 if(strpos($Content, 'Content-Type: text/html')) {   
  118.                         $Content = substr($Content, strpos($Content, 'Content-Type: text/html')+33);   
  119.                 } else {   
  120.                         $Content = substr($Content, strpos($Content, chr(0x0d).chr(0x0a).chr(0x0d).chr(0x0a))+4);   
  121.                 }   
  122.                    
  123.                 $Content = str_replace(' href="',' href="'.$myaddress.'?url=',$Content);   
  124.                 $Content = str_replace(' href=\'',' href=\''.$myaddress.'?url=',$Content);   
  125.                 $Content = str_replace(' src="',' src="'.$myaddress.'?url=',$Content);   
  126.                 $Content = str_replace(' src=\'',' src=\''.$myaddress.'?url=',$Content);   
  127.                 $Content = str_replace(' src=image',' src="'.$myaddress.'?url=image',$Content);   
  128.                 $Content = str_replace(' src=customavatars/',' src='.$myaddress.'?url=customavatars/',$Content);   
  129.                 $Content = str_replace(' action="',' action="http://oem.taihainet.com/2008jd/',$Content);   
  130.                 $Content = str_replace(' url("',' url("'.$myaddress.'?url=',$Content);   
  131.                 $Content = str_replace('target="saves"',"",$Content);  
  132.                 $Content = str_replace(' background="',' background="'.$myaddress.'?url=',$Content);   
  133.                 $Content = str_replace(' url(\'',' url(\''.$myaddress.'?url=',$Content);   
  134.                 $Content = str_replace($myaddress.'?url=javascript:','javascript:',$Content);   
  135.                 $Content = str_replace(';url=',';url='.$myaddress.'?url=',$Content);   
  136.                    
  137.                 echo $Content;   
  138.         }   
  139. }   
  140.   
  141. ?>   

.net程序链接mysql数据库【原创】

作者:互联网观察 发布时间:Nov 29, 2009 分类:互联网观察

.net程序主要使用微软自家的sql2005 或者sql2008 或更早些的sql2000.使用内置的ado.net就可以针对这些数据库进行链接。

【mysql】

MySQL是一个小型关系型数据库管理系统,开发者为瑞典MySQLAB公司,在2008年1月16号被Sun公司收购。MySQL被广泛地应用在Internet上的中小型网站中。由于其体积小、速度快、总体拥有成本低,尤其是开放源码这一特点,许多中小型网站为了降低网站总体拥有成本而选择了MySQL作为网站数据库。

 

一些应用要使用mysql数据库。好的。如何使用.net程序连接到mysql数据库。

mysql提供了net程序链接数据库的的dll文件。下载地址:http://dev.mysql.com/downloads/connector/net/6.2.html

最新版本 6.2.1.

使用方法:引用dll后引用命名空间。之后可以使用一个MySqlHelper类来进行操作,就像使用net企业库一样简单。

【提示】最新版本的6.2.1已经加入了.net Entity Framework Entity 的支持。相信以后可以更方便的操作mysql数据库。

 

详细使用文档可以查看.net 使用 mysql 的 在先文档(英文):

http://dev.mysql.com/doc/refman/5.1/en/connector-net.html

 

 

彻底解决Html工具HtmlAgilityPack 中文乱码问题

作者:互联网观察 发布时间:Nov 23, 2009 分类:互联网观察

对于HtmlAgilityPack,修改HtmlWeb.cs的如下方法(红色为修改代码):

        private HttpStatusCode Get(Uri uri, string method, string path, HtmlDocument doc)         {             string cachePath = null;             HttpWebRequest req;             bool oldFile = false;

            req = WebRequest.Create(uri) as HttpWebRequest;             req.Method = method;

            _fromCache = false;             _requestDuration = 0;             int tc = Environment.TickCount;             if (UsingCache)             {                 cachePath = GetCachePath(req.RequestUri);                 if (File.Exists(cachePath))                 {                     req.IfModifiedSince = File.GetLastAccessTime(cachePath);                     oldFile = true;                 }             }

            if (_cacheOnly)             {                 if (!File.Exists(cachePath))                 {                     throw new HtmlWebException("File was not found at cache path: '" + cachePath + "'");                 }

                if (path != null)                 {                     IOLibrary.CopyAlways(cachePath, path);                     // touch the file                     File.SetLastWriteTime(path, File.GetLastWriteTime(cachePath));                 }                 _fromCache = true;                 return HttpStatusCode.NotModified;             }

            if (_useCookies)             {                 req.CookieContainer = new CookieContainer();             }

            if (PreRequest != null)             {                 // allow our user to change the request at will                 if (!PreRequest(req))                 {                     return HttpStatusCode.ResetContent;                 }

                // dump cookie //                if (_useCookies) //                { //                    foreach(Cookie cookie in req.CookieContainer.GetCookies(req.RequestUri)) //                    { //                        HtmlLibrary.Trace("Cookie " + cookie.Name + "=" + cookie.Value + " path=" + cookie.Path + " domain=" + cookie.Domain); //                    } //                }             }

            HttpWebResponse resp;

            try             {                 resp = req.GetResponse() as HttpWebResponse;             }             catch (WebException we)             {                 _requestDuration = Environment.TickCount - tc;                 resp = (HttpWebResponse)we.Response;                 if (resp == null)                 {                     if (oldFile)                     {                         if (path != null)                         {                             IOLibrary.CopyAlways(cachePath, path);                             // touch the file                             File.SetLastWriteTime(path, File.GetLastWriteTime(cachePath));                         }                         return HttpStatusCode.NotModified;                     }                     throw;                 }             }             catch(Exception)             {                 _requestDuration = Environment.TickCount - tc;                 throw;             }

            // allow our user to get some info from the response             if (PostResponse != null)             {                 PostResponse(req, resp);             }

            _requestDuration = Environment.TickCount - tc;             _responseUri = resp.ResponseUri;             bool html = IsHtmlContent(resp.ContentType);             System.Text.Encoding respenc;

            if ((resp.ContentEncoding != null) && (resp.ContentEncoding.Length>0))             {                 respenc = System.Text.Encoding.GetEncoding(resp.ContentEncoding);             }             else if ((resp.CharacterSet != null) && (resp.CharacterSet.Length > 0))//根据Content-Type中获取的charset             {                 if (string.Compare(resp.CharacterSet, "ISO-8859-1", true, System.Globalization.CultureInfo.InvariantCulture) == 0)                     respenc = System.Text.Encoding.GetEncoding("GB2312");                 else                     respenc = System.Text.Encoding.GetEncoding(resp.CharacterSet);             }             else             {                 respenc = System.Text.Encoding.GetEncoding("GB2312");             }

            if (resp.StatusCode == HttpStatusCode.NotModified)             {                 if (UsingCache)                 {                     _fromCache = true;                     if (path != null)                     {                         IOLibrary.CopyAlways(cachePath, path);                         // touch the file                         File.SetLastWriteTime(path, File.GetLastWriteTime(cachePath));                     }                     return resp.StatusCode;                 }                 else                 {                     // this should never happen...                     throw new HtmlWebException("Server has send a NotModifed code, without cache enabled.");                 }             }             Stream s = resp.GetResponseStream();             if (s != null)             {                 if (UsingCache)                 {                     // NOTE: LastModified does not contain milliseconds, so we remove them to the file                     SaveStream(s, cachePath, RemoveMilliseconds(resp.LastModified), _streamBufferSize);

                    // save headers                     SaveCacheHeaders(req.RequestUri, resp);

                    if (path != null)                     {                         // copy and touch the file                         IOLibrary.CopyAlways(cachePath, path);                         File.SetLastWriteTime(path, File.GetLastWriteTime(cachePath));                     }                 }                 else                 {                     // try to work in-memory                     if ((doc != null) && (html))                     {                         if (respenc != null)                         {                             doc.Load(s, respenc);                         }                         else                         {                             doc.Load(s, true);                         }                     }                 }                 resp.Close();             }             return resp.StatusCode;         }

说实话。dedecms的默认模板从来没有一个精品。

作者:互联网观察 发布时间:Nov 7, 2009 分类:互联网观察

说实话。dedecms的默认模板从来没有一个精品。

我很喜欢dedecms 认为他很好。很值得尊敬。

我是一个程序员。当然自己也开发模板。插件。接触过很多开源软件。

要说的是,和一些开源软件相比(国外),dedecms的模板,包括后台。都很粗放。尽管很实用。但不的不说真的很粗放。

希望官方下一个版本的模板本着。 1.简洁,css优化的非常到位,非常简洁。现在的css好几百k。已经很庞大了。 2.精致,模板的好和不好在细微处最能展现。一些微小的细节,甚至包括字号大小,文字位置。都可以体现出美感! 3.大众,尽量少的特效,这样很有利于二次开发。 以上几点只是希望。毕竟dedecms是开源的。我们不能对他要求太高!

dedecms加油!

京ICP证030173号 new