shilpacute Posted September 2, 2012 Share Posted September 2, 2012 pls help! cant login to admin panel..the code i used is //session_start(); session_name("adminSession"); session_register("adminLoggedIn"); session_register("adminUser"); session_register("errorNumber"); session_register("mandatoryMessage"); ini_set('session.gc_maxlifetime',3600); $mandatoryMessage = "<font class='normalText'>[All entries marked with <font class='errorText'>*</font> are mandatory]<br><br></font>"; //$dbConnect = mysql_pconnect("localhost", "root", ""); // @mysql_select_db("shoptvm", $dbConnect); $dbConnect = mysql_pconnect("testdb1.db.3187143.hostedresource.com", "testdb1", "xyz123"); @mysql_select_db("dbtvm1", $dbConnect); $curDateQuery = mysql_query("SELECT DATE_FORMAT(CURDATE(), '%M %d, %Y'), CURDATE()"); $curDateResults = mysql_fetch_row($curDateQuery); $curSysDateDisp = $curDateResults[0]; $curSysDateValue = $curDateResults[1]; function printHeader($adminLoggedIn) { global $adminLoggedIn,$adminUser,$currentUser,$pageType, $curSysDateDisp, $curSysDateValue; if(!checkSession($adminLoggedIn)) { //header("Location: ../index.php"); exit; } //echo $adminLoggedIn; ?> Quote Link to comment https://forums.phpfreaks.com/topic/267906-help-php4-to-php-5-migrationcant-login-to-admin-panel/ Share on other sites More sharing options...
matthew9090 Posted September 2, 2012 Share Posted September 2, 2012 What are we meant to do with that? Tell us what errors you get and what happens when you run the script. Quote Link to comment https://forums.phpfreaks.com/topic/267906-help-php4-to-php-5-migrationcant-login-to-admin-panel/#findComment-1374659 Share on other sites More sharing options...
Jessica Posted September 2, 2012 Share Posted September 2, 2012 You need to go change your database credentials now, as you've just posted them on a public forum. Quote Link to comment https://forums.phpfreaks.com/topic/267906-help-php4-to-php-5-migrationcant-login-to-admin-panel/#findComment-1374660 Share on other sites More sharing options...
PFMaBiSmAd Posted September 2, 2012 Share Posted September 2, 2012 A) The code you posted is missing the most important part that would be needed to help you, the checkSession() function definition. B) The code is using the @ error suppressor. This will only hider troubleshooting (if your mysql_select_db statement is failing, you would want to know that since that would indicate a fundamental problem with your database.) You should never put @'s in your code to hide errors. You need to find and fix the cause of all errors. C) The code has a long list of variables being brought into the printHeader function using the global keyword, one of which is a duplicate of the call-time parameter being passed into that function. Using the global keyword makes it harder to write and troubleshoot code without having/knowing what ALL the code is. Where are those variables being set, which ones are being modified inside of that function, are they supposed to be modified inside of that function, or are they even used inside of that function? D) The code is over 10 years out of date, having nothing to do with php4 vs php5. It's using session_register that was depreciated (in favor of using $_SESSION variables) and disabled by default about 7 years before the end of life of php4. Instead of session_register/session_is_registered, you need to set and reference $_SESSION[...] variables and you need a session_start() statement (before you output anything to the browser) on any page that sets or references a $_SESSION variable. E) Both the session_name and the ini_set('session.gc_maxlifetime',3600) statements must go before any other session related statements. Based on the out of context code fragment you posted, the following is likely (would require knowing exactly what all your code and data is doing) the equivalent code rewritten to final php4 and current php5 standards - <?php session_name("adminSession"); // must go before the session_start ini_set('session.gc_maxlifetime',3600); // must go before the session_start session_start(); // uses the above two settings // based on the session_register('adminLoggedIn') statement, there would be a session variable - $_SESSION['adminLoggedIn'] that indicates if the current visitor is logged in as an admin // this is used in the form page? $_SESSION['mandatoryMessage'] = "<font class='normalText'>[All entries marked with <font class='errorText'>*</font> are mandatory]<br><br></font>"; // I did not do anything with the remaining variables identified in the session_register() statements since is not clear from the posted code if/what the values are being used for. $dbConnect = mysql_pconnect("<snip>", "<snip>", "<snip>"); // persistent connections only work on a very few server/php combinations. Most likely you are getting a normal connection from this. mysql_select_db("dbtvm1", $dbConnect); $curDateQuery = mysql_query("SELECT DATE_FORMAT(CURDATE(), '%M %d, %Y'), CURDATE()"); // if you have more than one mysql connection, you need to use the $dbConnect variable as the 2nd parameter in your mysql_query statements list($curSysDateDisp,$curSysDateValue) = mysql_fetch_row($curDateQuery); // shorter version of the code you had function printHeader($LoggedIn) { // when you call this function, it should be printerHeader($_SESSION['adminLoggedIn']); if(!checkSession($LoggedIn)) { header("Location: ../index.php"); exit; } echo $LoggedIn; ?> Quote Link to comment https://forums.phpfreaks.com/topic/267906-help-php4-to-php-5-migrationcant-login-to-admin-panel/#findComment-1374685 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.