PHP Create short address (var_export)

Source: Internet
Author: User
PHP Create short address (var_export)

Submit Page shorten.php:

?

?

?

?

Handling page show.php:

?

?

 
  '); fclose ($file); $output = ' Original Url: '. $url. '
Shorten ulr:http://www.yourdomain.com/api/s= '. $uif. ';} else $output = ' access error ';} else{$uif = Array_search ($url, $shortUrls); $output = ' Original URL: '. $url. '
Shorten ulr:http://www.yourdomain.com/api/s= '. $uif. ';} echo $output. '

Back ';}? >
?

?

Link page? functions.php

?

?

 0) $out-= POW ($base, $pad _up);} $out = sprintf ('%F ', $out); $out = substr ($out, 0, Strpos ($out, '. '));} else {//Digital number-->> alphabet Letter Codeif (is_numeric ($pad _up)) {$pad _up--;if ($pad _up > 0) $in + = PO W ($base, $pad _up);} $out = ""; for ($t = Floor (log ($in, $base)); $t >= 0; $t-) {$bcp = Bcpow ($base, $t), $a = floor ($in/$bcp)% $base; $out = $out. substr ($index, $a, 1); $in = $in-($a * $BC p);} $out = Strrev ($out); Reverse}return $out;}? >
?

?

Link page? shorturls.php

?

?

 
  
?

?

?

Principle: The submitted URL is stored in the array, and a unique key is generated, then the array is stored in the text, of course, you can also be stored in the database, this instance is stored in the text.

?

Explanation of some functions:

?

1. Array_search () function

?

Array_search (value,array,strict)

?

The Array_search () function, like In_array (), looks for a key value in the array. If the value is found, the key name of the matching element is returned. Returns False if it is not found.

?

2.?var_export ()? function

?

?

This function returns the structure information about the variable passed to the function, similar to Var_dump (), unlike the PHP code whose returned representation is valid.

You can return the representation of a variable by setting the second argument of the function to TRUE.

?

Compare Var_export () and Var_dump ().

?

?

?

Finally, accept the page? redirect.php

?

?

!--? phpinclude ' shorturls.php '; $uid = $_get[' uid ']; $addr = ($uid and array_key_exists ($ UID, $shortUrls))? $shortUrls [$uid]: '/'; header (' Location: ' $addr); ? 

This page needs to be combined with. htaccess or. waccess

?

?

rewriteengine on Rewriterule ^s= (. *) $/redirect.php?uid=$1 [r=301,l] 
?

?

?

?

Association:

php Create a short ID for creating a shorter IDs with Php-like Youtube or tinyurl?

?

?

If the problem, please leave a message ~

?

?

  • 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.