-1

Is there any way in PHP to get a value from the URL. For example, if I have a folder called user and an index.php inside that folder. Then I navigate to mydomian.com/user/username

Can I get the 'username' value and respond to that with the index.php?

I've looked around and can't seem to find an answer, without using arguments inside the URL.

Tom
  • 2,543
  • 3
  • 21
  • 42
  • 5
    Possible duplicate of [Get the full URL in PHP](http://stackoverflow.com/questions/6768793/get-the-full-url-in-php) – Nathan Tuggy Nov 19 '15 at 02:16

2 Answers2

0

If you using httpd, and has rewrite turn on, try config your httpd as

rewritecond %{REQUEST_URI} ^/user/ [nc]
rewriterule ^/user/(.*)$ /user?username=$1 [r=301,ns]

You can put it into httpd.conf, or put it into some .htaccess file. And in your index.php, using

$_GET['username']

To get the username. Based on your question, guess you need understand lots of thing before this really works

pinkdawn
  • 1,023
  • 11
  • 20
0

I make a folder called user, put it a .htaccess of its own with:

RewriteRule ^(.*)$ index.php?username=$1 [L,QSA]

I then got the value username with:

$_GET['username'];

Now when I navigate to mywebsite.com/user/tom, it will output tom.

Tom
  • 2,543
  • 3
  • 21
  • 42