Page 1 of 1

parse error on line 82

Posted: Thu Jul 01, 2004 1:37 pm
by fresh

Code: Select all

<?php

// check if pass is correct
$sp = $_GET['name'];
$perm = $_GET['pass'];
$mess0 = "<center><font color=black size=3>You must enter a password to login.</font></a></center>";
$mess1 = "<center><font color=black size=3>You must enter a name to login.</font></a></center>";
$mess2 = "<center><font color=black size=3>That account or password is invalid.</font></a></center>";
if(!$sp) {
echo "<center><font size=6>What Happened?</font></center><br><br>";
echo "<center><div style='border:#000000 1px solid; width:200;'>".$mess0."</div></center>";
echo "<br><br><center><a href='#' style='text-decoration:none'><font size=2 color=white>back</font></a></center>";
} elseif(!$perm) {
echo "<center><font size=6>What Happened?</font></center><br><br>";
echo "<center><div style='border:#000000 1px solid; width:200;'>".$mess1."</div></center>";
echo "<br><br><center><a href='#' style='text-decoration:none'><font size=2 color=white>back</font></a></center>";
} elseif(!file_exists("members/".$sp.".htm")) {
echo "<center><font size=6>What Happened?</font></center><br><br>";
echo "<center><div style='border:#000000 1px solid; width:200;'>".$mess2."</div></center>";
echo "<br><br><center><a href='#' style='text-decoration:none'><font size=2 color=white>back</font></a></center>";
} else {
  function bytexor($a,$b,$l)
  {
   $c="";
   for($i=0;$i<$l;$i++) {
     $c.=$a{$i}^$b{$i};
   }
   return($c);
  }

  function binmd5($val)
  {
   return(pack("H*",md5($val)));
  }

  function decrypt_md5($msg,$heslo)
  {
   $key=$heslo;$sifra="";
   $key1=binmd5($key);
   while($msg) {
     $m=substr($msg,0,16);
     $msg=substr($msg,16);
     $sifra.=$m=bytexor($m,$key1,16);
     $key1=binmd5($key.$key1.$m);
   }
   echo "\n";
   return($sifra);
  }

  function crypt_md5($msg,$heslo)
  {
   $key=$heslo;$sifra="";
   $key1=binmd5($key);
   while($msg) {
     $m=substr($msg,0,16);
     $msg=substr($msg,16);
     $sifra.=bytexor($m,$key1,16);
     $key1=binmd5($key.$key1.$m);
   }
   echo "\n";
   return($sifra);
  }

$crypted = crypt_md5($message, $key);

if($fp==$crypted) {
header("Location:main.php");
fclose($fp);
} else {
echo "<center><font size=2 color=black>Invalid Login.</font></center><br><br>";
echo "<center><a href='login.php'><font size=1 color=black>Re-Try</font></a></center>";
}
?>
heres my script, for login... I can't seem to get it to work properly, where did I go wrong with my syntax??? Im trying to read a file and compare the md5 encryption with the pass which is to also be encrypted and used to compare with what was encrypted when the user joined... can someone please take a look at this for me... thanks in advance


feyd | use

Code: Select all

tags[/color]

Posted: Thu Jul 01, 2004 1:49 pm
by feyd
which line is 82?

actually

Posted: Thu Jul 01, 2004 1:54 pm
by fresh
I altered the script, after I posted it, and now the error is on line 75 which is the line after the ?>... there is no code on line 75... what's wrong with my script...??

Posted: Thu Jul 01, 2004 1:57 pm
by feyd
you're not closing all the if..else junk..

Posted: Thu Jul 01, 2004 2:05 pm
by fresh
like where... it looks like I did???

Posted: Thu Jul 01, 2004 2:07 pm
by feyd

Code: Select all

if(!$sp) { 
echo "<center><font size=6>What Happened?</font></center><br><br>"; 
echo "<center><div style='border:#000000 1px solid; width:200;'>".$mess0."</div></center>"; 
echo "<br><br><center><a href='#' style='text-decoration:none'><font size=2 color=white>back</font></a></center>"; 
} elseif(!$perm) { 
echo "<center><font size=6>What Happened?</font></center><br><br>"; 
echo "<center><div style='border:#000000 1px solid; width:200;'>".$mess1."</div></center>"; 
echo "<br><br><center><a href='#' style='text-decoration:none'><font size=2 color=white>back</font></a></center>"; 
} elseif(!file_exists("members/".$sp.".htm")) { 
echo "<center><font size=6>What Happened?</font></center><br><br>"; 
echo "<center><div style='border:#000000 1px solid; width:200;'>".$mess2."</div></center>"; 
echo "<br><br><center><a href='#' style='text-decoration:none'><font size=2 color=white>back</font></a></center>"; 
} else {
the last else there is never closed.

ok

Posted: Thu Jul 01, 2004 2:35 pm
by fresh
got it closed up now, but now it's saying a call to undefined function:

Code: Select all

<?php

// check if pass is correct
$sp = $_GET['name'];
$perm = $_GET['pass'];
$mess0 = "<center><font color=black size=3>You must enter a password to login.</font></a></center>";
$mess1 = "<center><font color=black size=3>You must enter a name to login.</font></a></center>";
$mess2 = "<center><font color=black size=3>That account or password is invalid.</font></a></center>";
if(!$sp) {
echo "<center><font size=6>What Happened?</font></center><br><br>";
echo "<center><div style='border:#000000 1px solid; width:200;'>".$mess0."</div></center>";
echo "<br><br><center><a href='#' style='text-decoration:none'><font size=2 color=white>back</font></a></center>";
} elseif(!$perm) {
echo "<center><font size=6>What Happened?</font></center><br><br>";
echo "<center><div style='border:#000000 1px solid; width:200;'>".$mess1."</div></center>";
echo "<br><br><center><a href='#' style='text-decoration:none'><font size=2 color=white>back</font></a></center>";
} elseif(!file_exists("members/".$sp.".htm")) {
echo "<center><font size=6>What Happened?</font></center><br><br>";
echo "<center><div style='border:#000000 1px solid; width:200;'>".$mess2."</div></center>";
echo "<br><br><center><a href='#' style='text-decoration:none'><font size=2 color=white>back</font></a></center>";
} else {
  function bytexor($a,$b,$l)
  {
   $c="";
   for($i=0;$i<$l;$i++) {
     $c.=$a{$i}^$b{$i};
   }
   return($c);
  }

  function binmd5($val)
  {
   return(pack("H*",md5($val)));
  }

function crypt_md5($msg,$heslo)
  {
   $key=$heslo;$sifra="";
   $key1=binmd5($key);
   while($msg) {
     $m=substr($msg,0,16);
     $msg=substr($msg,16);
     $sifra.=bytexor($m,$key1,16);
     $key1=binmd5($key.$key1.$m);
   }
   echo "\n";
   return($sifra);
  } }

$crypted = crypt_md5($message, $key); //here's the error
$fx = fopen($sp.".txt","r");
$fx = readfile($sp.".txt");
$str = $crypted;
if($perm==$str) {
header("Location:main.php");
fclose($fx);
exit;
} else {
echo "<center><font size=2 color=black>Invalid Login.</font></center><br><br>";
echo "<center><a href='login.php'><font size=1 color=black>Re-Try</font></a></center>";
}
?>
i am trying to read a txt file, which holds an encrypted pass, then I want to compare that pass, to the input the user submits, which should be encrypted as well, before, the script goes to compare the input to the stored value, which came from when the user signed up... can someone please, please, fix this script to work... please

Posted: Thu Jul 01, 2004 2:42 pm
by feyd
well.. those 3 functions will only exist when that else which holds them is run..

well

Posted: Thu Jul 01, 2004 2:50 pm
by fresh
my if statement checks if the user inputted a name, if so then it checks if they entered a pass, and then finally it checks to see if that username, exists.. if exists, then it proceeds to the validate the user input, if not it echos invalid username or password... I tested this with signup.php, and then tried to login and it says that the function I described in my post above, is undefined... could there be anyother reasons why this isnt working, I mean can you look at this script and call it solid code? thanks

Posted: Thu Jul 01, 2004 2:58 pm
by feyd
this is the entirity of your else as it stood in your last code post:

Code: Select all

} else { 
  function bytexor($a,$b,$l) 
  { 
   $c=""; 
   for($i=0;$i<$l;$i++) { 
     $c.=$a{$i}^$b{$i}; 
   } 
   return($c); 
  } 

  function binmd5($val) 
  { 
   return(pack("H*",md5($val))); 
  } 

function crypt_md5($msg,$heslo) 
  { 
   $key=$heslo;$sifra=""; 
   $key1=binmd5($key); 
   while($msg) { 
     $m=substr($msg,0,16); 
     $msg=substr($msg,16); 
     $sifra.=bytexor($m,$key1,16); 
     $key1=binmd5($key.$key1.$m); 
   } 
   echo "\n"; 
   return($sifra); 
  } }

i know

Posted: Thu Jul 01, 2004 3:13 pm
by fresh

Code: Select all

<?php

// check if pass is correct
$sp = $_GET['name'];
$perm = $_GET['pass'];
function bytexor($a,$b,$l)
  {
   $c="";
   for($i=0;$i<$l;$i++) {
     $c.=$a{$i}^$b{$i};
   }
   return($c);
  }

  function binmd5($val)
  {
   return(pack("H*",md5($val)));
  }

function crypt_md5($msg,$heslo)
  {
   $key=$heslo;$sifra="";
   $key1=binmd5($key);
   while($msg) {
     $m=substr($msg,0,16);
     $msg=substr($msg,16);
     $sifra.=bytexor($m,$key1,16);
     $key1=binmd5($key.$key1.$m);
   }
   echo "\n";
   return($sifra);
  }

$crypted = crypt_md5($message, $key);
$fx = fopen($sp.".txt","r");
$fx = readfile($sp.".txt");
exit;

if($crypted==$perm) {
echo "correct";
} else {
echo "<center><font size=2 color=black>Invalid Login.</font></center><br><br>";
echo "<center><a href='login.htm'><font size=1 color=black>Re-Try</font></a></center>";
}
?>
for the sake of making this easy... I took out the else crap... now look at the chunk of code that compares input with stored data... this is not echoing correct... even when the correct pass is put in, plus I dont even think the input is being md5'd... feyd, is this script missing anything, I mean, I have never done this before today, and am totally winging this whole PHP thing, especially the PHP login schema... Im trying to learn man, so, could you just give me a push in the right direction, please... thanks

Posted: Thu Jul 01, 2004 3:24 pm
by feyd
you do that an exit; in there... ;)

lol

Posted: Thu Jul 01, 2004 3:49 pm
by fresh
duh, yeah that might help... thought you had to exit for some reason... only after you open and close dir and files... right??? anyway, now the darn thing is saying every password is correct...lol, ahhh this is killin me... i knew it wasnt md5in the input... any help with that?

whoo hoo

Posted: Thu Jul 01, 2004 4:26 pm
by fresh
got it... I gave in, setup a database, and went here to learn by example:

http://www.free2code.net/tutorials/prog ... plogin.php

great tutorial with code... ;)