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

  • Home
  • SEARCH
  • 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 a old website that generate its own RSS everytime a new post
I have a webpage that requires login. Once a user has logged in I
Is there anyway to save a URL with NSUserDefaults without setURL:forKey: that is only
In my WinForms app, data can be printed on many locations. Everytime the user
Every time a user posts something containing < or > in a page in
Everytime i retrieve data from a mysql stored procedure with a concat function an
If I want to keep an xml file updated with all the images that
I'm trying to do this update_activity_time everytime a user does something in the app.
I would like to save the programs settings every time the user exits the
Everytime I upload a file to my ASP.NET site, all users are logged out

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.