0

Hey all,

I'm just hoping to receive great help from you people..

I'm tryin to fix my PHP coding and it looks good,but the server says that a particular line is broken..

<?php
	$hd = fopen('content.txt', 'r');
	$line = fgets($hd);
	$content = array();
	
	while($line)
	{
		$word = explode(',', $line);
		$content [$word[0]] => array('img_path' => $word[1], 'description' => $word[2], 'price' => $word[3]);      // the error message is indicating this line is broken!!  Is it because of an equal sign missing? I tried putting an equal sign, but still it doesn't run.
		
		$line = fgets($hd);
	}
	fclose($hd);

And also, I'm trying to implement a log-in system without using Database management system.. I just want to use an array..

session_start();
	$users = array("user1" =>"3202", "user2" =>"2002", "user3" =>"1061", "user4"=>"1400", "user5"=>"1001");

//So, inside the if statement .... Would that be ok to use $_REQUEST or GET or even isSet?



if($_REQUEST['username'] == "user" && $_REQUEST['password'] == "3202"){ 

 <-- This condition is NOT right.. and I don't really know how to re-set it up..   like how to check if the username is matching with its corresponding password

		
		$_SESSION['username'] = "user1" ;
		$_SESSION['password'] = "3202" ;
		
		$_SESSION['username'] = "user2" ;
		$_SESSION['password'] = "2002" ;
		
		$_SESSION['username'] = "user" ;
		$_SESSION['password'] = "1001" ;
		
		$_SESSION['username'] = "user3" ;
		$_SESSION['password'] = "1061" ;
		
		$_SESSION['username'] = "user4" ;
		$_SESSION['password'] = "1400" ;
		header("Location: home.php ");

I'm looking forward to hearing from you Champions..

5
Contributors
5
Replies
6
Views
6 Years
Discussion Span
Last Post by vibhaJ
0

For the second one, you'll need something like

if($_REQUEST['username'] && $_REQUEST['password'] == $users[$_REQUEST['username']])
0

Please anyone take the time to explain what's wrong the code. I'm just a php noob..

0

Why you are setting so much session variables?
I think your logic is messy.

Try below code if it helps you.

<?  session_start();
	// list of username and password
	$users = array("user1" =>"3202", "user2" =>"2002", "user3" =>"1061", "user4"=>"1400", "user5"=>"1001");


if( isset($_POST['username']) && isset($_POST['password']) ) // form sibmitted with username and password
{ 
	foreach($users as $username=>$password)
	{
		if($username==$_POST['username'] && $password==$_POST['password']) // check username and password is vaalid or not
		{
			$_SESSION['username'] = $_POST['username'] ; // username is correct so set session 
			$_SESSION['password'] = $_POST['password'] ; // password is correct so set session 		
			
			header("Location: home.php ");
			exit;
		}
	}
	echo "Incorrect username and password.";	// no match found
	exit;
}

?>

YeeeEE.... 500 POSTS ON DANIWEB.. M HAPPY :)

Edited by vibhaJ: n/a

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.