Jump to content

Help ! php4 to php 5 migration..cant login to admin panel


Recommended Posts

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;

?>

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;
?>

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.