Results 1 to 3 of 3

Thread: New PHP Login script, need help completing

  1. #1
    Join Date
    Nov 2004
    Location
    NYS
    Posts
    29

    Default New PHP Login script, need help completing

    Hey guys. I'm working on a login script and I'm having some problems getting my code to compare two things correctly. I have an html page with a form containing

    <input type=text name=username> :username

    <input type=text name=password> :password


    sending it to my php script

    Then in my script i have this :
    Code:
    	$teacher==$_POST["teacher"];
    	$password==$_POST["password"];
    	$somecontent == "tom/nhhh/nkelley/nkkk/ntaylor/nttt";
    
    	echo $teacher . "
    ";                ---  Verify Teacher
    	echo $password . "
    ";             ---   Verify Password
    
    	$success ==0;
    
    
    	if(!($t=fopen("teacher.txt","r")))
    	exit("Unable to open Teacher File");
    	
    	while(!feof($t))
    	   { 
    		$t_read=fgets($t,65535);
    		echo $t_read . "
    ";
    		if ($teacher . "/r" == $t_read)
    		   {
    			$p_read == fgets($t,65535);
    			echo $p_read . "
    ";
    			if ($password==$p_read)
    			   {
    				echo "Successful Loggin!~";
    				$success == 1;
    			   }
    		   }
    	
    		else
    		   {
    			fgets($t);
    		   }
    	   }
    	fclose($t);
    	if(!($success==1))
    	echo $teacher . " with the password " . $password . " can not be 
    found in the database";
    I made the text file myself, because is_writeable would return false and chmod wouldnt work, so I couldn't write a script to register the usernames with fwrite.

    My database looks like this in notepad

    tom
    hhh
    kelley
    kkk
    taylor
    ttt

    I want it to scan the database's 1st line and show me what it finds
    Code:
    $t_read=fgets($t,65535);
    		echo $t_read . "
    ";
    then I want it to compare that to the name entered by the user
    Code:
    		if ($teacher . "/r" == $t_read)
    		   {
    			$p_read == fgets($t,65535);
    			echo $p_read . "
    ";
    			if ($password==$p_read)
    			   {
    				echo "Successful Loggin!~";
    				$success == 1;
    			   }
    		   }
    and in that script it does the same thing for the password. I think that after it reads the teachers name from the database, it is set on the next line. Then from there, if the teachers name matches the one entered, it reads the next line and compares that to the password. Tom's password would be hhh. Kelley's would be kkk... etc... If the teachers nme doesnt match, it reads a new line with fgets, but doesnt do anything with it, inorder to set it at the next username line.

    all of this works fine. Visuallly, I see tom print out first, then hhh, for the things entered by the user in the form, then I see tom print out as the first line read out, so I know thats being compared to the tome entered, but I see a blank space after it when I highlight. I'm thinking there might be some sort of charecter that was generated when I hand wrote my notepad document. I could be wrong, but eitehr way its not working. If you guys could give me a hand that would be thx :-). I am trying to avoid usign mySQL as my webhost doesnt support it.

    Sincerly,
    Black Lotus [/code]

  2. #2
    Join Date
    Sep 2003
    Posts
    3,040

    Default

    seems the code is ok.

    Now upload the file and debug if there any problem. You may print the values read from text file and from the forum.
    Become PHP Expert in 30 days
    FreeMarriage.com - Free Online Matrimonial
    FlashWebHost.com - Professional Web Hosting, Designing.

  3. #3
    Join Date
    Nov 2004
    Location
    NYS
    Posts
    29

    Default

    ty for the help, I found the problem. In my comparison opperators, I had a dubble equals instead of a single, resetting the compared variable instead of testing it. Tricky stuff in php!!! lol

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •