开发者

PHP ( Reading URL arguments ) [closed]

开发者 https://www.devze.com 2023-04-03 06:48 出处:网络
It's difficult to te开发者_如何转开发ll what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical andcannot be reasonably answered in its current for
It's difficult to te开发者_如何转开发ll what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center. Closed 10 years ago.

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)

0

精彩评论

暂无评论...
验证码 换一张
取 消