Php short address conversion Implementation Method

Source: Internet
Author: User
This article mainly introduces the php short address conversion implementation method, which involves the URL and string operation skills and has some reference value. For more information, see

This article mainly introduces the php short address conversion implementation method, which involves the URL and string operation skills and has some reference value. For more information, see

This article describes how to implement php short address conversion. Share it with you for your reference. The specific analysis is as follows:

From yesterday afternoon to now I overturned one information storage solution after another, from mysql to file_get_contents with unlimited memory, and then to formatting the input fscanf ,, finally, we chose a mature and stable method for reading ini.

The main program only has two files: zipurl. php and index. php.

The zipurl. php file is as follows:

The Code is as follows:

<? Php
// This file is used to convert the url
// Sort URLs
Function dealurl ($ url)
{
If ($ url [4]! = ':') $ Url = 'HTTP: // '. $ url;
Return $ url;
}
Function ranum ()
{
$ Str = "0123456789 abcdefghijklmnopqrstuvwxyz ";
$ 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;
}
// Save the number
Function zipurl ($ urls)
{
// Check the number for deduplication
$ 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 ();
?>

ZIP your URL





The index. php file is as follows:

The Code is as follows:

<? Php
// Check the ID
// Short address access part
Function readfiles ($ strs)
{
$ Array = parse_ini_file ("url. tmp", true );
Var_dump ($ array );
Return $ array [$ strs];
}
Function main ()
{
// Switch to the module
If ($ str = $ _ SERVER ['query _ string'])
Echo'

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.