Difference between revisions of "PHP 4"

From Ilianko
 
(6 intermediate revisions by the same user not shown)
Line 1: Line 1:
 +
[[Category:PHP]]
 +
 
== GET ==
 
== GET ==
  
Line 22: Line 24:
 
</pre></code>
 
</pre></code>
  
== COOKIE==
+
 
 +
== SERVER ==
 +
 
 +
<?php
 +
  print_r($_SERVER) 
 +
?>
 +
 
 +
<?php
 +
  if($_SERVER['REQUESTED_METHOD'] == 'POST')
 +
  {
 +
    echo 'OK';
 +
  }
 +
?>
 +
 
 +
== SESSION ==
  
 
<code><pre>
 
<code><pre>
 
<?php
 
<?php
 
+
session_start();
 
  echo 'old: ';
 
  echo 'old: ';
  print_r($_COOKIE['user']);
+
  print_r($_SESSION);
  
 
  echo '<br /> new: ';
 
  echo '<br /> new: ';
  print_r($_POST['user']);
+
  print_r($_POST);
 
?>
 
?>
  
Line 42: Line 58:
 
<?php
 
<?php
 
    
 
    
   setcookie("user", $_POST['user']);
+
   $_SESSION['user'] = $_POST;
 +
?>
 +
</pre></code>
  
 +
<code><pre>
 +
<?php
 +
 
 +
  session_start();
 +
  print_r($_SESSION);
 +
 
 +
  if(  isset($_SESSION['element']){ 
 +
    $_SESSION['element']++;
 +
  }
 +
  else
 +
    $_SESSION['element'] = 1;
 
?>
 
?>
 
</pre></code>
 
</pre></code>
  
== SERVER ==
+
== COOKIE==
 +
 
 +
<code><pre>
 +
<?php
  
  <?php
+
  echo 'old: ';
 +
print_r($_COOKIE['user']);
  
  print_r($_SERVER)
+
echo '<br /> new: ';
 +
print_r($_POST['user']);
 +
?>
  
?>
+
<form method=POST>
 +
  <input type=text name=user>
 +
  <input type=submit name=button value="natisni">
 +
</form>
  
  
<?php
+
<?php
 
    
 
    
  if($_SERVER['REQUESTED_METHOD'] == 'POST')
+
  setcookie("user", $_POST['user']);
  {
+
 
    echo 'OK';
+
?>
  }
+
</pre></code>
 +
 
  
?>
 
  
== SESSION ==
+
print_r($_COOKIE);
 +
setcookie('broj', ++$_COOKIE['broj'],  time() + (10 * 365 * 24 * 60 * 60));

Latest revision as of 14:14, 22 October 2013


GET

<?php
  print_r($_GET)
?>



POST

<?   
  print_r($_POST)
?>
<form method=POST>
  <input type=text name=user>
  <input type=submit name=button value="natisni">
</form>


SERVER

<?php
  print_r($_SERVER)  
?>
<?php
  if($_SERVER['REQUESTED_METHOD'] == 'POST')
  {
    echo 'OK';
  }
?>

SESSION

<?php
 session_start();
 echo 'old: ';
 print_r($_SESSION);

 echo '<br /> new: ';
 print_r($_POST);
?>

<form method=POST>
  <input type=text name=user>
  <input type=submit name=button value="natisni">
</form>


<?php
  
  $_SESSION['user']  = $_POST;
?>
<?php
  
  session_start();
  print_r($_SESSION);
   	
  if(  isset($_SESSION['element']){  	
    $_SESSION['element']++;
  }
  else 
    $_SESSION['element'] = 1;
?>

COOKIE

<?php

 echo 'old: ';
 print_r($_COOKIE['user']);

 echo '<br /> new: ';
 print_r($_POST['user']);
?>

<form method=POST>
  <input type=text name=user>
  <input type=submit name=button value="natisni">
</form>


<?php
  
  setcookie("user", $_POST['user']);

?>


print_r($_COOKIE);
setcookie('broj', ++$_COOKIE['broj'],  time() + (10 * 365 * 24 * 60 * 60));