0

I want to pass parameters like www.example.com/user/1 where 1 is parameter which I normally would pass like www.example.com?user=1

I want to pass parameters like frameworks do. Also how will I fetch them in another page if I have multiple parameters? How would I know which parameter is which?

Can someone please guide me?

jww
  • 97,681
  • 90
  • 411
  • 885
Ndroid21
  • 400
  • 1
  • 8
  • 19
  • If i understand you want something like this? www.example.com?user_id=1&par=2. You can retrieve that with $_GET['param_name']. Then if you want www.example.com/id/1/par/2 you have to use .htacces file. Here is an [example](https://moz.com/blog/using-mod-rewrite-to-convert-dynamic-urls-to-seo-friendly-urls) – Sfili_81 Aug 29 '18 at 06:53
  • @Sfili_81 No I want URL like www.example.com/id/1/par/2 – Ndroid21 Aug 29 '18 at 06:54
  • 2
    Possible duplicate of [How to create friendly URL in php?](https://stackoverflow.com/questions/812571/how-to-create-friendly-url-in-php) – kidA Aug 29 '18 at 06:59
  • Possible duplicate of [Php get value of part of url](https://stackoverflow.com/questions/34601372/php-get-value-of-part-of-url) – Ranielle Canlas Aug 29 '18 at 07:06

2 Answers2

0

You can use URL Rewriting with .htaccess

Look at here: URL Rewriting

Delbo ar
  • 362
  • 2
  • 4
  • 12
0
  1. You can use Url Rewriting by updating your .htaccess file
  2. You can explode the URL to get the value of your parameter in URL Here
  3. You can use Routing class like AltoRouter

    $router = new AltoRouter();

    // map homepage $router->map( 'GET', '/', function() { require DIR . '/views/home.php'; });

    // map users details page $router->map( 'GET|POST', '/users/[i:id]/', function( $id ) { $user = ..... require DIR . '/views/user/details.php'; });

Ranielle Canlas
  • 624
  • 5
  • 19