如何使用相同的文件重定向我的代码?

i have a file and a function, the file named : 'try.php' with script like this :

<?php
function is_logged_in(){
    if(empty($_SESSION['authid'])){
        header("location: ./try.php?act=login");
    }
}

is_logged_in();
if(isset($_GET['act'])){
    // login form here
}

I have some error "The page isn't redirecting properly". so How can i redirect my code to the same file?

You have to make sure that you'll not create redirect loop, eg. by checking act parameter.

<?php
function is_logged_in(){
    if(empty($_SESSION['authid']) && (!isset($_GET['act']) || $_GET['act'] !== 'login')) {
        header("location: ./try.php?act=login");
    }
}

is_logged_in();
if(isset($_GET['act'])){
    // login form here
}