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 8648021
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T13:13:00+00:00 2026-06-12T13:13:00+00:00

Im creating a website and one of the features is on the side it

  • 0

Im creating a website and one of the features is on the side it will show the user the pages they’ve visited since they got to the website, and they can click any of those names and get it to take them back to that page. I have it working, however when they click back to a certain page if they click through them again it writes out the repeat pages. for instance if say we have 10 pages, main01 to main10. The user gets to page main05, and decides he wants to go back to main03, he click main03 on his history list and goes there just fine, decides he wants to keep going and clicks “continue” this brings him to page main04, which is fine. But the history list becomes:

main01
main02
main03
main04
main05
main03
main04

so what I’ve tried to do is create a method that checks to see if the page visited has already been added to the array, if it has been then it should just echo nothing. if it hasnt then it echos the correct link. but whenever I try it now it just displays the last page you visited, and overwrites that every time you change pages. Here is my code:

    if($_POST['visited']){
    $_SESSION['visitedpages'][$_SESSION['i']] = $_POST['visited'];
    $_SESSION['i']++;
    echo "<pre>";
    print_r($_SESSION['visitedpages']);
    echo "</pre>";
}


if($_SESSION['visitedpages']){
    $a_length = count($_SESSION['visitedpages']);
    for($x = 0; $x < $a_length; $x++){


        $name = $_SESSION['visitedpages'][$x];
        $exists = checkifexists($name, $a_length);

        if(!$exists){
        echo "<a href=\"$name.php\">$name</a><br />";
        }
        else{
        echo "";
        }
    }

}

function checkifexists($name, $a_length){
    for($z = 0; $z < $a_length;$z++){

        $existingname = $_SESSION['visitedpages'][$z-1];
        if($name === $existingname) {
            return true;
        }
    }
    return false;

}

how can I get this working correctly? Any help would be appreciated.

EDIT: Actually it looks like I got it working by checking if it exists when its being written to the array, rather than when its being written as a link. However now whenever I click the link to visit the page (for instance main03 from main05) it goes to main03 but the history list doesn’t display, any input on this?

EDIT2: So I changed it, using in_array, per your suggestion, and its displaying properly but its still listing duplicates. here is the code Im using:

            if(in_array($_POSTED['visited'],$_SESSION['visitedpages'])){
            echo "";
        }
        else{
            $_SESSION['visitedpages'][$_SESSION['i']] = $_POST['visited'];
            $_SESSION['i']++;
            echo "<pre>";
            print_r($_SESSION['visitedpages']);
            echo "</pre>";
            $arrayinit = true;

        }

and now the array looks like this whenever I visit previous pages:

Array
(
[0] => main01
[1] => main02
[2] => main03
[3] => main04
[4] => main03
)
  • 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-06-12T13:13:01+00:00Added an answer on June 12, 2026 at 1:13 pm

    You need to check your checkifexists function.

    You’re checking to see if this page has already been mentioned; if it has, then return true. But what you’re doing is going through the whole of $_SESSION['visitedpages'] to see if a page is in there, and of course it is.

    Try calling it with:

    $exists = checkifexists($name, $x - 1);
    

    Then you’ll just check elements earlier in the array to see if they’re duplicates.

    For what it’s worth, you might be able to do this more efficiently with in_array

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I m creating a Website as Static HTML pages. In that only in one
I am creating a website where there are two user intefaces. ONe for sellers
I'm creating a website for a kiosk. I've got 3 divs on one page,
I'm creating a website and part of the functionality is that a user can
I am creating one website where all pages are creating in html but dynamic
im creating a website that requires user authorisation to access some features. im currently
In the app I'm creating, one of the features is that users can submit
So I am creating a website using Django templates, forms etc. One thing I've
I am creating a website that will allow people to make lists, but I'm
I'm creating a website in which I will be managing users and their permissions.

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.