Hello to all,
I have a book at my hands called:
"Beginning
PHP5, APACHE, MySQL
Web Development"
in which it is mentioned that, if the readers are in need of help, they could look for it at this forum (and especially at this Echo Lounge) and that if they were lucky enough, they might find one of the authors of the book that i mentioned above.
That's the reason why i dare enter at this lounge rather than stay at the "newbies" place to ask there my totally newbie question.
Here is my question:
In my effort to learn php from the beginning, i started trying out all the codes it's written in the book, untill i stack at the "Passing variables with Sessions" topic where there are 2 example codes, the following:
code 1 (movie1.php):
(giving values to the $_SESSION['var'])
<?php
session_start();
$_SESSION['username'] = "Joe12345";
$_SESSION['authuser'] = 1;
?>
<html>
<head>
<title>Find my Favorite Movie!</title>
</head>
<body>
<?php
$myfavmovie = urlencode("Life of Brian");
echo "<a href='moviesite.php?favmovie=$myfavmovie'>";
echo "Click here to see information about my favorite movie!";
echo "</a>";
?>
</body>
</html>
and
code 2 (moviesite.php):
(retrieving values from $_SESSION['var'])
<?php
session_start();
//check to see if user has logged in with a valid password
if ($_SESSION['authuser'] != 1) {
echo "Sorry, but you don't have permission to view this page.";
exit();
}
?>
<html>
<head>
<title>My Movie Site - <?php echo $_REQUEST['favmovie']; ?></title>
</head>
<body>
<?php
echo "Welcome to our site, ";
echo $_SESSION['username'];
echo "! <br>";
echo "My favorite movie is ";
echo $_REQUEST['favmovie'];
echo "<br>";
$movierate = 5;
echo "My movie rating for this movie is: ";
echo $movierate;
?>
</body>
</html>
The problem is that i can't retrieve the values of $SESSION['username'] and $SESSION['authuser']. They appear to be empty (or null), so at the output of the second page i get the message:
Sorry, but you don't have permission to view this page.
instead of the:
Welcome to our site, Joe12345!
My favorite movie is Life of Brian
My movie rating for this movie is: 5
Also, when i changed the condition of the if statement to be:
if ($_SESSION['authuser'] != null) {
echo "Sorry, but you don't have permission to view this page.";
exit();
}
i didn't get the message:
Sorry, but you don't have permission to view this page.
but the following:
Welcome to our site, !
My favorite movie is Life of Brian
My movie rating for this movie is: 5
which means that the two variables ($SESSION['authuser'] and $SESSION['username']) are null.
What should i do?
Please help me.
Thank you.