Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4531168
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T13:52:42+00:00 2026-05-21T13:52:42+00:00

Everytime the user visit a page, the page url will be stored into an

  • 0

Everytime the user visit a page, the page url will be stored into an array session. I want to have 10 elements in the array only. So that 10 elements will save 10 latest visited page urls. Here is my codes :

<?php
$currentpageurl = $_GET['username'];

$urlarray=array();

$urlarray[] = $currentpageurl;

$_SESSION['pageurl']=$urlarray;

foreach($_SESSION['pageurl'] as $key=>$value)
    {
    echo 'The value of $_SESSION['."'".$key."'".'] is '."'".$value."'".' <br />';
    }
?>

I tested the code, it always overwrite the element in the array with new visited page, thus it has only 1 element in the array. How to make it not to overwrite the element?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-21T13:52:42+00:00Added an answer on May 21, 2026 at 1:52 pm

    You are always overwriting the array with a new one here:

    $urlarray=array();       // new empty array
    $urlarray[] = $currentpageurl;    
    $_SESSION['pageurl']=$urlarray;
    

    Instead use:

    session_start();
    // like @Kwpolska said, you probably miss that, so $_SESSION didnt work
    
    is_array($_SESSION["pageurl"]) or $_SESSION["pageurl"] = array();
    // fix for your current problem
    
    $_SESSION['pageurl'][] = $currentpageurl;
    // This appends it right onto an array.
    
    $_SESSION["pageurl"] = array_slice($_SESSION["pageurl"], -10);
    // to cut it down to the last 10 elements
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an activity that opens txt files. And everytime a user wants to
I have a photo gallery I would like that every time a user does
I have a DataGridView attached to an XML DataSource. Everytime user edits a cell
I have a webpage that requires login. Once a user has logged in I
I want to set a cookie whenever a user visits a page, so not
I have a table that I want to pick one row from it and
What is the best way to identify a user to visit a page in
I accidentally deleted hadoop.tmp.dir, in my case /tmp/{user.name}/*. Now everytime when I run hive
I want to refresh a table using a SSIS package every time the user
I want to do input validation with jQuery. Every time the user blurs an

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.