Wrox Programmer Forums
|
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 July 3rd, 2006, 12:12 PM
Registered User
 
Join Date: Jul 2006
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default if/else statement

i got this book, Beginning PHP5, Apache, MySQL Web Development and im going through the Try It Out on page 54 and having a bit of difficulty.

Basically, i've setup 3 different *.php files movie1.php, moviesite.php and login.php,

movie1.php is where im having the problem.

user signs into login.php with Username "Joe" and password "12345", well in my movie1.php this is how it looks:

<?php

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

    //check username and password information
    if (($_SESSION['username'] == 'Joe') &&
        ($_SESSION['userpass'] == '12345')) {
        $_SESSION['authuser'] = 1;

    } else {
      echo "Sorry, but you don't have permission to view this page, you loser!1";
    exit();
    }
?>

Now when i sign in with Joe as username and 12345 as password, it should take me to my movie1.php and allow me to go on, but instead it gives me "Sorry, but you dont have permission to view this page, you loser!1"

It wont register the "1" value for 'authuser', and i cant get any further.

I've tried changing the username and password to something like "1" just for easy access, i've tried lowercase, uppercase, i've even copied and pasted from another text file to make sure that my keyboard wasnt putting something else in. I'm not sure what could be causing this.

 
Old July 3rd, 2006, 12:36 PM
Friend of Wrox
 
Join Date: Nov 2005
Posts: 223
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I don't have the book so I will need some more details.

Is this php code the only code on movie1.php.
If this is the case the only thing this code does is
set session named authuser to 1.

Have you completed the tutorial?

__________________________________________________ ________
This is my junk I'm gona eat it
 
Old July 3rd, 2006, 12:42 PM
Registered User
 
Join Date: Jul 2006
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default

okay, i will paste all the code from all 3 different files:

login.php
<?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>

movie1.php
<?php

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

    //check username and password information
    if (($_SESSION['username'] == 'Joe') &&
        ($_SESSION['userpass'] == '12345')) {
         $_SESSION['authuser'] = 1;

    } else {
      echo "Sorry, but you don't have permission to view this page, you loser!1";
    exit();
    }
?>
<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>

moviesite.php

<?php
session_start();
//check to see if user has logged in with valid password
    if ($_SESSION['authuser'] !=1) {
        echo "Sorry, but you don't have permission to view this page, you loser!";
        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 Favority Movie Is " ;
    echo $_REQUEST['favmovie'];
    echo "<br>";
    $movierate = 5;
    echo "My movie rating for this movie is: ";
    echo $movierate;
?>
</body>
</html>

thats basically everything i have so far for this tutorial. also i read somewhere that $_SESSION wouldnt work if i didnt have register_globals = off, so i went and put it to "on" and still nothing, but im pretty sure thats not the problem.

 
Old July 3rd, 2006, 02:00 PM
Friend of Wrox
 
Join Date: Nov 2005
Posts: 223
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi,

I guess I figured out your prob
check this
solution solved
or this
simular post

__________________________________________________ ________
This is my junk I'm gona eat it
 
Old July 3rd, 2006, 04:17 PM
Registered User
 
Join Date: Jul 2006
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default

i tried all of those suggestions, and i really appreciate the help but it seems that i may be having a different problem. i went to my php.ini which is located in c:\windows and changed the session.save path to c:\php\sess\tmp and i setup network sharing for that folder (sess) with read/write permissions and restarted my apache server and still nothing.

basically when i login to the form (which is login.php) with the username "Joe" and password "12345" its supposed to take me to movie1.php and give me a link to moviesite.php.

well, what happpens when i login with the "Joe" "12345" , i get the echo msg which is "Sorry, but you don't have permission to view this page, you loser!1". So i'm thinking that for some reason the login/pass im using isnt being registered as the correct login/pass.. but i've double/triple checked everything and cant figure out why it would, unless its some sort of sessions setting its carrying over from a previous attempt. I also went into my c:\php\sess\temp folder and deleted all the sessions in there, but still nothing.

Its not supposed to do that, if i've got it set to( $_SESSION['authuser'] = 1 ) in movie1.php, which tells me that its overlooking that whole part of movie1.php and going to "echo"..."





 
Old July 3rd, 2006, 06:06 PM
Registered User
 
Join Date: Jul 2006
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default

nevermind, i figured it out...<input type="password" name="pasS"> ... i had that last "S" capitalized...DOH!!! this has been a 6hr headache for me :(






Similar Threads
Thread Thread Starter Forum Replies Last Post
What does the @ do in the following statement? kenn_rosie VB.NET 2002/2003 Basics 1 March 15th, 2006 12:20 PM
Like Statement Nitin_sharma Oracle ASP 2 May 10th, 2005 12:18 AM
Like Statement Nitin_sharma Oracle 4 February 12th, 2005 01:46 PM
Like statement Nitin_sharma Classic ASP Databases 7 February 1st, 2005 11:12 AM
if statement markhardiman VS.NET 2002/2003 1 July 31st, 2003 06:56 PM





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