I am developing a social networking site which, naturally, will have many registered users. I am trying to obtain the
For example, I have a page - profile_page.php which displays the profile page of the user. If a user manually types a users name in the browser, it would redirect them to the users page (if it exists).
I.e. at the moment when I go onto my own created profile, the url displays the following: http://localhost/profile_page.php
what I want and need it to display is http://localhost/profile_page.php?u=Freddy
or something similar.
What I have tried:
<?php
if (isset($_GET['u'])) {
$user_u_var = mysqli_real_escape_string($connect,$_GET['u']);
if (ctype_alnum($user_u_var)) {
//check if the user exists
$check = mysqli_query($connect, "SELECT username, first_name FROM users WHERE username='$user_u_var'");
if (mysqli_num_rows($check)===1) {
while ($get = mysqli_fetch_assoc($check)){
$user_u_var = $get['username'];
$fname = $get['first_name'];
}
}else { // refresh page
echo "<meta http-equiv=\"refresh\" content=\"0; url=http://localhost/www/index.php\">";
exit();
}
}
}
?>
I expected that writing the above code, would allow me to view the users name after the u= in the url, and allow me to search a users name and be directed to it, for example, if I search http://localhost/profile_page.php?u=Jason
in the url, I would be directed to the page for Jason - but neither are working, the url still remains as http://localhost/profile_page.php