Help with login script no longer working with PHP 5.3

Need help with a login script which stopped working after my IP-host upgraded the server to PHP 5.3
The script is really old! It was once developed in php3 about 6-7 (?) years ago. It has gradually stopped working on some platforms (browser) since a few months back, but now noone can access the site anymore ! :frowning: The guy who developed it for me is no longer around, and I’m not proficient in PHP…Really thankful for all help I can get!
[php]<?php
include("…/losen.php");
$logindb = “brf_L”;
$logintable = “Login”;
$username = $HTTP_COOKIE_VARS[“usernamecookie”];
$andelnr = getandel();

function getandel() {
global $username, $logindb;
initdb($logindb);
$svar = mysql_query(“SELECT Andel FROM Login WHERE user=’$username’”) or die (“Invalid query”);
$nummer = mysql_result($svar, Andel);
if ($nummer < 10) {
$andel = “Andel0$nummer”;
} else {
$andel = “Andel$nummer”;
}
return $andel;
}

function initdb($db) {
global $hostname, $mysqluser, $mysqlpassword;
mysql_pconnect($hostname,$mysqluser,$mysqlpassword) or die(“Unable to connect to SQL server”);
mysql_select_db($db) or die(“Unable to select database”);
}
function nytid() { //writes new time in the table
$time = time();
// initdb($logindb);
mysql_query(“UPDATE Login SET time=’$time’ WHERE user=’$username’”) or die(“Unable to perform insert”);
}
function inloggad() { //tests if you are logged in
//user name from cookie
//checks if time is OK and if IP is the same
$mintime = time() - 54000; //time in db should be at least 15 m from now
global $username, $REMOTE_ADDR, $logindb;
initdb($logindb);
$inlogdat = mysql_query(“SELECT * FROM Login WHERE user=’$username’ AND ip=’$REMOTE_ADDR’ AND time>’$mintime’”) or die (“Invalid query 1”);
$rows = mysql_num_rows($inlogdat);
return $rows;
}
function htmlpage() { // This is where the HTML page starts
?>

<?php } //**************MAIN PROGRAM STARTS HERE***************** if (inloggad() >= 1) { nytid(); htmlpage(); } else { die ("You have not logged in!"); } ?>[/php]

Well, there’s nothing but html tags being written to the page, so unless that’s supposed to be filled by something else, then i’d say that’s probably the problem.

Aha, needed this file as well…(I’ve blanked out all the HTML code)
[php]<?php
function chkpasswd () { // check password from $passwd and $username in mysql database
// if correct create cookie with $username, put $REMOTE_ADDR and
// time into database, forward to start.php3
// otherwise goto function login()
global $username, $passwd, $REMOTE_ADDR;

mysql_pconnect("mysql.xxxxx.org","xxxx","xxxxx") or die("Unable to connect to SQL server"); 
mysql_select_db("brf_L") or die("Unable to select database");  
$query = mysql_query("SELECT * FROM Login WHERE User='$username' AND Password='$passwd'") or die("Unable to perform query");
$rows = mysql_num_rows($query);
if ($rows == 0) {
	login();
}
setcookie ("usernamecookie");
    $cookie_life = 1*24*3600;
setcookie ("usernamecookie", "$username", time() + $cookie_life);
$time = time();
$insert = mysql_query("UPDATE Login SET time='$time' WHERE user='$username'") or die("Unable to perform insert");
$ipnr = mysql_query("UPDATE Login SET ip='$REMOTE_ADDR' WHERE user='$username'") or die("Unable to set ip");
echo "You have succesfully logged in";

?>

<?php } function login () { // This is where the HTML page starts ?>

<?php exit(); } ?> <?php // *******main program starts here mostly*********** // check if passwd and username both are set, if so check if they are correct // otherwise on case one print the login form // on case two print the log in form with "wrong password" if (empty($passwd) or empty($username)) { login(); } else { chkpasswd(); } ?>

[/php]

I don’t see any functions that are depreciated, i’d suggest renaming that php3 file to just php and see what happens. Unless you’re developing for multiple php versions, its really not needed.

:frowning: didn’t help…I renamed both files (loginstart.php3 and login.php3) to .php as well as changing all occurrences of .php3 to php.

try this :

change all this …
$username = $HTTP_COOKIE_VARS[“usernamecookie”];

to all this …

$username = $_COOKIE[“usernamecookie”];

@Richei - My mistake! I forgot one instance of .php3. Found it, changed it, and now it works beautiful! Thanks! :smiley:

Just one more thing. It works with PHP 5.2 but not 5.3. If I change the server to PHP 5.3 nothing happens when I try to login. The username and password cells simply blank out…

Since 5.3 is standard at my web hotel I need to get the script functioning for that version. Any idea what happens?

Do as the other person in here said, go through and find all the instances of $HTTP_COOKIE_VARS and change them to $_COOKIE.

Works partly - I get rerouted to the loginstart.php page, it displays on the screen - but with the following error msg:

Warning: mysql_result() expects parameter 2 to be long, string given in /home/b/brfskale/www/loginstart.php on line 50

what is on line 50?

Line 50 in the script loginstart.php> $nummer = mysql_result($svar, Andel);

but for some reason now it doesn’t work when I try to log in… Get the same as before - nothing happens when I click the login-button… :frowning:

uploaded the old version…that’s why it didn’t work…sorry.

Changing to $_COOKIE does work. It forwards the login process to the loginstart.php page, but with the error msg. I have changed $_COOKIE in all files and can move around among the files, but all display the same error msg.

Sponsor our Newsletter | Privacy Policy | Terms of Service