Reputation: 437
I have the following URL creating dynamically "http://mxcounters.com/gorilla-crowd/?page_id=4994?company_id=11" i want to read company_id from it. as each time it will be changed coming from previous page: I have tried as follows but its showing empty variable
$company_id = $_GET['company_id'];
echo $company_id;
Upvotes: 1
Views: 42
Reputation: 437
I got the ID with another method that's work in my case perfectly
$rest = 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
$company_id = substr($rest, -2, 2);
I get the whole link in a variable and then get the last 2 characters from this string as above and worked fine
Upvotes: 0
Reputation: 8540
Your URL's query string is wrongly formatted. The query string parameters need to be separated by &
(&
when URL encoded) not ?
as in your example. As a result $_GET['company_id']
isn't getting set.
Your URL should look like:-
http://mxcounters.com/gorilla-crowd/?page_id=4994&company_id=11
Then $_GET['company_id']
should contain 11
as expected.
Upvotes: 1