为什么没有找到重定向到网页?

I'm redirecting to page by link "welcome.php?language=english".

But when I place function 'confirm_patient_logged_in()' below Session declaration it's showing "Website not found". while it redirects to 'login.php' when this function is placed above Session declaration.

Can anyone tell what is reason behind this?

Welcome.php

<?php require_once("../../includes/session.php"); ?>

<?php confirm_patient_logged_in(); ?>  //WORKING HERE

<?php

if(isset($_GET["language"])){
    if($_GET["language"] == "english"){
        $_SESSION["language"] = "english";
    }else{
        $_SESSION["language"] = "hindi";
    }
}

?>

<?php confirm_patient_logged_in(); ?>   // NOT WORKING HERE

Function:

function confirm_patient_logged_in(){
        if(!patient_logged_in()){
        redirect_to("login.php");
    }
}

function redirect_to($new_location){
    header("Location: " . $new_location);
    exit;
}

patient_logged_in() checks if user is logged-in or not

It seems like you forgot to add session_start(); before using $_SESSION variable:

<?php

require_once("../../includes/session.php");

session_start();

if(isset($_GET["language"])){
    if($_GET["language"] == "english"){
        $_SESSION["language"] = "english";
    }else{
        $_SESSION["language"] = "hindi";
    }
}

confirm_patient_logged_in();   // SHOULD WORK

?>

So it the missing session_start(); was causing an error but you were unable to see the error probably display_error ini php.ini is disabled and you were getting Website not found notification on your browser.