i just started working in PHP and allredy stuck with problems. I am using PHP book from Wrox (p2programmer).
Here is code:
Code: Select all
<?php
session_start();
$_SESSION['username'] = $_POST['user'];
$_SESSION['userpass'] = $_POST['pass'];
$_SESSION['authuser'] = 0;
// provera informacije
if (($_SESSION['username'] == 'admin') and
($_SESSION['userpass'] == '12345' )) {
$_SESSION['authuser'] = 1;
} else {
echo "sorry mate u are not allowed to view this";
echo "click to back on login:";
echo '<a href="login.php">back</a>';
}
exit();
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Movie</title>
</head>
<body>
<?php
$favmovie = urlencode('Life of titanic');
echo "<a href=\"moviecode.php?favmovie=$favmovie\">";
echo "click here to visit page";
echo "</a>";
?>
</body>
</html>
Code: Select all
<?php
session_start();
if ($_SESSION['authuser'] !=1 ) {
echo "sorry u dont have perm dozvole";
exit ();
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Movie</title>
</head>
<body>
<?php
echo "welcome to our site";
echo $_SESSION['username'];
echo "!<br>";
echo "my favor movie is";
echo $_GET['favmovie'];
echo '<br>';
$movierate = 5;
echo 'My favorite movie name is';
echo $movierate;
?>
</body>
</html>
Code: Select all
<?php
session_unset();
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Movie</title>
</head>
<body>
<form method="post" action="movie4.php">
<p>Enter your username and pasword
<input type="text" name="user" />
</p>
<p>enter your password
<input type="password" name="pass" />
</p>
<input type="submit" name="submit" value="submit" />
</form>
</body>
</html>
When i enter wrong u/p info its prompt me error messages which is ok.