这个PHP代码中的循环在哪里?

I'm trying to create a restriction to a form in a website Im desingning so if you dont log in you cant open that form but apparently there's a loop I dont know where and I tried changing the headers locations and still the same, heres the code:

this one is for the login

<?php
  include ("conexion/conexion.php");


$usuario= $_POST['usuario'];
$clave= $_POST['clave'];


$sql="SELECT usuario,clave FROM usuarios WHERE usuario='".$usuario."' and clave='".$clave."'";
        $result=mysql_query($sql);
        $count=mysql_num_rows($result);

        if($count==1){ // The user exists
            $_SESSION["username"] = $usuario;
            $_SESSION["mypassword"] = $clave;  
            $_SESSION['login']=true;      
            header("location:loginusuario.php"); // page to redirect to


        }
        else {
header ("location: contacto.php");
}


?>

and this one for the file I created to restrinc the page

<?php
session_start();
if(!IsSet($_SESSION['login']) AND $_SESSION['login'] != true) {
header ("location: contrataciones.php");
}
else {
header ("location: loginusuario.php");
}
?>

if you can please copy and paste the edited code I need to finish this before tomorrow

Your if logic is inverse, if(!IsSet($_SESSION['login']) AND $_SESSION['login'] != true) will be if(IsSet($_SESSION['login']) AND $_SESSION['login'] == true) {

The logic here is wrong:

if(!IsSet($_SESSION['login']) AND $_SESSION['login'] != true) {

You should use OR, not AND.