Wrox Programmer Forums
Go Back   Wrox Programmer Forums > PHP/MySQL > Beginning PHP
|
Beginning PHP Beginning-level PHP discussions. More advanced coders should post to the Pro PHP forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Beginning PHP section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old January 9th, 2006, 11:04 PM
Registered User
 
Join Date: Jan 2006
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default Passing Variables with Login

I am trying to create a login for this moviesite exercise that I am working on. There are essentially three pages - a login page, an intermediary page that has a link to the movie info and then the movie info page. I can login to the intermediary page just fine, but for some reason when I click the link to go to the final page, I get a message (which I also created) denyting me access. So far as I can tell, it is coded properly...

Here is the code for the login page:

<?php
session_unset();

?>
<html>
<head>
<title>Please Log In</title>
</head>

<body>
<form method="post" action="movie1.php">
 <p>Enter your username:
   <input type="text" name="user">
 </p>
 <p>Enter your password:
   <input type="password" name="pass">
 </p>
 <p>
   <input type="submit" name="Submit" value="Submit">
 </p>
</form>
</body>
</html>

Here is the code for the intermediary page:

<?php
session_start();

$_SESSION['username'] = $_POST['user'];
$_SESSION['userpass'] = $_POST['pass'];
$_SESSION['authuser'] = 0;

if (($_SESSION['username'] == 'Joe') and
    ($_SESSION['userpass'] == '12345'))
   {
   $_SESSION['authuser'] == 1;
   }
   else
   {
   echo "Sorry, but you don't have permission to access this page.";
   exit();
   }
?>

<html>
<head>
<title>Find my Favorite Movie!</title>
</head>

<body>
<?php
  $_myfavmovie = urlencode("Madagascar");
  echo "<a href='moviesite.php?favmovie=$myfavmovie'>";
  echo "Click here to learn about my favorite movie!";
  echo "</a>";
?>
</body>
</html>

And here is the code for the final page...

<?php
session_start();

  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>

Thanks for your help!
 
Old January 10th, 2006, 06:40 AM
Friend of Wrox
 
Join Date: Dec 2004
Posts: 154
Thanks: 0
Thanked 0 Times in 0 Posts
Default

$_SESSION['authuser'] == 1;
===>
$_SESSION['authuser'] = 1;

and

$_myfavmovie = urlencode("Madagascar");
===>
$myfavmovie = urlencode("Madagascar");
 
Old January 10th, 2006, 09:27 AM
Registered User
 
Join Date: Jan 2006
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to Anupam Chatterjee
Default

Just illustrating the first point made by Mantis above. Thanks dude :)

Intermediary page :

<?php
session_start();

$_SESSION['username'] = $_POST['user'];
$_SESSION['userpass'] = $_POST['pass'];
$_SESSION['authuser'] = 0;

if (($_SESSION['username'] == 'Joe') and
    ($_SESSION['userpass'] == '12345'))
{
$_SESSION['authuser'] = 1;
}
else
{
echo "Sorry, but you don't have permission to access this page.";
exit();
}
?>





Similar Threads
Thread Thread Starter Forum Replies Last Post
Passing session variables from login page. captainzorro Classic ASP Components 1 April 23rd, 2008 11:54 PM
Passing variables karlirvin Beginning PHP 3 December 9th, 2005 04:37 PM
Passing variables karlirvin PHP How-To 4 December 2nd, 2005 08:02 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.