<p> 1、关于PHP重定向</p><p> 方法一:header("Location: index.php");</p><p> 方法二:echo "<script>window.location ="$PHP_SELF";</script>";</p><p> 方法三:echo "<META HTTP-EQUIV="Refresh" CONTENT="0; URL=index.php">";</p><p> 2、获取访问者浏览器</p><code>function browse_infor()<br />{<br />$browser="";$browserver="";<br />$Browsers =array("Lynx","MOSAIC","AOL","Opera","JAVA","MacWeb","WebExplorer","OmniWeb");<br />$Agent = $GLOBALS["HTTP_USER_AGENT"];<br />for ($i=0; $i<=7; $i++)<br />{<br />if (strpos($Agent,$Browsers[$i]))<br />{<br />$browser = $Browsers[$i];<br />$browserver ="";<br />}<br />}<br />if (ereg("Mozilla",$Agent) && !ereg("MSIE",$Agent))<br />{<br />$temp =explode("(", $Agent); $Part=$temp[0];<br />$temp =explode("/", $Part); $browserver=$temp[1];<br />$temp =explode(" ",$browserver); $browserver=$temp[0];<br />$browserver =preg_replace("/([d.]+)/","1",$browserver);<br />$browserver = " $browserver";<br />$browser = "Netscape Navigator";<br />}<br />if (ereg("Mozilla",$Agent) && ereg("Opera",$Agent))<br />{<br />$temp =explode("(", $Agent); $Part=$temp[1];<br />$temp =explode(")", $Part); $browserver=$temp[1];<br />$temp =explode(" ",$browserver);$browserver=$temp[2];<br />$browserver =preg_replace("/([d.]+)/","1",$browserver);<br />$browserver = " $browserver";<br />$browser = "Opera";<br />}<br />if (ereg("Mozilla",$Agent) && ereg("MSIE",$Agent))<br />{<br />$temp = explode("(", $Agent); $Part=$temp[1];<br />$temp = explode(";",$Part); $Part=$temp[1];<br />$temp = explode(" ",$Part);$browserver=$temp[2];<br />$browserver =preg_replace("/([d.]+)/","1",$browserver);<br />$browserver = " $browserver";<br />$browser = "Internet Explorer";<br />}<br />if ($browser!="")<br />{<br />$browseinfo = "$browser$browserver";<br />}<br />else<br />{<br />$browseinfo = "Unknown";<br />}<br />return $browseinfo;<br />}<br />//调用方法$browser=browseinfo() ;直接返回结果</code><p> 3、获取访问者操作系统</p>
<p> </p>
<code>function osinfo() {<br />$os="";<br />$Agent = $GLOBALS["HTTP_USER_AGENT"];<br />if (eregi('win',$Agent) && strpos($Agent, '95')) {<br />$os="Windows 95";<br />}<br />elseif (eregi('win 9x',$Agent) && strpos($Agent, '4.90')) {<br />$os="Windows ME";<br />}<br />elseif (eregi('win',$Agent) && ereg('98',$Agent)) {<br />$os="Windows 98";<br />}<br />elseif (eregi('win',$Agent) && eregi('nt 5.0',$Agent)) {<br />$os="Windows 2000";<br />}<br />elseif (eregi('win',$Agent) && eregi('nt',$Agent)) {<br />$os="Windows NT";<br />}<br />elseif (eregi('win',$Agent) && eregi('nt 5.1',$Agent)) {<br />$os="Windows XP";<br />}<br />elseif (eregi('win',$Agent) && ereg('32',$Agent)) {<br />$os="Windows 32";<br />}<br />elseif (eregi('linux',$Agent)) {<br />$os="Linux";<br />}<br />elseif (eregi('unix',$Agent)) {<br />$os="Unix";<br />}<br />elseif (eregi('sun',$Agent) && eregi('os',$Agent)) {<br />$os="SunOS";<br />}<br />elseif (eregi('ibm',$Agent) && eregi('os',$Agent)) {<br />$os="IBM OS/2";<br />}<br />elseif (eregi('Mac',$Agent) && eregi('PC',$Agent)) {<br />$os="Macintosh";<br />}<br />elseif (eregi('PowerPC',$Agent)) {<br />$os="PowerPC";<br />}<br />elseif (eregi('AIX',$Agent)) {<br />$os="AIX";<br />}<br />elseif (eregi('HPUX',$Agent)) {<br />$os="HPUX";<br />}<br />elseif (eregi('NetBSD',$Agent)) {<br />$os="NetBSD";<br />}<br />elseif (eregi('BSD',$Agent)) {<br />$os="BSD";<br />}<br />elseif (ereg('OSF1',$Agent)) {<br />$os="OSF1";<br />}<br />elseif (ereg('IRIX',$Agent)) {<br />$os="IRIX";<br />}<br />elseif (eregi('FreeBSD',$Agent)) {<br />$os="FreeBSD";<br />}<br />if ($os=='') $os = "Unknown";<br />return $os;<br />}<br />//调用方法$os=os_infor() ;</code><p> 4、文件格式类</p>
<p> </p>
<code>$mime_types = array(<br />'gif' => 'image/gif',<br />'jpg' => 'image/jpeg',<br />'jpeg' => 'image/jpeg',<br />'jpe' => 'image/jpeg',<br />'bmp' => 'image/bmp',<br />'png' => 'image/png',<br />'tif' => 'image/tiff',<br />'tiff' => 'image/tiff',<br />'pict' => 'image/x-pict',<br />'pic' => 'image/x-pict',<br />'pct' => 'image/x-pict',<br />'tif' => 'image/tiff',<br />'tiff' => 'image/tiff',<br />'psd' => 'image/x-photoshop',<br />'swf' => 'application/x-shockwave-flash',<br />'js' => 'application/x-javascript',<br />'pdf' => 'application/pdf',<br />'ps' => 'application/postscript',<br />'eps' => 'application/postscript',<br />'ai' => 'application/postscript',<br />'wmf' => 'application/x-msmetafile',<br />'css' => 'text/css',<br />'htm' => 'text/html',<br />'html' => 'text/html',<br />'txt' => 'text/plain',<br />'xml' => 'text/xml',<br />'wml' => 'text/wml',<br />'wbmp' => 'image/vnd.wap.wbmp',<br />'mid' => 'audio/midi',<br />'wav' => 'audio/wav',<br />'mp3' => 'audio/mpeg',<br />'mp2' => 'audio/mpeg',<br />'avi' => 'video/x-msvideo',<br />'mpeg' => 'video/mpeg',<br />'mpg' => 'video/mpeg',<br />'qt' => 'video/quicktime',<br />'mov' => 'video/quicktime',<br />'lha' => 'application/x-lha',<br />'lzh' => 'application/x-lha',<br />'z' => 'application/x-compress',<br />'gtar' => 'application/x-gtar',<br />'gz' => 'application/x-gzip',<br />'gzip' => 'application/x-gzip',<br />'tgz' => 'application/x-gzip',<br />'tar' => 'application/x-tar',<br />'bz2' => 'application/bzip2',<br />'zip' => 'application/zip',<br />'arj' => 'application/x-arj',<br />'rar' => 'application/x-rar-compressed',<br />'hqx' => 'application/mac-binhex40',<br />'sit' => 'application/x-stuffit',<br />'bin' => 'application/x-macbinary',<br />'uu' => 'text/x-uuencode',<br />'uue' => 'text/x-uuencode',<br />'latex'=> 'application/x-latex',<br />'ltx' => 'application/x-latex',<br />'tcl' => 'application/x-tcl',<br />'pgp' => 'application/pgp',<br />'asc' => 'application/pgp',<br />'exe' => 'application/x-msdownload',<br />'doc' => 'application/msword',<br />'rtf' => 'application/rtf',<br />'xls' => 'application/vnd.ms-excel',<br />'ppt' => 'application/vnd.ms-powerpoint',<br />'mdb' => 'application/x-msaccess',<br />'wri' => 'application/x-mswrite',<br />);</code><p> 5、php生成excel文档</p></p><code><?<br />header("Content-type:application/vnd.ms-excel");<br />header("Content-Disposition:filename=test.xls");<br />echo "test1 ";<br />echo "test2 <br />";<br />echo "test1 ";<br />echo "test2 <br />";<br />echo "test1 ";<br />echo "test2 <br />";<br />echo "test1 ";<br />echo "test2 <br />";<br />echo "test1 ";<br />echo "test2 <br />";<br />echo "test1 ";<br />echo "test2 <br />";<br />?><br />//改动相应文件头就可以输出.doc .xls等文件格式了</code></p></p>