SitePoint Sponsor

User Tag List

Results 1 to 11 of 11
  1. #1
    SitePoint Addict
    Join Date
    Jul 2005
    Posts
    215
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Put URL into the Array...

    Hi All,
    I am trying to create Navigation Trail, so as Clicks are made from One (Php Page) to Another, the URL needs to be Copy and stored into the array.

    Any headstart will be great.
    Thanks.

  2. #2
    Keep it simple, stupid! bokehman's Avatar
    Join Date
    Jul 2005
    Posts
    1,935
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You need a method to identify the user from page to page (sessions or IP) and a method of storage (either the file sytem or a datebase). Once you have established that the code is very simple.

  3. #3
    SitePoint Addict
    Join Date
    Jul 2005
    Posts
    215
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Actually Page retrives data from the Database, Example Cars:

    Such as Cars -> GM -> Oldsmobiles -> Cutless -> 1999
    or Cars -> Honda -> Pilot -> Yr 2000
    or Cars -> Toyota -> Camry -> yr 2000
    etc. etc. etc.

    I just want to know how to copy URL & put into the Array which will be created on the fly an not stored into the database.

    Thanks.

  4. #4
    SitePoint Wizard silver trophy
    Join Date
    Mar 2006
    Posts
    6,132
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
    <?php
    session_start
    ();
    $_SESSION['history'][] = $_SERVER['PHP_SELF'];
    // or maybe this if you need the query string
    $_SESSION['history'][] = $_SERVER['REQUEST_URI'];
    ?>

  5. #5
    SitePoint Addict
    Join Date
    Jul 2005
    Posts
    215
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks a lot.

    I need to try this out.

  6. #6
    SitePoint Addict
    Join Date
    Jul 2005
    Posts
    215
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    clamcrusher Wrote:
    <?php
    session_start();
    $_SESSION['history'][] = $_SERVER['PHP_SELF'];
    ?>
    So I started new session and I presume it stores URL in the Session ($_SESSION['history'][]) variable, how can I print this variable???

    I did try following:
    PHP Code:
        session_start(); 
        
    $_SESSION['history'][] = $_SERVER['PHP_SELF']; 
        
    $test = array($_SESSION['history']);
                 echo 
    $test
    But it does not print the array. I need to print the URL as many time as php page is submitted to itself.
    Thanks.

  7. #7
    dooby dooby doo silver trophybronze trophy
    spikeZ's Avatar
    Join Date
    Aug 2004
    Location
    Manchester UK
    Posts
    13,804
    Mentioned
    157 Post(s)
    Tagged
    3 Thread(s)
    PHP Code:
    foreach($_SESSION['history'] as $output) {
    echo 
    $output;

    Just as a basic output. You an then refine it to add your >> bits
    Mike Swiffin - Community Team Advisor
    Only a woman can read between the lines of a one word answer.....

  8. #8
    SitePoint Addict CommanderZ's Avatar
    Join Date
    Apr 2006
    Location
    Czech Republic
    Posts
    236
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by jjdave
    But it does not print the array. I need to print the URL as many time as php page is submitted to itself.
    Thanks.
    You must use something like for...each cycle to print all the adresses

  9. #9
    SitePoint Addict
    Join Date
    Jul 2005
    Posts
    215
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thank You.

    For...Each cycle works well.

    There is one BUT. When I Refresh (the page) or use Brower Buttons (Back or Forward) it also appends those URLs as well. Is there a any way to trap that error?

    Thanks a lot. I did achieve my objective with For...Each.

  10. #10
    SitePoint Wizard silver trophy
    Join Date
    Mar 2006
    Posts
    6,132
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    it depends how you want to eliminate the duplicate entrys.

    by default, the array entries will be sorted in the order they were added to the array.

    some ways to do it:

    use array_unique()
    this may affect the sort order in a way that may be desireable, or not desireable to you.

    another way could be only add an entry to the history if it does not already exist

    PHP Code:

    if (!in_array($_SERVER['PHP_SELF'], $_SESSION['history'])) {
        
    $_SESSION['history'][] = $_SERVER['PHP_SELF'];


    but doing these things are now making this into a list of visited pages, not a history of their click path. im not sure if thats what you want.

  11. #11
    SitePoint Addict
    Join Date
    Jul 2005
    Posts
    215
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    clamcrusher Wrote:
    but doing these things are now making this into a list of visited pages, not a history of their click path. im not sure if thats what you want.
    You are correct, I do not want List but I do want Click Path.

    You all have given me main Points or Proper Sentex. Now I need to plug in the info properly.

    Thank You.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •