Jump to content

not catching the post variables


davidp

Recommended Posts

For some reason my PHP script is not catching the post variables that should be being sent by this form.  I have been looking at it for awhile now, and I cannot find any bug.  Maybe one of you could help?

 

This is the code that is supposed to catch the post variables:

 

if ( $_GET['action'] == "login" )
{
//Check the username and password
$userName = "";
$password = "";
if ( isset( $_POST['userid'] ) )
    $userName = $_POST['userid'];
if ( isset( $_POST['userpassword'] ) )
    $password = $_POST['userpassword'];
    
print "Username: ".$userName."<br>Password: ".$password."<br>";

 

This is the form itself (if HTML formats properly on this board...I guess I will find out when I post this):

 

<form action="../site/transition.php?action=login" method="POST">
	    dPru ID:<br>
	    <input type="text" name="userid"><br>
	    Password:<br>
	    <input type="password" name="userpassword"><br>
	    <input type="submit" value="Log In">
                </form>
	<a href="../site/index.php?action=newaccount">Create Account</a>

 

All the names of the fields match up with what I call them in the PHP script.  I know that the PHP script is being run, because I have output going on, so I know that it is not being skipped over.  Other forms that I have on the site that are similar to this one work fine...so I don't understand why this won't work!

 

Thanks for any help on this bug.

 

Link to comment
Share on other sites

yeah i left out that last curly bracket just because there is more code after that....the if statement doesn't end there...i just posted the important part.

 

That is really odd.  Here is another strange thing.  Let's say that I test one of my other forms that is functioning properly, for example.  If I use that form...and submit data...and then I try a refresh, the message box comes up telling me "Are you sure you want to resubmit POSTDATA?"...which is of course what should happen.

 

When I do that for that specific form, however, no message box comes up like that.  It is almost as if it is not even recognizing the fact that I told it to use the post method.  Why would that happen?  It's really strange.

 

If you want to test it for yourselves, it is the login form at the following site:

 

http://students.cs.byu.edu/~dpru/musicstore/site/

 

You can try logging in using these fields for data:

 

username: test

password: testcase

Link to comment
Share on other sites

I downloaded Fiddler, which is a program that watches your HTTP requests that you send. 

 

Here is the HTTP request that is being sent when I click submit:

 

POST /~dpru/musicstore/site/transition.php?action=login HTTP/1.1
Accept: */*
Referer: http://students.cs.byu.edu/~dpru/musicstore/site/
Accept-Language: en-us
Content-Type: application/x-www-form-urlencoded
UA-CPU: x86
Accept-Encoding: gzip, deflate
User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; .NET CLR 1.0.3705; .NET CLR 1.1.4322; Media Center PC 4.0; .NET CLR 2.0.50727; FDM)
Proxy-Connection: Keep-Alive
Content-Length: 33
Host: students.cs.byu.edu
Pragma: no-cache
Cookie: PHPSESSID=c394148909541df0b83ad1a707bb03dc

userid=test&userpassword=testcase

 

The request is perfectly fine.  It is a POST request, and it contains the post data.  Nothing is missing.

 

I thought maybe the server doesn't like receiving post requests, but it receives my other post requests from other forms perfectly fine....so that cannot be the problem.  That leaves the only problem lying in my PHP code.  Whats wrong?  :-[

 

I'm going to go ahead and post a larger amount of the PHP code...maybe it could shed some light:

 

require_once ("../classes/account.php");

require_once ("globals.php");
require_once ( "secure.php" );

require_once ("../db/dbm.php");

if ( !isset($_SESSION['dp_account']) )
{
    header ( "Location: ".BASE_URL );
}

if ( isset( $_GET['action'] ) )
{
    /***************************************
    The Login Script
    ***************************************/
    if ( $_GET['action'] == "login" )
    {
//Check the username and password
$userName = "";
$password = "";

print $_POST['userid']."<br>";

if ( isset( $_POST['userid'] ) )
    $userName = $_POST['userid'];
if ( isset( $_POST['userpassword'] ) )
    $password = $_POST['userpassword'];
    
print "Username: ".$userName."<br>Password: ".$password."<br>";

//Connect to the database
$dbm = new DBM ( );
if ( !$dbm->isConnected() )
{
    print 'Sorry, we are unable to connect to the database at this time.<br>';
    //print '<a href="'.BASE_URL.'">Main Site</a>';
}

//Check to see if the login is valid
if ( $dbm->isValidLogin($userName, $password) )
{
    $_SESSION['dp_account']->login($userName);
    print 'You successfully logged in!';
}
else
{
    print 'Invalid Login!';
    $_SESSION['dp_account']->logout();
}

//header ( "Location: ".BASE_URL );
    }
    
    /***************************************
    The Logout Script
    ***************************************/
    if ( $_GET['action'] == "logout" )
    {
$_SESSION['dp_account']->logout();
if ( isset ( $_SERVER['HTTP_REFERER'] ) )
{
    header ( "Location: ".$_SERVER['HTTP_REFERER'] );
}
else
{
    header ( "Location: ".BASE_URL );
}
exit;
    }

    /***************************************
    The New Account Script
    ***************************************/
    if ( $_GET['action'] == "newaccount" )
    {
//Connect to the database
global $dbm;
$dbm = new DBM ( );

if ( !$dbm->isConnected() )
{
    print 'Sorry, but your account could not be created because a connection with the database has failed.';
    exit;
}

//Process the new account
$userData['FirstName'] = $_POST['FirstName'];
$userData['LastName'] = $_POST['LastName'];
$userData['UserName'] = $_POST['UserName'];
$userData['Email'] = $_POST['Email'];
$userData['Password'] = $_POST['Password1'];
$userData['Country'] = $_POST['Country'];

$userData['Password2'] = $_POST['Password2'];
$userData['Validate'] = $_POST['Validate'];

print $_POST['FirstName'];
print $_POST['LastName'];
print $_POST['UserName'];
print $_POST['Email'];
print $_POST['Password1'];
print $_POST['Country'];
print '<br>';

$fileName = $_GET['fileName'];
if ( !$dbm->isValidImageValidation($fileName, $userData['Validate']) )
{
    print 'The text you entered into the image validation field was wrong!<br>';
    return;
}

if ( $dbm->UserExists( $userData['UserName'] ) )
{
    print 'That username already exists!';
    return;
}

if ( strcmp($userData['Password'], $userData['Password2']) == 0 && (strlen($userData['Password']) >= 6) )
{
    $dbm->insertUser ( $userData['FirstName'], $userData['LastName'], $userData['Email'], 
			$userData['UserName'], $userData['Password'], $userData['Country'] );
    print 'Your account has been successfully created';
}
else print 'Password does not match!';
    }
}

 

Thanks for any help yall can give me here.  :-[

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.