PHP Short Address Conversion implementation Method _php skill

Source: Internet
Author: User
Tags button type file url

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.

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.