To understand PHP's header()

前端 未结 3 1698
南笙
南笙 2020-12-19 16:53

Where do you use the command header()?

I have the following code at handlers/handle_login.php. The user has gone to the site from index.php

3条回答
  •  失恋的感觉
    2020-12-19 17:13

    Try using '/':

    if(!$logged_in){
         header("Location: /index.php");                                                                          
         die("You are not logged_in");
     }
    

    Without a slash, it is assumed that you're referring to something in the current directory. By sticking that slash at the front, you're explicitly referring to the file at the root of the site. Since the page is 'index.php', you could just as easily use "header('Location: /')".

提交回复
热议问题