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

Change => to = (but only the first one)

For the second one, you'll need something like

if($_REQUEST['username'] && $_REQUEST['password'] == $users[$_REQUEST['username']])
Member Avatar for diafol

Yikes!! Don't use $_REQUEST, ever.

Use the correct sglobal.

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

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 :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.