How to get the number that comes after id
?
View link
Here it is
if (isset($_GET['id'])) {$id =$_GET['id']; } else{ exit("Вы зашил на страницу без параметра!");}
But does not work.
I need immeno
not
How to get the number that comes after id
?
View link
Here it is
if (isset($_GET['id'])) {$id =$_GET['id']; } else{ exit("Вы зашил на страницу без параметра!");}
But does not work.
I need immeno
not
$link = $_SERVER["REQUEST_URI"]; //получаем текущий uri if (isset($link])) { $link_id = substr($link, 13) //кол-во обрезаемых символов $id = $link_id; } else { exit("Вы зашил на страницу без параметра!"); }
Hey. Url needs to be parsed. You can try this way:
<?php $url = "http://lol.com/page.php/id1"; // парсим url $url_array = explode("/", trim($url, "/")); // узнаем длину строки $len = strlen($url_array[4]); // выбираем все значение строки, без первых двух символов (id) $id = substr($url_array[4], 2, $len); // смотрим результат print $id; ?>
It is also possible to bring all this into a separate function. I hope to be useful.
$e = explode("/", $_SERVER['REQUEST_URI']); echo $e[4];
the easiest way :)
Well, firstly, GET
parameters are passed after the sign?
In your case http://lol.com/page.php?id=1
I will propose another variant with regular expressions that will cover such cases as
id1?wall id1#mail
Well, and so on.
$re= "/\/id([0-9]++)/i"; preg_match_all($re, $url, $result); var_dump($result);
Like this:
$url = "http://lol.com/page.php?id=126"; $parsed_url = parse_url($url); preg_match("/^id=([0-9]+)/", $parsed_url['query'], $matches); var_dump(end($matches));
Source: https://ru.stackoverflow.com/questions/130549/
All Articles
$_GET
when you requesthttp://lol.com/page.php/id1
? Put print_r ($ _GET) at the beginning of the script; exit (); and give the answer here. - Sergiksexit();
nothing should be done. - Sergiks