Jump to content
  • Revista PROGRAMAR: Já está disponível a edição #60 da revista programar. Faz já o download aqui!

RedCandy

localhost redirecionou-o demasiadas vezes

Recommended Posts

RedCandy

Bom dia, estou com um problema em redirecionar para a página login.php, todas as outras páginas teem código para redirecionar para a página login.php quando ainda não foi feito o login.

Abaixo, o código da página login.php

<?php
	session_start();		
	if($_SESSION['nome'] == NULL || $_SESSION['nome']== "")
	{
		header("Location: http://localhost/testepap/login.php");
	}
				
?>
<html>
<title>Inicio</title>
<meta charset="UTF-8">
<meta http-equiv="Content-type" content="text/html; charset=UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://www.w3schools.com/w3css/4/w3.css">
<body>


<div class="w3-top">
  <div class="w3-bar w3-white w3-wide w3-padding w3-card">
    <a href="home.php" class="w3-bar-item w3-button"><b>AE</b> Augusto Cabrita</a>
    <div class="w3-right w3-hide-small">
		<a class="w3-bar-item">Bem-vindo, visitante! </a>
		<a href="Template.php" class="w3-bar-item w3-button">Matriculas</a>
		<a href="Login.php" class="w3-bar-item w3-button">Login</a>
		<a href="registar.php" class="w3-bar-item w3-button">Registar</a>
		<a href="http://aeacabrita.sytes.net/webgiae/" class="w3-bar-item w3-button">GIAE</a>
    </div>
  </div>
</div>
		
		
	
<header class="w3-display-container w3-content w3-wide" style="max-width:1500px;" id="home">
</header>


<div class="w3-content w3-padding" style="max-width:1564px">
	<div class="w3-container w3-padding-32" id="projects">
		<h3 class="w3-border-bottom w3-border-light-grey w3-padding-16">Para aceder ao site é necessário fazer o login, se nao tiver uma conta criada, <a href="registar.php"> registre-se.</a></h3>
	</div>

	<div class="w3-row-padding">
		<form action="home.php" method="POST">
			Nome: <input required type="text" name="nome" style="width: 300px;"><br><br><br>
			Senha: <input required type="password" name="password" style="width: 300px;"><br><br>
			<?php
			if (isset($_COOKIE["Fail"])){
				echo "<p style='color: red;'>Nome ou Senha errada</p>";
				 setcookie("Fail", "True", time()-1);
			}
			else{
				echo "<br><br>";
			}
			?>
		<input class="btn register" type="submit" name="submit" value="Login" >
		</form>
	</div>

</div>
</body>
</html>

 

Share this post


Link to post
Share on other sites
M6

Experimenta

<?php
	session_start();		
	if($_SESSION['nome'] == NULL || $_SESSION['nome']== "")
	{
		header("Location: http://localhost/testepap/login.php");
		exit();
	}
				
?>

 


10 REM Generation 48K!
20 INPUT "URL:", A$
30 IF A$(1 TO 4) = "HTTP" THEN PRINT "400 Bad Request": GOTO 50
40 PRINT "404 Not Found"
50 PRINT "./M6 @ Portugal a Programar."

 

Share this post


Link to post
Share on other sites
jmp

Olá RedCandy

Da forma abaixo deveria funcionar bem!

Dá uma olhadela no código com calma.

Em 25/03/2019 às 10:50, RedCandy disse:

header("Location: http://localhost/testepap/login.php");

Share this post


Link to post
Share on other sites
M6

A página de Login não terá o mesmo redirecionamento?
Se sim, remove-o.


10 REM Generation 48K!
20 INPUT "URL:", A$
30 IF A$(1 TO 4) = "HTTP" THEN PRINT "400 Bad Request": GOTO 50
40 PRINT "404 Not Found"
50 PRINT "./M6 @ Portugal a Programar."

 

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×

Important Information

By using this site you accept our Terms of Use and Privacy Policy. We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.