دورة php للمبتدئين الدرس الثاني عشر
1- المتغير globals$ ف php
<?php
$nom = 'samadi';
$prenom = 'samir';
function fullname(){
$GLOBALS['fullname'] = $GLOBALS['nom'].' '.$GLOBALS['prenom'];
}
fullname();
echo $GLOBALS['fullname'];
?>
2- المتغير SERVER_$ ف php
<?php
// $nom = 'samadi';
// $prenom = 'samir';
// function fullname(){
// $GLOBALS['fullname'] = $GLOBALS['nom'].' '.$GLOBALS['prenom'];
// }
// fullname();
// echo $GLOBALS['fullname'];
//retourne le nom de fichier executer
echo $_SERVER['PHP_SELF'];
echo "<br>";
//retourne le nom de serveur hôte ici localhost
echo $_SERVER['SERVER_NAME'];
echo "<br>";
//retourne le nom de navigateur utilisé
echo $_SERVER['HTTP_USER_AGENT'];
echo "<br>";
//retourne le chemin du fichier
echo $_SERVER['SCRIPT_NAME'];
?>
3- المتغير REQUEST_$ ف php
<?php
// $nom = 'samadi';
// $prenom = 'samir';
// function fullname(){
// $GLOBALS['fullname'] = $GLOBALS['nom'].' '.$GLOBALS['prenom'];
// }
// fullname();
// echo $GLOBALS['fullname'];
//retourne le nom de fichier executer
// echo $_SERVER['PHP_SELF'];
// echo "<br>";
// //retourne le nom de serveur hôte ici localhost
// echo $_SERVER['SERVER_NAME'];
// echo "<br>";
// //retourne le nom de navigateur utilisé
// echo $_SERVER['HTTP_USER_AGENT'];
// echo "<br>";
// //retourne le chemin du fichier
// echo $_SERVER['SCRIPT_NAME'];
if($_SERVER['REQUEST_METHOD'] == 'POST'){
$name = $_REQUEST['name'];
echo $name;
}
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>Php Cours</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" type="text/css" media="screen" href="main.css" />
<script src="main.js"></script>
</head>
<body>
<form action="index.php" method="post">
<input type="text" name="name" id="name">
<input type="submit" value="valider">
</form>
</body>
</html>
4- المتغير POST_$ ف php
<?php
// $nom = 'samadi';
// $prenom = 'samir';
// function fullname(){
// $GLOBALS['fullname'] = $GLOBALS['nom'].' '.$GLOBALS['prenom'];
// }
// fullname();
// echo $GLOBALS['fullname'];
//retourne le nom de fichier executer
// echo $_SERVER['PHP_SELF'];
// echo "<br>";
// //retourne le nom de serveur hôte ici localhost
// echo $_SERVER['SERVER_NAME'];
// echo "<br>";
// //retourne le nom de navigateur utilisé
// echo $_SERVER['HTTP_USER_AGENT'];
// echo "<br>";
// //retourne le chemin du fichier
// echo $_SERVER['SCRIPT_NAME'];
if($_SERVER['REQUEST_METHOD'] == 'POST'){
$name = $_POST['name'];
echo $name;
}
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>Php Cours</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" type="text/css" media="screen" href="main.css" />
<script src="main.js"></script>
</head>
<body>
<form action="index.php" method="post">
<input type="text" name="name" id="name">
<input type="submit" value="valider">
</form>
</body>
</html>
5- المتغير GET_$ ف php
<?php
// $nom = 'samadi';
// $prenom = 'samir';
// function fullname(){
// $GLOBALS['fullname'] = $GLOBALS['nom'].' '.$GLOBALS['prenom'];
// }
// fullname();
// echo $GLOBALS['fullname'];
//retourne le nom de fichier executer
// echo $_SERVER['PHP_SELF'];
// echo "<br>";
// //retourne le nom de serveur hôte ici localhost
// echo $_SERVER['SERVER_NAME'];
// echo "<br>";
// //retourne le nom de navigateur utilisé
// echo $_SERVER['HTTP_USER_AGENT'];
// echo "<br>";
// //retourne le chemin du fichier
// echo $_SERVER['SCRIPT_NAME'];
if($_SERVER['REQUEST_METHOD'] == 'GET'){
$name = $_GET['name'];
echo $name;
}
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>Php Cours</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" type="text/css" media="screen" href="main.css" />
<script src="main.js"></script>
</head>
<body>
<form action="index.php" method="get">
<input type="text" name="name" id="name">
<input type="submit" value="valider">
</form>
</body>
</html>