简体   繁体   English

我如何使用echo或header重定向php页面?

[英]how can i redirect page in php with echo or header?(in if condition)

Ok, I tried echo and header to redirect my page when the password is correct but the page isn't redirecting. 好的,当密码正确但页面未重定向时,我尝试了echo和header来重定向页面。 I tried several time but nothing is happening 我尝试了几次,但没有任何反应

i am using xammp and php7 for this site. 我在这个网站上使用xammp和php7。

if($stmt->rowCount() > 0){
    // get retrieved row
    $row = $stmt->fetch(PDO::FETCH_ASSOC);
    // create array
    $user_arr=array(
        "status" => true,
        "message" => "Successfully Login!",
header( 'Location: ./index.html' ),
        "id" => $row['id'],
        "username" => $row['username']

    );

in phpstorm when i am using header( 'Location: ./index.html' ), it telling me that i am using void. 在phpstorm中,当我使用header('Location:./index.html')时,它告诉我我正在使用void。

The issue is a broken array. 问题是阵列损坏。

<?php
    if($stmt->rowCount() > 0){
        // get retrieved row
        $row = $stmt->fetch(PDO::FETCH_ASSOC);
        // create array
        $user_arr=array(
            "status" => true,
            "message" => "Successfully Login!",
            "id" => $row['id'],
            "username" => $row['username']
        );
        // Moved out of $user_arr
        header( 'Location: ./index.html' );
        exit;
    }
?>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM