Vote count:
0
I have url like this http://www.example.com/user/1 and i want get user id which is 1. When i try it with my code i get right id but my css style is not applied to the page. But when i try to get id from url http://www.example.com?profile.php?user=1 i can see style of my page. The code what i use in first example is:
$request = parse_url($_SERVER['REQUEST_URI']);
$path = $request["path"];
$result = rtrim(str_replace(basename($_SERVER['SCRIPT_NAME']), '', $path), '/');
$parts = $query = explode("/", $result);
$user = $parts[2];
$sql = "SELECT firstName, lastName FROM users WHERE id = ".$user." LIMIT 1";
$res = $con->query($sql);
$row = $res->fetch_assoc();
and where i try to get id for secuond example i use only $_GET method. Please help.
asked 12 secs ago
how to get value from url after /
Aucun commentaire:
Enregistrer un commentaire