BobbyDigital Posted June 19, 2007 Share Posted June 19, 2007 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! Quote Link to comment https://forums.phpfreaks.com/topic/56221-solved-urgent-help-with-http_post_vars-and-_post/ Share on other sites More sharing options...
per1os Posted June 19, 2007 Share Posted June 19, 2007 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. Quote Link to comment https://forums.phpfreaks.com/topic/56221-solved-urgent-help-with-http_post_vars-and-_post/#findComment-277694 Share on other sites More sharing options...
BobbyDigital Posted June 19, 2007 Author Share Posted June 19, 2007 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... Quote Link to comment https://forums.phpfreaks.com/topic/56221-solved-urgent-help-with-http_post_vars-and-_post/#findComment-277714 Share on other sites More sharing options...
per1os Posted June 19, 2007 Share Posted June 19, 2007 <?php echo '_POST<pre>' , print_r($_POST), '</pre>'; echo 'HTTP_POST<pre>' , print_r($HTTP_POST_VARS), '</pre>'; ?> Run that instead so we can see which one is actually being outputed. Quote Link to comment https://forums.phpfreaks.com/topic/56221-solved-urgent-help-with-http_post_vars-and-_post/#findComment-277722 Share on other sites More sharing options...
BobbyDigital Posted June 19, 2007 Author Share Posted June 19, 2007 This is what I get from that code: _POST<pre>1</pre>HTTP_POST<pre>Array ( [username] => AAA [userpass] => testpass [btnlogin] => Submit ) 1</pre> Quote Link to comment https://forums.phpfreaks.com/topic/56221-solved-urgent-help-with-http_post_vars-and-_post/#findComment-277736 Share on other sites More sharing options...
akitchin Posted June 19, 2007 Share Posted June 19, 2007 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. Quote Link to comment https://forums.phpfreaks.com/topic/56221-solved-urgent-help-with-http_post_vars-and-_post/#findComment-277737 Share on other sites More sharing options...
BobbyDigital Posted June 19, 2007 Author Share Posted June 19, 2007 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... Quote Link to comment https://forums.phpfreaks.com/topic/56221-solved-urgent-help-with-http_post_vars-and-_post/#findComment-277744 Share on other sites More sharing options...
BobbyDigital Posted June 19, 2007 Author Share Posted June 19, 2007 I found out what the problem is... it is the $HTTP_SESSION_VARS and $_SESSION - they aren't working. Is there a way to get around this? Quote Link to comment https://forums.phpfreaks.com/topic/56221-solved-urgent-help-with-http_post_vars-and-_post/#findComment-277827 Share on other sites More sharing options...
chigley Posted June 19, 2007 Share Posted June 19, 2007 $_SESSION = $HTTP_SESSION_VARS; Maybe? Quote Link to comment https://forums.phpfreaks.com/topic/56221-solved-urgent-help-with-http_post_vars-and-_post/#findComment-277829 Share on other sites More sharing options...
BobbyDigital Posted June 19, 2007 Author Share Posted June 19, 2007 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. Quote Link to comment https://forums.phpfreaks.com/topic/56221-solved-urgent-help-with-http_post_vars-and-_post/#findComment-277837 Share on other sites More sharing options...
BobbyDigital Posted June 19, 2007 Author Share Posted June 19, 2007 I forgot to mention - right now, its just sending me back to the login page. So that is why I think the variables aren't being passed. Quote Link to comment https://forums.phpfreaks.com/topic/56221-solved-urgent-help-with-http_post_vars-and-_post/#findComment-277850 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.