PHP 5

From Ilianko


<!DOCTYPE html>
<html>
  <head>
    <meta charset="UTF-8"  />
  </head>
<body>
<table border=1>
	<tr>
	<td>Вид</td>
	<td>Цена</td>
	<td>Количество</td>
	</tr>
	<tr>
		
		<td>Картофи</td>
	<td>0.99</td>
	<td>10 кг.</td>
		
		
	</tr>	
	
	
</table>

</body>

</html>

include

include() include_once() require() require_once();

<?php
include("header.php");
include("menu.php");
?>


<table border=1>
	<tr>
	<td>Вид</td>
	<td>Цена</td>
	<td>Количество</td>
	</tr>

<?php

	foreach($_SESSION['buy'] as $value)
	{
		echo '<tr>
		<td>'.$value['vid'].'</td>
	    <td>'.$value['price'].'</td>
	    <td>'.$value['quantity'].'</td>
	</tr>';
	}	
?>	
	
</table>

<?php

 include("footer.php");
?>


header.php

<?php
  session_start();
  mb_internal_encoding('utf-8');
  
  
  if(!isset($_SESSION['logged']) && $_SESSION['loggeg'] == false)
  {
	header('Location:login.php');
  }

?>
<!DOCTYPE html>
<html>
  <head>
  	
  	
    <meta charset="UTF-8"  />
  </head>
<body>

menu.php


<a href="contacts.php">Kontakti</a>
<a href=index.php>Начало</a> <a href=addProduct.php>Добавяне продукти</a>

login.php

<?php
  session_start();
  mb_internal_encoding('utf-8');
  
  
  if( isset($_POST['pass']) && isset($_POST['user'])  
  && (   md5($_POST['pass'])  === "d8578edf8458ce06fbc5bb76a58c5ca4")  
  && ($_POST['user'] === "user"))
  {

  	$_SESSION['loggeg'] = true;
	header('Location:index.php');	
  }	 
 



?>

 <!DOCTYPE html>
<html>
  <head>
  	
  	
    <meta charset="UTF-8"  />
  </head>
<body>


<form action="" method=POST >
	
  User: <input name=user type="text" />
  Pass: <input name=pass type="password" />
  
  
  <input type=submit value="Вход" />	
	
	
</form>


</body>
</html>

addProduct.php

<?php
include("header.php");
include("menu.php");


$error = '';


if( isset($_POST['vid']))
{


  if( mb_strlen($_POST['vid']) < 3  )
  {
  
  	$error .= "<br /> Greshka vyv vida";
  
  }
  
  
  
  
  if(!is_numeric($_POST['quantity']) || !is_numeric($_POST['price'])  )
  {
  	$error .= "<br> Цена и Kolichestvo trqbwa da e chislena stojnost";
  
  }


  if($error)
    echo $error;
  else {
    $_SESSION['buy'][] = array(
     'vid' => strip_tags($_POST['vid']),'price' => strip_tags($_POST['price']), 'quantity' => strip_tags($_POST['quantity']));
  }


}

?>
    

	<form action="" method="post">
		Вид <input name=vid type="text" /><br />
		
		Цена: <input name=price type="text" /><br />
		
		Количество: <input name="quantity" type="text"/> <br />
		
		<input name"submit" type="submit" value="Dobavi" />
		
		
	</form>
	
<?php

  include("footer.php");
?>

  • trim();
  • strip_tags();
  • is_numeric($var);
  • mb_strlen();
  • mb_internal_encoding();