PHP. Классы и объекты.

Cоздание класса :

 <html>
 

<body>
 <?
 class Animal
 {
	var $name;
function set_name ($text)
{
	$this ->name = $text;
}	
	 function get_name ()
	 {
		 return $this -> name ;
	 } 	 
 }
 wewew
 $lion = new Animal ;
 $lion -> set_name ("Bonifacii") ;
 echo "Imya sozdannogo l'va:" , $lion->get_name (),"." ;
 ?>
 </body>
 </html>

PHP.HTTP аутентификация.

<html> <head>
<title>Proverka Dati</title></head>
<body> 
 <?
 if (! isset ($_SERVER ['PHP_AUTH_USER']))
 {
	 header ('WWW-Authenticate:Basic realm ="workgroup"');
	 header ('HTTP/1.0 401 Unauthorized');
	 echo 'Noauthorized dostup zapreshen';
	 exit;
 }
 else
 {
echo "Dobro pozhalovat, {$_SERVER ['PHP_AUTH_USER']}." ;	 
 }
 ?>
 
  </body>
  </html>

PHP. Использование JavaScript для проверки данных.

<html> <head>

 <SCRIPT LANGUAGE="JavaScript">
 <!--
 function checker ()
 {
	 var regExp1=/^(\d{1,2})-(\d{1,2})-(\d{2})$/
	 var regExp2 = /^(\d{1,2})-(\d{1,2})-(\d{4})$/
	 var result1=document.form1.date1/value.match (regExp1)
	 var result2=document.form1.date1/value.match (regExp2)
	 if (result1 == null && result2 == null) { 
	 alert ("Data vvedena neverno . Korrectnii format - DD-MM-GG ili DD-MM-GGGG")
	 document.form1.date1.value=""
	 return false
	 }
  
 else 
 {
	 document.form1.submit ()
 }
 
 }
 //-->
 </SCRIPT>

 

PHP. Сохранение данных.

<html> <head><title>Button1</title></head>
<body> 
 
 
<?php  
 $errors = array  () ;
 if ( isset ($_REQUEST ["seen_already"]))
 {
	 validate_data ();
	 if (count($errors)>0 )
	 {
		 diplay_errors ();
		 display_form ();
	 }
	 else
	 {
		 process_data ();
	 }
 }
 else
 {
	 display_form ();
 }
 function validate_data ()
 {
	 global $errors ;
	 if  ($_REQUEST ["FirstName"] == "")
	 {
		 $errors [] = "<FONT COLOR='RED'>  Imya obyazatelno dlya vvoda </FONT>";
	 }
 }
 function display_errors ()
 {
	 global $errors ;

PHP.Кодирование тегов HTML.

<html> <head><title>Button1</title></head>
<body> 
 
 
<?php  
 $errors = array  () ;
 if ( isset ($_REQUEST ["seen_already"]))
 {
	 validate_data ();
	 if (count($errors)>0 )
	 {
		 diplay_errors ();
		 display_form ();
	 }
	 else
	 {
		 process_data ();
	 }
 }
 else
 {
	 display_form ();
 }
 function validate_data ()
 {
	 global $errors ;
	 if  ($_REQUEST ["Name"] == "")
	 {
		 $errors [] = "<FONT COLOR='RED'>  Imya obyazatelno dlya vvoda </FONT>";
	 }
 }
 function display_errors ()
 {
	 global $errors ;

PHP.Удаление тегов HTML.

<html> <head><title>Button1</title></head>
<body> 
 
 
<?php  
 $errors = array  () ;
 if ( isset ($_REQUEST ["seen_already"]))
 {
	 validate_data ();
	 if (count($errors)>0 )
	 {
		 diplay_errors ();
		 display_form ();
	 }
	 else
	 {
		 process_data ();
	 }
 }
 else
 {
	 display_form ();
 }
 function validate_data ()
 {
	 global $errors ;
	 if  ($_REQUEST ["Name"] == "")
	 {
		 $errors [] = "<FONT COLOR='RED'>  Imya obyazatelno dlya vvoda </FONT>";
	 }
 }
 function display_errors ()
 {
	 global $errors ;

PHP. Проверка строковых полей.

<html> <head><title>Button1</title></head>
<body> 
 
 
<?php  
 $errors = array  () ;
 if ( isset ($_REQUEST ["seen_already"]))
 {
	 validate_data ();
	 if (count($errors)>0 )
	 {
		 diplay_errors ();
		 display_form ();
	 }
	 else
	 {
		 process_data ();
	 }
 }
 else
 {
	 display_form ();
 }
 function validate_data ()
 {
	 global $errors ;
	 if  (!preg_match ('/php/i',$_REQUEST ["Text"]))
	 {
		 $errors [] = "<FONT COLOR='RED'>V tekste dolzhno bыt slovo 
		 
	 \"PHP\"</FONT>";
	 }
 }
 function display_errors ()
 {

PHP.Проверка числовых полей.

<html> <head><title>Button1</title></head>
<body> 
 
 
<?php  
 $errors = array  () ;
 if ( isset ($_REQUEST ["seen_already"]))
 {
	 validate_data ();
	 if (count($errors)>0 )
	 {
		 diplay_errors ();
		 display_form ();
	 }
	 else
	 {
		 process_data ();
	 }
 }
 else
 {
	 display_form ();
 }
 function validate_data ()
 {
	 global $errors ;
	 if  (strcmp($_REQUEST ["Number"] , strval (intval($_REQUEST ["Number"]))))
	 {
		 $errors [] = "<FONT COLOR='RED'>Sleduet vvesti chislo</FONT>";
	 }
 }

PHP. Обязательное для заполнения поле.

<html> <head><title>Button1</title></head>
<body> 
 
 
<?php  
 $errors = array  () ;
 if ( isset ($_REQUEST ["seen_already"]))
 {
	 validate_data ();
	 if (count($errors)>0 )
	 {
		 diplay_errors ();
		 display_form ();
	 }
	 else
	 {
		 process_data ();
	 }
 }
 else
 {
	 display_form ();
 }
 function validate_data ()
 {
	 global $errors ;
	 if ($_REQUEST ["Name"] == " ")
	 {
		 $errors [] = "<FONT COLOR='RED'>Imya Obyazatelno dlya vvoda</FONT>";
	 }
 }
 function display_errors ()
 {
	 global $errors ;

PHP.Проверка данных.

<html> <head><title>Button1</title></head>
<body> 
 
<?php

function display_errors () 
{
global $errors ;
foreach ($errors as $err )
{
echo $err.'<BR>';
}
}

function display_form ()
{
echo "<FORM METHOD='POST' ACTION='phpvalidate.php'>";
echo "<INPUT TYPE='SUBMIT' VALUE='OK' >";
echo "<INPUT TYPE='HIDDEN'  NAME='seen_already' VALUE='data'> ";
echo "</FORM>" ;
}





$errors =array ();
if (isset ($_REQUEST ["seen_already"]))
{
validate_data ();
if (count ($errors) >0 )
{
display_errors ();

Pages

Subscribe to fkn+antitotal RSS