php probmes at start

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
teresa
Forum Newbie
Posts: 2
Joined: Fri Jan 21, 2011 10:57 am

php probmes at start

Post by teresa »

Greetings to all,
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>

Problem is when i tried to login and make sucessfull login it opens page but its empty?
When i enter wrong u/p info its prompt me error messages which is ok.
User avatar
Jade
Forum Regular
Posts: 908
Joined: Sun Dec 29, 2002 5:40 pm
Location: VA

Re: php probmes at start

Post by Jade »

Your exit statement is outside of the else portion of your if-else statement.

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(); //you only want to exit if they're not logged in
        }
       //putting exit() down here means this page will always exit whether you're logged in or not
?>

<!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>

 

teresa
Forum Newbie
Posts: 2
Joined: Fri Jan 21, 2011 10:57 am

Re: php probmes at start

Post by teresa »

Oh stupid me :(

Thanks a lot!
Post Reply