douhuan5073 2016-02-01 22:11
浏览 17

如何根据用户获取URL或['u']

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

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 ETLCloud 处理json多层级问题
    • ¥15 matlab中使用gurobi时报错
    • ¥15 这个主板怎么能扩出一两个sata口
    • ¥15 不是,这到底错哪儿了😭
    • ¥15 2020长安杯与连接网探
    • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
    • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
    • ¥15 可见光定位matlab仿真
    • ¥15 arduino 四自由度机械臂
    • ¥15 wordpress 产品图片 GIF 没法显示