PHP - PHP No funciona al igualar 2 palabras identicas

 
Vista:

PHP No funciona al igualar 2 palabras identicas

Publicado por maxilance (1 intervención) el 06/02/2012 20:33:28
Hola,
Tengo el siguiente form:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
<form action="<?php echo $_SERVER['login/PHP_SELF']; ?>" method="post">
<?
		$pfile = fopen("includes/userpwd.txt","r");
		rewind($pfile);
 
		while (!feof($pfile)) {
			while ($line = fgets($pfile)){
			    $tmp = explode('\n', $line);
		 	    $tmp2 = explode(':', $tmp[0]);
 
			   echo "<label>".trim($tmp2[0]).' <input name="username" value="'.trim($tmp2[0]).'" type="radio"></label<br>';
			}
		}
		
		fclose($pfile);
?>
<input value="Reiniciar" name="submitBtn" type="submit">
</form>


Al elegir cualquier botón, y presionar en submit, envía los siguiente:

1
2
3
4
5
6
7
8
if (isset($_POST['submitBtn'])){
		echo $username;
		$username  = isset($_POST['username']) ? $_POST['username'] : '';
		// Try to register the user
		$jh = new loginjh();
		$error = $jh->formatUser($username);
 
	}


La clase formatUser($username) es:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
function formatUser($username)
	{
		$errorText = '';
		$pfile = fopen("includes/userpwd.txt","r");
		rewind($pfile);
		while (!feof($pfile)) {
 
			while ($line = fgets($pfile)){
			$tmp = explode('\n', $line);
			$tmp2 = explode(':', $tmp[0]);
 
	        echo trim($username) . " " . trim($tmp2[0]) . "<br>";
 
				if (trim($tmp2[0]) == trim($user)) {
					$errorText = $username . " SI ";
				} else {
					$errorText = $username . " NO ";
				}
				break;
			}
		}
 
		fclose($pfile);
 
		return $errorText;
	}


El echo trim($username) . " " . trim($tmp2[0]) . "<br>"; me devuelve estos valores:
cliente3 cliente1
cliente3 admin
cliente3 cliente3
cliente3 cliente4

Es decir que al momento de llegar a cliente3, deberia mostrarme el $errorText como OK.

Y sin embargo no lo toma a cliente3 = cliente3.

Alguna ayuda ?

Muchas Gracias!
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder