Some of the experience accumulated in PHP

Source: Internet
Author: User
Tags ereg explode flock rar zip gtar

1, about PHP redirection

Code fragment
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
Code fragment
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

Code fragment
function Osinfo () {
$os = "";
$Agent = $GLOBALS ["Http_user_agent"];

4. File Format class


Code fragment
$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 ',


Reading file functions

Code fragment
function ReadFromFile ($file _name) {
if (file_exists ($file _name)) {
$filenum =fopen ($file _name, "R");
Flock ($filenum, LOCK_EX);
$file _data=fread ($filenum, FileSize ($file _name));
Rewind ($filenum);
Fclose ($filenum);
return $file _data;
}
}
Write to a file function

Code fragment
function WriteToFile ($file _name, $data, $method = "W") {
$filenum =fopen ($file _name, $method);
Flock ($filenum, LOCK_EX);
$file _data=fwrite ($filenum, $data);
Fclose ($filenum);
return $file _data;
}
Page Quick Turn
Code fragment
function Turntopage ($url = "index.php", $info = "page shift ...", $second =2) {
Print "Print "<meta http-equiv=" Refresh "content=" $second; url= $url ">n";
Print "<style type=" text/css ">n<!--n";
Print "TD {Font-family:" Verdana "," Arial "; Font-size:12px}n";
Print "A {COLOR: #000000; Text-decoration:none}n ";
print "-->n</style>n";
print "Print "<table width=" 100% "border=" 0 "align=" center ">n";
print "<tr>n";
Print "<td height=" ">&nbsp;</td>n";
print "</tr>n";
print "<tr>n";
Print "&LT;TD align=" center ">n";
Print "<table width=" 60% "border=" 0 "cellpadding=" 8 "bgcolor=" #AA9FFF ">n";
print "<tr>n";
Print "<td height=" align= "Center" > page turn to hint information </td>n ";
print "</tr>n";
print "<tr>n";
Print "&LT;TD align=" center "> $info </td>n";
print "</tr>n";
print "<tr>n";
Print "&LT;TD align=" center ">n";
Print "<a href=" $url > if your browser does not support automatic jump, please click here </a></td>n ";
print "</tr>n";
print "</table></td>n";
print "</tr>n";
print "<tr>n";
Print "<td height=" ">&nbsp;</td>n";
print "</tr>n";
print "</table>n";
print "</body>nExit
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.