Force the opening of a page

Asked

Viewed 62 times

0

Next, I’m studying CRUD with PHP and I can’t solve a problem... How do I make PHP open another page if a condition is true?

In case it is a login, where after checking if login and password are right, I want to redirect the site to another page.

*{margin:0px;padding:0px;}
.cabeca{
	background-color: #006666;
	height:60px;
}

.corpo{
	height:600px;
	background-color: ;
}
.form1{
	height:70px;
	width: 40%;
	margin:0px auto;
	margin-top:200px;
	border:1px solid #ccc;
	padding:30px;
	text-align:center;
}
<!doctype html>
<html lang="pt-br">
	<head>
		<title>N2</title>
		<meta charset="utf-8">
		<link rel="stylesheet" href="css/style.css">
	</head>

	<body>
		<nav class="cabeca">
		</nav>

		<section class="corpo">
			<div class="form1">
				<form action="" method="POST">
						Login <input type="text" name="login"><br>
						Senha <input type="password" name="senha"><br>
						<input type="submit" value="ok"><br>
				</form>
			</div>
		</section>

		<footer class="cabeca">
		</footer>
		
		<?php
			include("conexao.php");
			$login=$_POST["login"];
			$senha=$_POST["senha"];

			$l=mysqli_query($con,"select nome_user from user where cod_user=1");
			$s=mysqli_query($con,"select senha_user from user where cod_user=1");

			$resl=mysqli_fetch_array($l);
			$resS=mysqli_fetch_array($s);




			if($resl[0]==$login && $resS[0]==$senha){
				//abrir uma pagina caso a condição esteja verdadeira;
			
			}
			else{

			}
						
		?>
	</body>
</html>

1 answer

0


You can use the function header :

header('Location: http://www.example.com/');

in your case :

if($resl[0]==$login && $resS[0]==$senha){
        header('Location: http://teu_dominio/tua_pagina.html/');
}
  • 1

    It is worth remembering that the header should be used before any output PHP, that is, before any HTML, echo or print

Browser other questions tagged

You are not signed in. Login or sign up in order to post.