Home > Article > Backend Development > PHP short URL super simple code PHP reference URL code Baidu short URL short URL generation
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: