|
|||
|
PHP. include, require. Reserved variableshttps://www.w3schools.com/php/php_includes.asp
Reserved variables: $_GET $_POST $_SERVER $_SERVER['PHP_SELF'] $_SERVER['PATH'] $_ENV $_SESSION $_COOKIES https://www.php.net/manual/en/reserved.variables.php https://www.w3schools.com/php/php_superglobals.asp https://www.w3schools.com/php/php_superglobals_get.asp https://www.w3schools.com/php/php_forms.asp 1. Example, how to use forms: <form method="post" action="test_get.php">
<input type="text" name="fname" value = "<?php echo @$_POST['fname']; ?>"> <input type="submit"> </form> <?php echo "We have confirmed your name: <b>" . @$_POST['fname'] . "</b>"; ?> 1a. Example about useage of GET. This is UNSECURE example, because GET method is used instead of POST for password and user. The reason is to test and see variables for learning purposes: Not flexible code
<a href = "noPage.php?name=xyz&surname=sss">Ok</a><br /> More flexible code <a href = "<?php echo $_SERVER['PHP_SELF']; ?>?name=xyz&surname=sss">Ok</a><br /> <?php ?><hr />GET vars <br /><?php foreach ( $_GET as $r=>$b){ echo "$r = $b <br />"; } ?><hr />SERVER vars<br /><?php foreach ( $_SERVER as $r=>$b){ echo " $r = $b <br />"; } ?><hr />Array var<br><?php echo "{$_SERVER["QUERY_STRING"]} <br />"; ?> 2. Prototype of registration: <h3>MAIN</h3>
<a href= "<?php echo $_SERVER['PHP_SELF']; ?>">Home</a><br /> <?php $passwd = @$_GET["passwd"]; $user = @$_GET["user"]; if ( ! $user or ! $passwd ){ ?> <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="get"> <input type="text" name="user" value=""><br /> <input type="password" name="passwd" value=""><br /> <input type="submit" name = "OK"><br /> </form> <?php } elseif ($user == "jonas" && $passwd=="1972"){ include("my.html"); } elseif ($user=="petras" && $passwd=="1973"){ include("other.html"); }else{ echo "not good <br />"; } ?> my.html: my blah blah
other.html: other blah blah
Task 1: 1. Please create 3rd user "john" and his data page 2. Please create control code box (e.g. voucher code), which can be used by the users. It is 123. User can not see data without the code. Form view: user: [ ]
-password: [ ] control: [ ] |