PHP ( Reading URL arguments ) [closed]
How to use username url in php !! I want to do like this when requesting page http://localhost/profile/superrcoder it has to show profile page of superrcoder example, in facebook, https://www.facebook.com/facebook shows facebook fan page
I dont hava any idea to implement it!
I'm using XAMPP in windows.
The simple way is to use a rewrite rule for Apache and parse it with PHP.
You have to enable mod_rewrite for your XAMPP installation.
Create .htaccess in the root of your localhost with the following content:
Options +FollowSymLinks
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php?uq=$1 [L,QSA]
Now, in the index.php as the last rewrite rule refers to, you should be able to do something like:
<?php
$url_parts = explode('/', $_GET['uq']);
var_dump($url_parts);
?>
The array dumped by PHP sould give you an idea.
It uses url rewriting to make the url look like that but normally it's passing information via $_GET. So the url has parameters and values such as username=example but is rewritten to look 'pretty'.
Have a look at mod_rewrite
Instead, I believe you should be using .htaccess
to cause the redirections, in conjunction with PHP's database abilities. For example:
profile.php
if (!empty($_GET['user'])) {
//Do some crazy database stuff to get the profile info or page.
}
.htaccess
RewriteRule ^(.*)$ /profile.php?user=$1
(Note the codes are incomplete, they are just examples)
精彩评论