Jump to content

[SOLVED] Help with Login Script


jmrothermel

Recommended Posts

Hi everyone, Im having a really hard time with this login script.  It worked fine on the old servers - I moved servers and re-uploaded and now everytime I try to login to my site I get

 

Fatal error: Cannot redeclare checkonline() (previously declared in /home/vchins/virtualchinchillas-www/functions.php:2) in /home/vchins/virtualchinchillas-www/functions.php on line 2

 

The code I am using for the login script is as follows:

 

<?
include("1header.php");

$username = addslashes($_POST['username']);
$password = addslashes($_POST['password']);
$authcode = addslashes($_POST['authcode']);
$admincode = addslashes($_POST['admincode']);

/*if ($admincode != "jmrothermel") {echo "<script>window.location='http://www.virtualchinchillas.com';</script>";}*/
if($username && $password && $authcode) {
$check = mysql_num_rows(mysql_query("SELECT `username` FROM `members` WHERE `username`='$username' AND `password`='$password'"));
if($check === 1) {
	$query = mysql_query("SELECT `validated` FROM `members` WHERE `username`='$username'");
	extract(mysql_fetch_array($query));
	switch ($validated) {
		case 0: //not validated
			echo "<script>window.location='validate.php?level=0&username=$username';</script>";
			break;
		case 1: //validated
			if(setcookie("ipets",$username."||".$authcode,0)) {
				$numrows_total_members = mysql_query("select count(*) from `members`");
				$counter_total_members = mysql_fetch_array($numrows_total_members);
				list ($isonline, $authcodeok, $counter_online) = checkonline($username, $authcode);
				switch (TRUE) {
					case ($isonline == 1 and $authcodeok == 1):
						//proceed
						echo "<script>window.location='1explore.php';</script>";
						break;
					case ($isonline == 1 and $authcodeok == 0):
						//change info in serverdata.txt
						updateonline($username, $authcode);
						echo "<script>window.location='1explore.php';</script>";
						break;
					case ($isonline == 0 and $authcodeok == 0):
						//log user in - insert info in serverdata.txt
						insertonline($username, $authcode);
						insertonlinetoday($username);
						echo "<script>window.location='1explore.php';</script>";
						break;
			}
			} else {
				echo "Can't set cookie";
			}
			break;
		case 2: //sent message
			echo "<script>window.location='validate.php?level=2&username=$username';</script>";
			break;
	}
} else {
	echo "Sorry, username/password mismatch!";
}
} else {
include('logheader.php');
$authcode = mt_rand(0, 100000);
print "<h2>Login</h2><p><form action='1login.php' method='post'>
Username<br><input type='text' name='username' size='20'><p>
Password<br><input type='password' name='password size='20'><p>
<!--Admin CODE<br><input type='text' name='admincode' size='20'><p>-->
<input type='hidden' name='authcode' value='$authcode' />
<input type='submit' value=' Login '></form>";
}
include("footer.php");
?>

 

Can anyone tell me what I might have wrong???  Im so confused  ???

Link to comment
Share on other sites

omg duh I didnt include the page causing the error.  Here it is:

 

<?
function checkonline($username, $authcode) {
$linha = file("serverdata.txt"); //username;authcode
$totalonline = count($linha); //gets online users count
$islogged = 0;
$authcodeok = 0;
for($i=0;$i<$totalonline;$i++) { //for each of the names in the file
	$vars = explode(";",$linha[$i]);
	if ($vars[0] === $username) {
		$islogged = 1;
		if ($vars[1] === $authcode) {
			$authcodeok = 1;
		}
	}
}
return array($islogged, $authcodeok, $totalonline);
}

function insertonlinetoday($username) {
$linha = file("onlinetoday.txt", "r");
$today = date("Y-m-d");
$stripped = trim($linha[0], "\r\n");
if ($stripped == date("Y-m-d")) {
	//this is the correct date
	$f = fopen ("onlinetoday.txt", "a+",0);
	$txtstring = $username."\r\n";
	fwrite($f,$txtstring,strlen($txtstring));
	fclose($f);
} else {
	//new day, unlink and start file over
	unlink("onlinetoday.txt");
	$f = fopen ("onlinetoday.txt", "w+");
	$txtstring = date("Y-m-d")."\r\n".$username."\r\n";
	fwrite($f,$txtstring,strlen($txtstring));
	fclose($f);
}
}

function onlinetoday() {
print "<table border=1 cellpadding=5 cellspacing=0><tr><td><center><b>Members who visited today</b></td></tr><tr><td></center>
<img src='http://www.chinclub.net/update/smilies/smilie7.gif'> = Upgraded Member</td></tr><tr><td></center>";
$linha = file("onlinetoday.txt");
$linha2 = file("serverdata.txt");
$total = count($linha);
$total2 = count($linha2);
for ($i=1;$i<$total;$i++) {
	if (strlen(trim($linha[$i])) > 1) { //if is shown on both files, online img else, offline
		for ($j=0;$j<$total2;$j++) {
			$smalldata = explode(";",$linha2[$j]);
			if (trim($linha[$i]) == trim($smalldata[0])) { //match - prints user with online image
				print "<img src=online.gif><a href='http://www.virtualchinchillas.com/profile.php?action=profile&username=";
				echo trim($linha[$i])."'>".trim($linha[$i])."</a>";
				break;
			}
			if ((trim($linha[$i]) != trim($smalldata[0])) and ($j == $total2 - 1)) { //no match, offline
				print "<img src=offline.gif><a href='http://www.virtualchinchillas.com/profile.php?action=profile&username=";
				echo trim($linha[$i])."'>".trim($linha[$i])."</a>";
			} 
		}
		//admin and upgrade piece below
		$sql = mysql_fetch_row(mysql_query("SELECT `upgrade`, `admin` FROM `members` WHERE `username`='".trim($linha[$i])."'"));
		if($sql[0] == 1) {
			print "<img src='http://www.chinclub.net/update/smilies/smilie7.gif'>";
		}
		if($sql[1] == 1) {
			print "<b>ADMIN</b><img src='http://www.chinclub.net/update/smilies/smilie7.gif'>";
		}
	}
	print "<br>";
}
print "</center></td></tr></table>";
}

function updateonline($username, $authcode) {
$linha = file("serverdata.txt");
$total = count($linha);
$fp = fopen("serverdata.txt","w+");
for ($i=0;$i<$total;$i++){
	list($sd_user, $sd_authcode) = explode(";",$linha[$i]);
	if ($sd_user == $username){
		$txtstring2 = $username.";".$authcode."\r\n";
		fwrite($fp, $txtstring2, strlen($txtstring2));
	} else {
		fwrite($fp,$linha[$i], strlen($linha[$i]));
	}
}
fclose($fp);
}

function removeonline($username, $authcode) {
	$linha = file("serverdata.txt");
$total = count($linha);
for ($i=0;$i<$total;$i++){
	list($sd_user, $sd_authcode) = explode(";",$linha[$i]);
	if ($sd_user == $username){
		unset($linha[$i]);
	} 
	if ($sd_user == "" or $sd_user == "\r\n"){
		unset($linha[$i]);
	} 		
}
$fp = fopen("serverdata.txt","w+");
$txtstring2 .= implode("",$linha);
fwrite($fp, $txtstring2, strlen($txtstring2));
fclose($fp);
}


function insertonline($username, $authcode) {
$f = fopen ("serverdata.txt", "a+",0);
$txtstring = $username.";".$authcode."\r\n";
fwrite($f,$txtstring,strlen($txtstring));
fclose($f);
}

function getusername() {
$alldata = explode("||", $_COOKIE["ipets"]);
return $alldata[0];
}

function getauthcode() {
$alldata2 = explode("||", $_COOKIE["ipets"]);
return $alldata2[1];
}

function validatenav() {
$a = 0; //screwed up!!!
if (isset($_COOKIE["ipets"])) {
	$linha = file("serverdata.txt"); //username;authcode
	$totalonline = count($linha); //gets online users count
	$alldata = explode("||", $_COOKIE["ipets"]);
	for($i=0;$i<$totalonline;$i++) { //for each of the names in the file
		$vardata = trim($linha[$i]);
		$newalldata = implode(";", $alldata);
		if ($vardata == $newalldata) {
				$a = 1;
		}
	}
}
return $a;
}

Link to comment
Share on other sites

somehow some where you are redeclaring a function which you can't do

 

that function checkonline (which I see being declared below) is being "created" so to speak when you include the functions file.  If you retry to create any function with that exact name it produces the above stated error.

 

 

Like duclet said require_once should fix this, but the issue I have is the document you should having the issue doesn't even reference said file so you must be hiding stuff making it hard for us to help you.

Link to comment
Share on other sites

Look at the include('xxxx') statements in the files

as said replace them with include_once('xxxx');

 

now look thru the files that were referenced in these includes

and do the same thing.

 

notice that the excrepts ya show us dun actually show the script that is causing the problem.

 

Link to comment
Share on other sites

See the problem is I took over the site from someone who was "so great with PHP"  ::)

 

So now Im stuck trying to find where the error is occuring.  Do you think it would be easier just to recreate the login script?

 

 

No because the error is inside the function decelerations not this individual page odds are it is a reoccuring issue.

Link to comment
Share on other sites

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.