0

I couldn't find much help while I was looking for my answer that's the reason for the question on here.

Basically I have this bit of code :

<a href="manage/10000' . $user["user_id"] . ' " class="user_grop">More Info</span></a>

now how is it possible to get what I am passing ?

Do I make a php file called manage.php ? if so what makes it so that it looks at manage.php ? and then get it through $_GET but how is it possible ?

I am not sure how to go about it so I would appreciate any of yours suggestions.

Thanks

dark_illusion_909099
  • 1,067
  • 2
  • 21
  • 41
  • 1
    If the code isn't yours and doesn't use a framework, look at the `.htaccess` file on the project base directory. There should be a rewrite containing that link. something like `RewriteRule ^manage/([0-9]+)$ /manage.php?user=$1` – Taha Paksu Oct 15 '16 at 20:18

4 Answers4

2

You need a routing-engine to manage that type of url.

There are many framework that include routing. The most used is Symfony http://symfony.com/doc/current/routing.html

Jacopo Brovida
  • 465
  • 4
  • 10
2

The general syntax would be as follows:

http://domain_name.com/script.php?parameter1=value&parameter2=value

In your case you would have the following assuming that your parameter is user_id:

<a href="manage.php?user_id='.$user["user_id"].'" class="user_grop">More Info</span></a>

In PHP you would use $_GET['user_id'] to fetch the passed value

$userID = $_GET['user_id'];

By including these lines in .htaccess

RewriteEngine On
RewriteRule ^manage\/([0-9]+)$ manage.php?user_id=$1

You could reach the same page with the following syntax:

http://domainname/manage/2313
Cristofor
  • 2,077
  • 2
  • 15
  • 23
2

Your problem can have two possible solutions:

  1. By creating manage.php file and passing query string to it.

Your code for the link will like this:

<a href="manage.php?user_id=' . $user["user_id"] . ' " class="user_grop">More Info</span></a>

Now on manage.php page, you can access user_id like this:

<?php $user_id = $_GET["user_id"]; ?>
  1. Using .htaccess, create .htaccess file and put the code below in it. .htaccess file must be placed in same dir where your index.php file is.

    <IfModule mod_rewrite.c> RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*)$ index.php?/$1 [L] </IfModule>

Now you can access your query strings on index.php file using $_SERVER['REQUEST_URI'] global variable.

<a href="manage/10000/' . $user["user_id"] . ' " class="user_grop">More Info</span></a>

Your link to access page must look like above note the / after 10000 else user_id will get merge with 10000

Chatting session was performed for the question, view chat transcript here

Community
  • 1
  • 1
Web Dev
  • 306
  • 3
  • 5
1

If you mean to say that you need to route to a different php file manage.php and get the passed variable from the previous page then either you can modify the link to

"manage.php?val=10000".$user["user_id"]

and then use $_GET to get the passed variable

Or else you can keep the same url use .htaccess to route your request to manage.php?val=$1

or else in frameworks like codeigniter you have routes file where you can define your route.

Jibin Mathew
  • 4,816
  • 4
  • 40
  • 68