突出显示所选元素/从登录页面重定向用户

问题描述 投票:0回答:2

我正在登录时使用简单的插入/编辑页面,并且有一些我自己无法解决的问题。

1)enter image description here

就像上面的图像一样,当用户单击右侧列表中的一个时,它突出显示选定的列表,并在左侧窗体中预填充其中的数据。

$result = mysqli_query($con, "SELECT * FROM contacts") or die(mysqli_error($con));

while($row = mysqli_fetch_array($result)){
    $company = $row['eyo_company_name'];
    $id = $row['con_id'];
    $editLinks .= "\n\t<a href=\"edit.php?id=$id\">$company</a><br>";
}

这是我从数据库中取出列表的方式,但是我不知道如何在选定的$ company上添加b标记。

2)我有一个单独的登录页面,在插入/编辑页面之前,用户将被迫登录。如果将用户从插入页面定向到登录页面,则登录成功后将重定向到插入页面。如果从编辑页面,它将重定向到编辑页面。

session_start();
if(isset($_SESSION['8cd97832a4fe'])){

}
else{
    header("Location:login.php?ref=insert.php"); //on insert.php
    header("Location:login.php?ref=edit.php");   //on edit.php
}

我在插入和编辑php时具有此代码块,因此当用户被定向到登录页面时,它可以检测到用户的定向位置。

    if(isset($_POST['loginsubmit'])) {
    $username = trim($_POST['username']);
    $password = trim($_POST['password']);
    $ref = $GET_['ref'];

    if(($username == $username_good) && (password_verify($password, $pw_enc))){
        session_start();
        $_SESSION['8cd97832a4fe'] = session_id();
        if($ref == 'insert.php'){
            header("Location:insert.php");
        }
        elseif ($ref == 'edit.php'){
            header("Location:edit.php");
        }
        else {
            header("Location:index.php");
        }

这是我当前在我的login.php中拥有的内容,但这只会将我定向到index.php。

任何帮助将不胜感激,谢谢!

php mysql
2个回答
0
投票

如果您创建一个会话来保存链接,而重定向到登录页面标题功能,将不接受没有(urlencode()函数的参数),参数会更好。所以你的代码将是首先

session_start();


if(isset($_SESSION['8cd97832a4fe'])){
}
else{
$_SESSION['ref']=insert.php; // //on insert.php
$_SESSION['ref']=edit.php; // //on edit.php
    header("Location:login.php"); 
}

然后

  if(isset($_POST['loginsubmit'])) {
        $username = trim($_POST['username']);
        $password = trim($_POST['password']);


        if(($username == $username_good) && (password_verify($password, $pw_enc))){
            session_start();
$ref = $_SESSION['ref'];
            $_SESSION['8cd97832a4fe'] = session_id();
            if($ref == 'insert.php'){
                header("Location:insert.php");
            }
            elseif ($ref == 'edit.php'){
                header("Location:edit.php");
            }
            else {
                header("Location:index.php");
            }

0
投票

您的GET变量键入$ref = $GET_['ref'];而不是$_GET['ref']

第二观察,session_start()应该是脚本中任何代码之前的第一行。

第三观察,

if(isset($_SESSION['8cd97832a4fe'])){
  }
else{
  header("Location:login.php?ref=insert.php"); //on insert.php
  header("Location:login.php?ref=edit.php");   //on edit.php
}

您在else块上使用多个标题。

© www.soinside.com 2019 - 2024. All rights reserved.