Several php skills. 1. PHP redirection Method 1: header (Location: index. php); Method 2: echoscriptwindow. location $ PHP_SELF; script; Method 3: echoMETAHTTP-EQUIVRefreshCONTENT 1. PHP redirection
Method 1: header ("Location: index. php ");
Method 2: echo "script window. location =" $ PHP_SELF "; script";
Method 3: echo" ";
2. obtain the visitor's browser
Function browse_infor ()
{
$ Browser = ""; $ browserver = "";
$ Browsers = array ("Lynx", "MOSAIC", "AOL", "Opera", "JAVA", "MacWeb", "WebExplorer", "OmniWeb ");
$ Agent = $ GLOBALS ["HTTP_USER_AGENT"];
For ($ I = 0; $ I <= 7; $ I ++)
{
If (strpos ($ Agent, $ Browsers [$ I])
{
$ Browser = $ Browsers [$ I];
$ Browserver = "";
}
}
If (ereg ("Mozilla", $ Agent )&&! Ereg ("MSIE", $ Agent ))
{
$ Temp = explode ("(", $ Agent); $ Part = $ temp [0];
$ Temp = explode ("/", $ Part); $ browserver = $ temp [1];
$ Temp = explode ("", $ browserver); $ browserver = $ temp [0];
$ Browserver = preg_replace ("/([d.] +)/", "1", $ browserver );
$ Browserver = "$ browserver ";
$ Browser = "Netscape Navigator ";
}
If (ereg ("Mozilla", $ Agent) & ereg ("Opera", $ Agent ))
{
$ Temp = explode ("(", $ Agent); $ Part = $ temp [1];
$ Temp = explode (")", $ Part); $ browserver = $ temp [1];
$ Temp = explode ("", $ browserver); $ browserver = $ temp [2];
$ Browserver = preg_replace ("/([d.] +)/", "1", $ browserver );
$ Browserver = "$ browserver ";
$ Browser = "Opera ";
}
If (ereg ("Mozilla", $ Agent) & ereg ("MSIE", $ Agent ))
{
$ Temp = explode ("(", $ Agent); $ Part = $ temp [1];
$ Temp = explode (";", $ Part); $ Part = $ temp [1];
$ Temp = explode ("", $ Part); $ browserver = $ temp [2];
$ Browserver = preg_replace ("/([d.] +)/", "1", $ browserver );
$ Browserver = "$ browserver ";
$ Browser = "Internet Explorer ";
}
If ($ browser! = "")
{
$ Browseinfo = "$ browser $ browserver ";
}
Else
{
$ Browseinfo = "Unknown ";
}
Return $ browseinfo;
}
// Call method $ browser = browseinfo (); directly return the result
3. obtain the visitor's operating system
Function osinfo (){
$ OS = "";
$ Agent = $ GLOBALS ["HTTP_USER_AGENT"];
If (eregi (win, $ Agent) & strpos ($ Agent, 95 )){
$ OS = "Windows 95 ";
}
Elseif (eregi (win 9x, $ Agent) & amp; strpos ($ Agent, 4.90 )){
$ OS = "Windows ME ";
}
Elseif (eregi (win, $ Agent) & ereg (98, $ Agent )){
$ OS = "Windows 98 ";
}
Elseif (eregi (win, $ Agent) & eregi (NNT 5.0, $ Agent )){
$ OS = "Windows 2000 ";
}
Elseif (eregi (win, $ Agent) & eregi (nt, $ Agent )){
$ OS = "Windows NT ";
}
Elseif (eregi (win, $ Agent) & eregi (NNT 5.1, $ Agent )){
$ OS = "Windows XP ";
}
Elseif (eregi (win, $ Agent) & ereg (32, $ Agent )){
$ OS = "Windows 32 ";
}
Elseif (eregi (linux, $ Agent )){
$ OS = "Linux ";
}
Elseif (eregi (unix, $ Agent )){
$ OS = "Unix ";
}
Elseif (eregi (sun, $ Agent) & eregi (OS, $ Agent )){
$ OS = "SunOS ";
}
Elseif (eregi (ibm, $ Agent) & eregi (OS, $ Agent )){
$ OS = "ibm OS/2 ";
}
Elseif (eregi (Mac, $ Agent) & eregi (PC, $ Agent )){
$ OS = "Macintosh ";
}
Elseif (eregi (PowerPC, $ Agent )){
$ OS = "PowerPC ";
}
Elseif (eregi (AIX, $ Agent )){
$ OS = "AIX ";
}
Elseif (eregi (HPUX, $ Agent )){
$ OS = "HPUX ";
}
Elseif (eregi (NetBSD, $ Agent )){
$ OS = "NetBSD ";
}
Elseif (eregi (BSD, $ Agent )){
$ OS = "BSD ";
}
Elseif (ereg (OSF1, $ Agent )){
$ OS = "OSF1 ";
}
Elseif (ereg (IRIX, $ Agent )){
$ OS = "IRIX ";
}
Elseif (eregi (FreeBSD, $ Agent )){
$ OS = "FreeBSD ";
}
If ($ OS =) $ OS = "Unknown ";
Return $ OS;
}
// Call method $ OS = OS _infor ();
4. file format
$ Mime_types = array (
Gif => image/gif,
Jpg => image/jpeg,
Jpeg => image/jpeg,
Jpe => image/jpeg,
Bmp => image/bmp,
Png => image/png,
Tif => image/tiff,
Tiff => image/tiff,
Pict => image/x-pict,
Pic => image/x-pict,
Pct => image/x-pict,
Tif => image/tiff,
Tiff => image/tiff,
Psd => image/x-photoshop,
Swf => application/x-shockwave-flash,
Js => application/x-javascript,
Pdf => application/pdf,
Ps => application/postscript,
Eps => application/postscript,
Ai => application/postscript,
Wmf => application/x-msmetafile,
Css => text/css,
Htm => text/html,
Html => text/html,
Txt => text/plain,
Xml => text/xml,
Wml => text/wml,
Wbmp => image/vnd. wap. wbmp,
Mid => audio/midi,
Wav => audio/wav,
Mp3 => audio/mpeg,
Mp2 => audio/mpeg,
Avi => video/x-msvideo,
Mpeg => video/mpeg,
Mpg => video/mpeg,
Qt => video/quicktime,
Mov => video/quicktime,
Lha => application/x-lha,
Lzh => application/x-lha,
Z => application/x-compress,
Gtar => application/x-gtar,
Gz => application/x-gzip,
Gzip => application/x-gzip,
Tgz => application/x-gzip,
Tar => application/x-tar,
Bz2 => application/bzip2,
Zip => application/zip,
Arj => application/x-arj,
Rar => application/x-rar-compressed,
Hqx => application/mac-binhex40,
Sit => application/x-stuffit,
Bin => application/x-macbinary,
Uu => text/x-uuencode,
Uue => text/x-uuencode,
Latex => application/x-latex,
Ltx => application/x-latex,
Tcl => application/x-tcl,
Pgp => application/pgp,
Asc => application/pgp,
Exe => application/x-msdownload,
Doc => application/msword,
Rtf => application/rtf,
Xls => application/vnd. ms-excel,
Ppt => application/vnd. ms-powerpoint,
Mdb => application/x-msaccess,
Wri => application/x-mswrite,
);
5. generate an excel file in php
Header ("Content-type: application/vnd. ms-excel ");
Header ("Content-Disposition: filename=test.xls ");
Echo "test1 ";
Echo "test2 ";
Echo "test1 ";
Echo "test2 ";
Echo "test1 ";
Echo "test2 ";
Echo "test1 ";
Echo "test2 ";
Echo "test1 ";
Echo "test2 ";
Echo "test1 ";
Echo "test2 ";
?>
// You can change the corresponding file header to export file formats such as .doc. xls.
Restore Method 1: header ("Location: index. php "); Method 2: echo" scriptwindow. location = "$ PHP_SELF";/script "; Method 3: echo" META HTTP-EQUIV = "Refresh" CONTENT...