Accumulated experience, dedicated to PHP enthusiasts!!!
Last Update:2017-02-28
Source: Internet
Author: User
Enthusiasts have recently completed their hands on the project, relatively idle. Come here and turn around and share some of the skills you've accumulated.
1, about PHP redirection
Method One: Header ("Location:index.php");
Method Two: echo "<script>window.location =\" $PHP _self\ ";</script>";
Method Three: Echo "<meta http-equiv=\" refresh\ "content=\" 0; Url=index.php\ ">";
2. Get Visitor 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 (), return results directly
3. Get 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) && strpos ($Agent, ' 4.90 ')) {
$os = "Windows ME";
}
ElseIf (' Win ', $Agent) && ereg (' Eregi ', $Agent)) {
$os = "Windows 98";
}
ElseIf (eregi (' win ', $Agent) && eregi (' nt 5\.0 ', $Agent)) {
$os = "Windows 2000";
}
ElseIf (eregi (' win ', $Agent) && eregi (' NT ', $Agent)) {
$os = "Windows NT";
}
ElseIf (eregi (' win ', $Agent) && eregi (' nt 5\.1 ', $Agent)) {
$os = "Windows XP";
}
ElseIf (' Win ', $Agent) && ereg (' Eregi ', $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 class
$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. PHP generates Excel document
?
Header ("Content-type:application/vnd.ms-excel");
Header ("Content-disposition:filename=test.xls");
echo "Test1\t";
echo "test2\t\n";
echo "Test1\t";
echo "test2\t\n";
echo "Test1\t";
echo "test2\t\n";
echo "Test1\t";
echo "test2\t\n";
echo "Test1\t";
echo "test2\t\n";
echo "Test1\t";
echo "test2\t\n";
?>
Change the file header to output the. doc. xls file format
6, Time comparison problem
Give a simple example to illustrate: for example, a forum on the day posted posts with new pictures marked.
Method One:
$db->rows[$i][date] is the value of the DateTime field in the database.
$today =time ();
$theDay =date ("y-m-d h:i:s", $today -24*3600);
$newTag = $db->rows[$i][date]>= $theDay? " ': ";
Method Two:
$newTag = $db->rows[$i][date]>=date ("y-m-d 00:00:00")? ': ";
7, PHP in the operation of the database package
My example ..... See annex above!