This article describes the implementation of the PHP short address conversion method. Share to everyone for your reference. The specific analysis is as follows:
From yesterday afternoon to now overturned one after another of the information storage scheme, from MySQL to add memory unrestricted file_get_contents, and then to the formatted input of the fscanf, finally chose a more mature and stable way to read the INI.
The entire main program has only two files zipurl.php, index.php
zipurl.php files are as follows:
Copy Code code as follows:
<?php
This file is used to convert URLs
Organize URLs
function Dealurl ($url)
{
if ($url [4]!= ': ') $url = ' http://'. $url;
return $url;
}
function Ranum ()
{
$str = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
$tmp = $str [Mt_rand (0,35)]. $str [Mt_rand (0,35)]. $str [Mt_rand (0,35)]. $str [Mt_rand (0,35)]. $str [Mt_rand (0,35)];
return $tmp;
}
Deposit Number
function Zipurl ($urls)
{
Check the number to heavy
$handle = fopen ("Url.tmp", "r+");
$array =parse_ini_file ("Url.tmp", true);
if (Array_search ($urls, $array)) return Array_search ($urls, $array);
$num =ranum ();
fprintf ($handle, "%s=%s\r", $num, $urls);
Fclose ($handle);
return $num;
}
function Main ()
{
if ($url =$_get[' url '])
{
$url =dealurl ($url);
$url =zipurl ($url);
echo "http://localhost/?". $url;
}
}
Main ();
?>
<meta charset= "Utf-8" >
<title>zip your url</title>
<link rel= "stylesheet" href= "Assets/css/amazeui.min.css" >
<div class= "Am-g" >
<div class= "Col-md-8 col-sm-centered" >
<form class= "Am-form" action= "zipurl.php" method= "Get" >
<fieldset class= "Am-form-set" >
<input type= "text" id= "url" name= "url" placeholder= "Enter the URL you want to convert" >
</fieldset>
<div><button type= "Submit" class= "am-btn am-btn-primary am-btn-block" > Conversion </button></div>
</form>
</div>
</div>
index.php files are as follows:
Copy Code code as follows:
<?php
Search number
Short Access Section
function Readfiles ($strs)
{
$array =parse_ini_file ("Url.tmp", true);
Var_dump ($array);
return $array [$strs];
}
function Main ()
{
Go to Module
if ($str =$_server[' query_string '])
Echo ' <script language= JavaScript ' >location.href= '. Readfiles ($str). ' "; </script> ';
}
Main ();
Statistics section
?>
<meta charset= "Utf-8" >
<title>zip your url</title>
<link rel= "stylesheet" href= "Assets/css/amazeui.min.css" >
<div class= "Am-g" >
<div class= "Col-md-8 col-sm-centered" >
<form class= "Am-form" action= "zipurl.php" method= "Get" >
<fieldset class= "Am-form-set" >
<input type= "text" id= "url" name= "url" placeholder= "Enter the URL you want to convert" >
</fieldset>
<button type= "Submit" class= "am-btn am-btn-primary am-btn-block" > Conversion </button>
</form>
</div>
</div>
Temporary file url.tmp:
Aaaaa=http://baidu.com
The effect is as shown in the following illustration:
I hope this article will help you with your PHP program design.