Jump to content

Recommended Posts

Hello -

 

I am trying to build a login for a website that doesn't have php 4.1 installed, so my original code is not working on their server. This is my original php:

 

<?php
session_start();
$errorMessage = '';
if (isset($_POST['username']) && isset($_POST['userpass'])) {
include 'includes/globals.php';
include 'includes/dbconnect.php';
$userId   = $_POST['username'];
$password = $_POST['userpass'];
$sql = "SELECT custname 
	FROM auth
	WHERE custname = '$userId' AND custno = '$password'";
$result = mysql_query($sql) or die('Query failed. ' . mysql_error()); 

if (mysql_num_rows($result) !== 0) {
	$_SESSION['db_is_logged_in'] = true;
	header('Location: OO_index.php'); // YOUR PAGE HERE
	exit;
}
include 'includes/dbdisconnect.php';
}
?>

 

This works great on my server and 2 other servers I've tested it on... However, it does not work on the old php version. I think it has to do with $_POST not being supported... so I switched them out with $HTTP_POST_VARS (and also $HTTP_SESSION_VARS) but it still won't work:

 

<?php
session_start();
$errorMessage = '';
if (isset($HTTP_POST_VARS['username']) && isset($HTTP_POST_VARS['userpass'])) {
include 'includes/globals.php';
include 'includes/dbconnect.php';
$userId   = $HTTP_POST_VARS['username'];
$password = $HTTP_POST_VARS['userpass'];
$sql = "SELECT custname 
	FROM auth
	WHERE custname = '$userId' AND custno = '$password'";
$result = mysql_query($sql) or die('Query failed. ' . mysql_error()); 

if (mysql_num_rows($result) !== 0) {
	$HTTP_SESSION_VARS['db_is_logged_in'] = true;
	header('Location: OO_index.php'); // YOUR PAGE HERE
	exit;
}
include 'includes/dbdisconnect.php';
}
?>

 

Does anyone have any idea what I'm doing wrong here? The page refreshes when you submit the login info, but it doesn't progress to the next page. Here is my login form, in case you want to look at it:

 

<form action="" method="post" name="aslogin" id="aslogin">
        <input name="username" type="text" id="username" size="16">
     	 <input name="userpass" type="text" id="userpass" size="16" maxlength="16">
     	 <input name="btnlogin" type="submit"  id="btnlogin" value="Submit">
  </form>

 

Please help if you can! Thank you!

Do some debugging try this:

 

<?php
session_start();
$errorMessage = '';

echo '<pre>' , print_r($_POST), '</pre>';
echo '<pre>' , print_r($HTTP_POST_VARS), '</pre>';
?>

 

See if anything prints out, and a quick little fix if the http_post_vars does work is something like this:

 

<?php
$phpversion = 4.1; // I think this is accesible via $_SERVER or even a function maybe ??? php_version(); un-sure which.
if ($phpversion < 4.4) { 
   foreach ($HTTP_POST_VARS as $key => $val) {
       $_POST[$key] = $val;
   }
}
?>

 

That will allow your script to work either way, it may be necessary to do a php version check.

Thanks so much for the quick reply.

 

I added this:

 

echo '<pre>' , print_r($_POST), '</pre>';
echo '<pre>' , print_r($HTTP_POST_VARS), '</pre>';

 

and this came back when I submitted the info in the form:

 

<pre>1</pre><pre>Array
(
    [username] => AAA
    [userpass] => testpass
    [btnlogin] => Submit
)
1</pre>

 

And I also tried adding the second bit of code you posted, but that didn't work either. Thanks for the help, let me know if you have any other ideas...

alternatively, you could just set the $_POST array to $HTTP_POST_VARS in one fell swoop:

 

$_POST = $HTTP_POST_VARS;

 

keep in mind that i don't think the $_POST will be available as a superglobal, but rather will reside in the local scope.

So essentially, replacing the $_POST parts with $HTTP_POST_VARS should work, correct? I have replaced all of the instances in the code, and it only refreshes the page when the form is submitted. I also tried using the $_POST = $HTTP_POST_VARS; but that won't work either...

Well, both of those seem not to be working. Basically, I have the login jump to a new page after logging in. And on that new page, at the top of my code, I have the following:

 

<?php
session_start();
if (!isset($HTTP_SESSION_VARS['db_is_logged_in']) || $HTTP_SESSION_VARS['db_is_logged_in'] !== true) {
header('Location: TheLoginPage.php');
exit;

}
?>

 

It seems that the session variables are not being passed at all from my login page. I've tried switching the $HTTP_SESSION_VARS with $_SESSION to no avail.

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.