Hello,
Noob alert!!
I tried to protect some pages with a code I found googling. But since my server was recently moved to a better one, the code stoped working and gives me the error "Fatal error: Call to undefined function session_is_registered() .../protect_page.php on line 3"
I googled it, and I think it's happening because of the version of PHP.
I tried to fix it, but no joy!
I would appreciate if you could help me! I will paste here the code I have.
the code I got on every page I wish to protect<? include('protect_page.php')?>
login.php
<!DOCTYPE HTML>
<html lang="en-US">
<head>
<meta charset="UTF-8">
<title>Log in</title>
<link rel="stylesheet" media="all" href="pwstyle.css" />
<script>
function goBack()
{
window.history.back()
}
</script>
</head>
<body>
<form name="form1" method="post" action="checkpw.php">
<div id="container">
<p>
<span id="pass">Password:</span>
<span id="formfield"><input name="pw" type="text" id="pw"></span>
<span class="submitbt"><input type="submit" name="submitbt"></span>
</p>
<p><input type="button" value="Back" onclick="goBack()"></p>
</div>
</form>
</body>
</html>
protect_page.php
<?
session_start();
if(!session_is_registered(pw)){
header("location:login.php");
}
?>
checkpw.php
<?php
// pw is the password sent from the form
$pw=$_POST['pw'];
$pw = stripslashes($pw);
// you can make this much more robust by checking against a database in this file at this point
if($pw == 'password1'){
session_register("pw");
header("location:domino.php");
}
elseif($pw == 'password2'){
session_register("pw");
header("location:domino.php");
}
elseif($pw == 'password3'){
session_register("pw");
header("location:domino.php");
} else {
header("location:wrong.php");
}
?>
Can you help me?