PHP Session Lab 1 Use the page1php and page2 page3 examples
PHP Session Lab
1. Use the page1.php and page2, page3 examples in chapter 23 as template. Create a fourth and fifth page participating the session. On each page, show links to all the other pages (it is OK to include a link to the current page).
On each page, display a list of all pages you visited during this session as shown below.
-You may use the Superglobal variable $_SERVER[“PHP_SELF”] to access the name of the current page.
-To declare an empty array use syntax: $some_array = [];
-To append to this array: $some_array[] = ‘Appended string’;
- you may use foreach() to retrieve the content of the session array
Please help me on how to display the list of pages as shown in the example above.Here is the code of the php files of pages 1-5.
page1.php
page2.php
page3.php
page4.php
page5.php
131.183.222.38 etest/Ch x C 131.183.222.38 examples/page3.php The last page you visited was etest/Chapter23/lab examples pages.php List of pages visited: /~etest/Chapter23/lab examples pagel.php etest Chapter23/lab examples/page2.php /~etest/Chapter23/lab examples/page3.php etest Chapter23/lab examples page2.php etest Chapter 23/lab examples pag /~etest Chapter23 lab examples page3.php /~etest/Chapter23/lab examples/page4.php /~etest/Chapter23/lab examples/page5.php /~etest Chapter23/lab examples page3.php Page 1 Page 2 Page 3 Page 4 Page 5Solution
page1.php
<?php
session_start();
echo \'<a href=\"page1.php?p1\">Page1.php</a>\';
echo \'<a href=\"page2,php?p2\">Page2.php</a>\';
echo \'<a href=\"page3.php?p3\">Page3.php</a>\';
echo \'<a href=\"page4.php?p4\">Page4.php</a>\';
echo \'<a href=\"page5.php?p5\">Page5.php</a>\';
$i=0;
if(isset($_GET[\'p1\']))
{
$file_array[$i]=\"page1.php\";
$i++;
}
if(isset($_GET[\'p2\']))
{
$file_array[$i]=\"page2.php\";
$i++;
}
if(isset($_GET[\'p3\']))
{
$file_array[$i]=\"page3.php\";
$i++;
}
if(isset($_GET[\'p4\']))
{
$file_array[$i]=\"page4.php\";
$i++;
}
if(isset($_GET[\'p5\']))
{
$file_array[$i]=\"page5.php\";
$i++;
}
echo \" The pages you visited are :\";
for($i=0;$i<$file_array.length;$++)
{
echo $file_array[$i];
}
?>
Like this you can do for another pages.
Thank you for asking CHEGG.

