Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/286.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/mongodb/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 登录时有多个用户_Php - Fatal编程技术网

Php 登录时有多个用户

Php 登录时有多个用户,php,Php,请问如何让每个用户登录到自己的区域? 我不想让用户加入社区 我希望他们登录到各自的区域 例如: 安娜=>site.com/anna/ mike=>site.com/mike/ 这就是我想要的,我不知道如何正确地做 需要'db.php'; 会议开始 if (isset($_POST['uname'])) { $uname = stripslashes($_REQUEST['uname']); $uname = mysqli_real_escape_string($con,$u

请问如何让每个用户登录到自己的区域? 我不想让用户加入社区 我希望他们登录到各自的区域 例如: 安娜=>site.com/anna/ mike=>site.com/mike/ 这就是我想要的,我不知道如何正确地做

需要'db.php'; 会议开始

if (isset($_POST['uname']))
{

    $uname = stripslashes($_REQUEST['uname']); 
    $uname = mysqli_real_escape_string($con,$uname); 

    $pwd = stripslashes($_REQUEST['pwd']);
    $pwd = mysqli_real_escape_string($con,$pwd);

    $query = "SELECT * FROM `users` WHERE uname='$uname' and pwd='$pwd'";
    $result = mysqli_query($con, $query) or die(mysql_error());

    $rows = mysqli_num_rows($result);

    if($rows == 1)
    {
        $_SESSION['uname'] = $uname;
        // I don't want to the users to join "thecommonplace"
        // I want them to be logged into their respective areas
        // Like for example : 
        // anna => site.com/anna/
        // mike => site.com/mike/
        // that's what I want and I have no idea how to do it correctly
        header("Location: site.com/thecommonplace/"); 
    }
        else
        {
        // no such user
        }
}

else // present login form
{

你差点就成功了!你所需要做的不是对链接进行硬编码,而是在链接后面添加$uname。你可以用手指把线粘在一起。 所以你的标题行是这样的

标题位置:site.com/$联塞特派团

请尝试以下位置:site.com/$uname/


标题位置:site.com/$uname/;难以置信的这么合乎逻辑。工作起来很有魅力。谢谢
require('db.php'); session_start();

if (isset($_POST['uname']))
{

$uname = stripslashes($_REQUEST['uname']); 
$uname = mysqli_real_escape_string($con,$uname); 

$pwd = stripslashes($_REQUEST['pwd']);
$pwd = mysqli_real_escape_string($con,$pwd);

$query = "SELECT * FROM `users` WHERE uname='$uname' and pwd='$pwd'";
$result = mysqli_query($con, $query) or die(mysql_error());

$rows = mysqli_num_rows($result);

if($rows == 1)
{
    $_SESSION['uname'] = $uname;
    // I don't want to the users to join "thecommonplace"
    // I want them to be logged into their respective areas
    // Like for example : 
    // anna => site.com/anna/
    // mike => site.com/mike/
    // that's what I want and I have no idea how to do it correctly
    header("Location: site.com/" . $uname); 
}
    else
    {
    // no such user
    }
}
  if($rows == 1)
        {
            $_SESSION['uname'] = $uname;
            header("Location: site.com/$uname/"); 
        }
            else
            {
            // no such user
            }