How do I get list of all pages visited during the session ex
How do I get list of all pages visited during the session, example 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
CAN SOME ONE HELP ME WITH THE CODE TO GET THE DISPLAY ABOVE!
Do not send me this code IT DOESN\'T WORK:
session_start();
echo \'Page1.php\';
echo \'Page2.php\';
echo \'Page3.php\';
echo \'Page4.php\';
echo \'Page5.php\';
$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[$i];$i++)
}
?>
This is what I came up with so far CAN SOMEONE MODIFY THIS WHERE I AM GETTING THE VISITED PAGES WITH NO ERRORS.
session_start();
// .$_SESSION[\'sess_var\'].\'
\';
$array_var = [];
$array_var[]= \'tom\';
$array_var[]=\'alice\';
$array_var[7] = \'Smith\';
echo $_SERVER[\'PHP_SELF\'];
$_SESSION[\'name\'] = \'Tom Smith
\';
// echo $_SESSION[\'name\'];
$currentpageurl = $_GET[\'name\'];
$_SESSION[\'name\']= array();
$_SESSION[\'name\'][] = $currentpageurl;
$_SESSION[\"name\"] = array_slice($_SESSION[\"name\"], -10);
?>
Page 1
Page 2
Page 3
Page 4
Page 5
Solution
session_start(); if(!empty($_SESSION[\'visited_pages\'])) { $_SESSION[\'visited_pages\'][\'prev\'] = $_SESSION[\'visited_pages\'][\'current\']; }else { $_SESSION[\'visited_pages\'][\'prev\'] = \'No previous page\'; } $_SESSION[\'visited_pages\'][\'current\'] = $_SERVER[\'REQUEST_URI\'];![How do I get list of all pages visited during the session, example below -You may use the Superglobal variable $_SERVER[“PHP_SELF”] to access the name of the cu How do I get list of all pages visited during the session, example below -You may use the Superglobal variable $_SERVER[“PHP_SELF”] to access the name of the cu](/WebImages/34/how-do-i-get-list-of-all-pages-visited-during-the-session-ex-1099878-1761580899-0.webp)
![How do I get list of all pages visited during the session, example below -You may use the Superglobal variable $_SERVER[“PHP_SELF”] to access the name of the cu How do I get list of all pages visited during the session, example below -You may use the Superglobal variable $_SERVER[“PHP_SELF”] to access the name of the cu](/WebImages/34/how-do-i-get-list-of-all-pages-visited-during-the-session-ex-1099878-1761580899-1.webp)