错误:localhost重定向了你太多次了

Hi I'm a new student and starting to learn coding/programming specially on PHP. I tried learning some code and I have encountered this problem.

This page isn’t working

localhost redirected you too many times. Try clearing your cookies. ERR_TOO_MANY_REDIRECTS

and this is my code:

session_start();

include('_includes/config.php');
include('_includes/db.php');

    if(isset($_POST['register'])){
        $_SESSION['uname'] = $_POST['uname'];
        $_SESSION['fname'] = $_POST['fname'];
        $_SESSION['lname'] = $_POST['lname'];
        $_SESSION['email'] = $_POST['email'];
        $_SESSION['address'] = $_POST['address'];
        $_SESSION['postal'] = $_POST['postal'];
        $_SESSION['pass'] = $_POST['pass'];
        $_SESSION['con-pass'] = $_POST['con-pass'];
    }

    if(strlen($_POST['uname'])<3){
        header("Location:register.php?err=" . urlencode("The username must be at least 3 characters long"));
        die();
    }

I really don't know what to do I have encountered some errors in php but I haven't encountered this kind of error PLEASE HELP and PLEASE ENLIGHTEN me on what I have done wrong.

Check if user request to register too than redirect, update code like below :

session_start();

include('_includes/config.php');
include('_includes/db.php');

    if(isset($_POST['register'])){
        $_SESSION['uname'] = $_POST['uname'];
        $_SESSION['fname'] = $_POST['fname'];
        $_SESSION['lname'] = $_POST['lname'];
        $_SESSION['email'] = $_POST['email'];
        $_SESSION['address'] = $_POST['address'];
        $_SESSION['postal'] = $_POST['postal'];
        $_SESSION['pass'] = $_POST['pass'];
        $_SESSION['con-pass'] = $_POST['con-pass'];
    }

    if(strlen($_POST['uname'])<3 && isset($_POST['register'])){ // add && isset($_POST['register'])
        header("Location:register.php?err=" . urlencode("The username must be at least 3 characters long"));
        die();
    }

Note: at all i'm suggest you don't redirect user to show error message if codes in some file! you can store error message in vars and check if error var is not empty echo it!

session_start();

include('_includes/config.php');
include('_includes/db.php');
$error = ''; //add this var
    if(isset($_POST['register'])){
        $_SESSION['uname'] = $_POST['uname'];
        $_SESSION['fname'] = $_POST['fname'];
        $_SESSION['lname'] = $_POST['lname'];
        $_SESSION['email'] = $_POST['email'];
        $_SESSION['address'] = $_POST['address'];
        $_SESSION['postal'] = $_POST['postal'];
        $_SESSION['pass'] = $_POST['pass'];
        $_SESSION['con-pass'] = $_POST['con-pass'];
    }

    if(strlen($_POST['uname'])<3 && isset($_POST['register'])){ // add && isset($_POST['register'])
        /*header("Location:register.php?err=" . urlencode("The username must be at least 3 characters long"));
        die();*/
        $error = 'this is error message';
    }
//add below code anywhere you want show error
if($error){
    echo $error;
}