被重定向到一页

时间:2018-04-12 00:37:31

标签: php html sql

我的目标是将用户重定向到他最初按下登录按钮并输入用户名和密码时的页面。到目前为止,我没有遇到任何问题。但是,如果我按下查看更多按钮,以便我被重定向到singleproduct.php,然后从浏览器返回到search.php,然后尝试登录,我被重定向到singleproduct.php而不是搜索.PHP。我在其他页面上执行此操作没有问题,包括singleproduct.php或我的任何其他页面,甚至在search.php中,如果我不通过浏览器按钮返回或向前结束它仍然有效。

是否与$ _SERVER [' REQUEST_URI']没有给出新网址或者我搞砸了其他地方?

我想知道为什么会这样,我该怎么做才能解决它。

的search.php

<?php
session_start();
include 'includes/dbh.inc.php';
$_SESSION['current_page'] = $_SERVER['REQUEST_URI'];
?>
<!DOCTYPE html>
<html lang="en">
<head>
</head>
<body>
    <form class="sea" action="search.php" method="GET">
        <input class="searchbar" name="search" type="text" placeholder="Search...">
        <button class="searchbutton" name="submit-search" type="submit"><i class="fa fa-search"></i></button>
    </form>
    //button for login
    <?php
    if(isset($_GET['submit-search'])) {
        $search = mysqli_real_escape_string($conn, $_GET['search']);
        $sql = "SELECT * FROM table WHERE product_name LIKE '%$search%' OR product_category LIKE '$search'";
        $result = mysqli_query($conn, $sql);
        $queryResult = mysqli_num_rows($result);
        if ($queryResult > 0) {
            while ($row = mysqli_fetch_array($result)) { ?>
            //read from database
            <a href="singleproduct.php?viewmore=<?php echo $row['product_id']; ?>"class="viewmore btn-info" role="button">View More</a>
            <?php }
        } ?>
</body>
</html>

singleproduct.php

<?php
session_start();
include 'includes/dbh.inc.php';
$_SESSION['current_page'] = $_SERVER['REQUEST_URI'];
?>
<!DOCTYPE html>
<div lang="en">
<head>
</head>
<body>
    <form class="sea" action="search.php" method="GET">
        <input class="searchbar" name="search" type="text" placeholder="Search...">
        <button class="searchbutton" name="submit-search" type="submit"><i class="fa fa-search"></i></button>
    </form>
    //button for login
    <?php
    $id = $_GET[viewmore];
    $result = mysqli_query($conn,"SELECT * FROM table WHERE product_id='".$id."' ");
 while($row = mysqli_fetch_array($result)){
 //read the database for the single item
 }?>
</body>
</html>

包括/ login.inc.php

<?php

session_start();
if (isset($_POST['submit'])){
    //Error Handlers
    if(){
    }
    else{
        $_SESSION['u_id'] = $row['user_id'];
            $_SESSION['u_uid'] = $row['user_uid'];
            $_SESSION['u_email'] = $row['user_email'];
            $_SESSION['u_status'] = $row['user_status'];
            $_SESSION['u_level'] = $row['user_level'];
            $_SESSION['success-message'] = '';
            header("Location: ". $_SESSION['current_page']);
            exit();
    }
}

0 个答案:

没有答案