0

My code was properly working on school server but now I have changed the host and the page does not redirect. I have tried many things but none of them work. Thanks for your help!

My code:

<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
</head>
<?php require_once('baza.php'); ?>
<?php
session_start();

$user=$_POST['user']; 
$pass=$_POST['pass'];

$encrypted_pass=md5($pass);
$sql="SELECT * FROM uporabniki WHERE uporabnik='$user' and geslo='$encrypted_pass'";
$result=mysql_query($sql);


$count=mysql_num_rows($result);

if($count==1){
$_SESSION['user']=$user;
$_SESSION['pass']=$pass;

session_write_close();

header('Location: dostop.php');
}
else {
echo "Napačno uporabniško ime ali geslo.<br>";
echo "<a href='vpis.php'>Nazaj na vpis</a> ali ";
echo "<a href='index.php'>nazaj na Domačo stran.</a>";
}

?>
</html>
endure
  • 3
  • 4

2 Answers2

1

Two things:

  1. Headers can only be sent out before any other output is sent. That includes the lines from the doctype through the head. You need to send the header before that - before even an empty space.

  2. You really need to add a die(); call directly after sending the header. Otherwise, even though the user will be redirected, the rest of the script will continue to execute in the background. This can range from mildly troublesome to absolutely catastrophic, depending on the application.

Joel Hinz
  • 24,719
  • 6
  • 62
  • 75
0

Call die() or exit() function after header()

mynawaz
  • 1,599
  • 1
  • 9
  • 16