Creating a history list, preventing multiples
<p>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:</p>

<pre><code>main01
main02
main03
main04
main05
main03
main04
</code></pre>

<p>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:</p>

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


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


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

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

}

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

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

}
</code></pre>

<p>how can I get this working correctly? Any help would be appreciated. </p>

<p>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?</p>

<p>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:</p>

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

        }
</code></pre>

<p>and now the array looks like this whenever I visit previous pages: </p>

<pre><code>Array
(
[0] =&gt; main01
[1] =&gt; main02
[2] =&gt; main03
[3] =&gt; main04
[4] =&gt; main03
)
</code></pre>
