Jump to content

[SOLVED] Login Issue's


TheJoey

Recommended Posts

<?php 
$file = fopen('user.txt', 'r');

/* Set login to false initially */
$login = false

/* Break out of loop if login becomes true OR EOF is encountered */
while(($login == false) && (!eof($file)))
{
  $data = explode(":", fgets($file));

  /* assume field 0 is username, field 1 is password */
  if( ($data['0'] == $username) && ($data['1'] == $password)
  {
    /* login is true, so will break out of loop after this iteration */
    $login = true;
  }
}
if $login = true
{
echo 'hi there user';
} else {echo 'nope';}
fclose($file);

?>
<html>
<body>
<form action="login4.php" method="post">
<ul>
<li><label for="username">
USERNAME: </label><input type="text"
name="username" id="username"/></li>
<li><label for="password">
PASSWORD: </label><input type="password"
name="password" id="password"/></li>
</ul>
<input name="login" type="submit" value="Login"/
</form>
</body>
</html>

 

Parse error: syntax error, unexpected T_WHILE in C:\xampplite\htdocs\login tests\login4.php on line 8

 

having trouble writing a login script that uses .txt files.

Link to comment
https://forums.phpfreaks.com/topic/177751-solved-login-issues/
Share on other sites

<?php 
$username = $_POST['username'];
$password = $_POST['password'];

$file = fopen("user.txt", "r");

/* Set login to false initially */
$login = false;

/* Break out of loop if login becomes true OR EOF is encountered */
while(($login == false) && (!feof($file)))
{
  $data = explode(":", fgets($file));

  /* assume field 0 is username, field 1 is password */
  if( ($data['0'] == $username) && ($data['1'] == $password))
  {
    /* login is true, so will break out of loop after this iteration */
    $login = true;
  }
}
if ($login = true)
{
echo 'hi there user';
} else {echo 'nope';}
fclose($file);

?>
<html>
<body>
<form action="login4.php" method="post">
<ul>
<li><label for="username">
USERNAME: </label><input type="text"
name="username" id="username"/></li>
<li><label for="password">
PASSWORD: </label><input type="password"
name="password" id="password"/></li>
</ul>
<input name="login" type="submit" value="Login"/
</form>
</body>
</html>

the code is fixed, and a few other errors are now fixed althought its always displaying 'hi there user'

even in the password is wrong

Link to comment
https://forums.phpfreaks.com/topic/177751-solved-login-issues/#findComment-937229
Share on other sites

Try this:

<?php 
$username = $_POST['username'];
$password = $_POST['password'];

$file = fopen("user.txt", "r");

/* Set login to false initially */
$login = false;

/* Break out of loop if login becomes true OR EOF is encountered */
while(($login == false) && (!feof($file)))
{
	$data = explode(":", fgets($file));

	/* assume field 0 is username, field 1 is password */
	if( ($data['0'] == $username) && ($data['1'] == $password))
	{
		/* login is true, so will break out of loop after this iteration */
		$login = true;
	}
}

if ($login == true)
{
	echo 'hi there user';
}
else
{
	echo 'nope';
}
fclose($file);
?>

Link to comment
https://forums.phpfreaks.com/topic/177751-solved-login-issues/#findComment-937236
Share on other sites

<?php
if ($login == true){
   $_SESSION['login'] = true;  # If successfull
   header("location: success.php");  # redirect to this page
} else {								  # Else redirect to
  header("location: unsuccess.php"); # this page
}
fclose($file);

?>

 

doesnt seem to be registering the session

Link to comment
https://forums.phpfreaks.com/topic/177751-solved-login-issues/#findComment-937264
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.