PHP short URL super simple code PHP reference URL code Baidu short URL short URL generation

WBOY
Release: 2016-07-29 08:53:21
Original
918 people have browsed it

PHP short URL super simple code
System environment:
php, apache2, linux
Operation to generate PHP short URL:
Copy the code to index.php and put it in a secondary file with only 1 character (such as u) as the folder name in the directory.
Add write permissions to this directory. To save trouble, just chmod 777 u (the root directory is also OK, you may need to change the code to avoid affecting other files)
The URL generation result:
Put http://www.heimaolianmeng.com/heimaoseojishu / becomes http://127.0.0.1/u/1
Principle of php generating short URL:
1. Get the URL to be shortened through form post
2. Put the URL in a javascript and write the file name Growth by numbers. The function of javascript is to jump to the specified url
Optimization:
If you can set a second-level domain name, just point the second-level domain name to that directory, and there is no need to enter an extra u/.
Code:
Code example:



Shorten URL


< ;body>
URL to be shortened: (must include protocol like http:// or https:// etc.)







< ;?php
if (isset($_POST['url'])) {
$origin = $_POST['url'];
if (strlen($origin) > 10) {
$filename = count(scandir ('.')) - 3; // strip php self . ..
file_put_contents($filename,
'

The above introduces the super simple code of PHP short URL, including short URL and PHP content. I hope it will be helpful to friends who are interested in PHP tutorials.

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!