0% found this document useful (0 votes)
69 views

Advanced: Dynamic Webpage Development

The document discusses advanced PHP concepts including form handling with $_GET, $_POST, and $_REQUEST variables, sessions using the $_SESSION global variable and session_start() function, and including/requiring files. It provides code examples for setting, accessing, modifying, and destroying session variables across multiple pages to maintain user session data.

Uploaded by

Joyce Perez
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
69 views

Advanced: Dynamic Webpage Development

The document discusses advanced PHP concepts including form handling with $_GET, $_POST, and $_REQUEST variables, sessions using the $_SESSION global variable and session_start() function, and including/requiring files. It provides code examples for setting, accessing, modifying, and destroying session variables across multiple pages to maintain user session data.

Uploaded by

Joyce Perez
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 15

advanced

Dynamic Webpage Development

PHP Lecture: Ryan Clifford L. Perez 1


1) Forms Handling
2) Sessions
3) Include and Require
4) Cookies
advanced
5) Headers

PHP Lecture: Ryan Clifford L. Perez 2


Advanced
HTML forms (web form) – allows the user to enter
data that is sent to a web server for processing.

Form Handling

PHP Lecture: Ryan Clifford L. Perez 3


How do PHP handle this forms and collect the
Advanced data for processing? By using…

<?php
Form Handling $_GET[“ ”];
$_POST[“ ”];
$_REQUEST[“ ”];
?>

PHP Lecture: Ryan Clifford L. Perez 4


The $_GET[“ ”]; variable is an array of variable
names and values sent by the HTTP GET method.

Advanced Index.php

<body>
<form action=“welcome.php" method=“GET">
Form Handling Name: <input type="text" name="name" />
$_GET[“ ”]; <input type="submit" />
</form>
</body>

PHP Lecture: Ryan Clifford L. Perez 5


Index.php
<body>
<form action=“welcome.php" method=“GET">
Name: <input type="text" name=“yourname" />
Advanced <input type="submit" />
</form>
</body>

Form Handling welcome.php


$_GET[“ ”];
<body>
Welcome <?php echo $_GET[“yourname”]; ?>
</body>

PHP Lecture: Ryan Clifford L. Perez 6


Index.php
<body>
<form action=“welcome.php" method=“POST">
Name: <input type="text" name=“yourname" />
Advanced <input type="submit" />
</form>
</body>

Form Handling welcome.php


$_POST[“ ”];
<body>
Welcome <?php echo $_POST[“yourname”]; ?>
</body>

PHP Lecture: Ryan Clifford L. Perez 7


Index.php (either GET or POST method)
<body>
<form action=“welcome.php" method=“GET">
Name: <input type="text" name=“yourname" />
Advanced <input type="submit" />
</form>
</body>

Form Handling welcome.php


$_REQUEST[“ ”];
<body>
Welcome <?php echo $_REQUEST[“yourname”]; ?>
</body>

PHP Lecture: Ryan Clifford L. Perez 8


When you work with an application, you open it, do
Advanced
some changes, and then you close it. This is much
like a Session.

Sessions A session is a way to store information to be used


across multiple pages.

PHP Lecture: Ryan Clifford L. Perez 9


A session is started with the session_start();
Advanced function.

Session variables are set with the PHP global


Sessions variable: $_SESSION.

PHP Lecture: Ryan Clifford L. Perez 10


A session is started with the session_start() function.
index.php
<?php
SESSION_START();
Advanced ?>
<body>
<?php
$_SESSION[“ Fullname”] = “Ryan Clifford Perez”;
Opening Sessions $_SESSION[“ Gender”] = “Male”;

echo $_SESSION[“ Fullname”];


?>
</body>

PHP Lecture: Ryan Clifford L. Perez 11


Accessing the session information we set on the index.php
viewsession.php

<?php
SESSION_START();
Advanced ?>
<body>
<?php
echo $_SESSION[“ Fullname”];
View Sessions
echo $_SESSION[“ Gender”];
?>
</body>

PHP Lecture: Ryan Clifford L. Perez 12


Display all the session variable values for a user session.
viewallsession.php

<?php
Advanced
SESSION_START();
?>
<body>
View all Sessions <?php
print_r($_SESSION);
?>
</body>

PHP Lecture: Ryan Clifford L. Perez 13


To change a session variable, just overwrite it.
index.php

<?php
Advanced
SESSION_START();
?>
<body>
Modify Sessions <?php $_SESSION[“ Fullname”] = “Ryan Clifford Perez”; ?>
<?php $_SESSION[“ Fullname”] = “Ryan Clifford”; ?>

</body>

PHP Lecture: Ryan Clifford L. Perez 14


To remove all global session variables and destroy the
session, use session_unset() and session_destroy().

<?php
SESSION_START();
Advanced ?>
<body>
<?php
// remove all session variables
SESSION_UNSET();
Destroy Sessions // destroy the session
SESSION_DESTROY();
?>

</body>

PHP Lecture: Ryan Clifford L. Perez 15

You might also like