parsing order of php url?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • petermichaux@yahoo.com

    #1

    parsing order of php url?

    Hi,

    I'm new to php but having a lot of fun with it writing an e-commerce
    store. I am puzzled by the fact that all of the following URLs open the
    same web page







    Only the right most ProductID number controls the page viewed. Is this
    always the case in PHP5? If it is guaranteed to be the case than I can
    use this to great advantage in tracking the sequence of pages that a
    visiter had viewed.

    Thanks,
    Peter

  • Janwillem Borleffs

    #2
    Re: parsing order of php url?

    petermichaux@ya hoo.com wrote:[color=blue]
    > Only the right most ProductID number controls the page viewed. Is this
    > always the case in PHP5? If it is guaranteed to be the case than I can
    > use this to great advantage in tracking the sequence of pages that a
    > visiter had viewed.
    >[/color]

    It will be the case as long as the $_POST, $_GET and $_REQUEST superglobals
    are defined as associative arrays, where the last key overwrites previous
    ones when equally named.

    On the other hand, I think it's not a good idea to base your solution on
    this behaviour, because it may be subject to future changes.

    A more reliable way of seeing on which pages your visitor has been is to use
    sessions.


    JW




    Comment

    • petermichaux@yahoo.com

      #3
      Re: parsing order of php url?

      Thanks for the reply. I thought that using sessions would probably be a
      better solution. The only thing is I won't know how many pages they
      have visited so i would have to either make a big array and hope it
      does not overflow or I have to make a last in first out stack. but then
      I'm worried if they use the back button I will not know where they are.
      Any references or links on how to do this?

      Peter

      Comment

      • Ken Robinson

        #4
        Re: parsing order of php url?


        petermich...@ya hoo.com wrote:[color=blue]
        > Thanks for the reply. I thought that using sessions would probably be[/color]
        a[color=blue]
        > better solution. The only thing is I won't know how many pages they
        > have visited so i would have to either make a big array and hope it
        > does not overflow or I have to make a last in first out stack. but[/color]
        then[color=blue]
        > I'm worried if they use the back button I will not know where they[/color]
        are.[color=blue]
        > Any references or links on how to do this?[/color]

        Arrays in PHP do not have a pre-defined size, so you don't have to
        worry about the size of the array, except if you use up available
        memory. If a user uses the back button, you would not know where they
        are using your scheme either. Also, as with any parameter passed via
        the URL, your tracking can be faked.

        Ken

        Comment

        • petermichaux@yahoo.com

          #5
          Re: parsing order of php url?

          Thanks, Ken. I'm used to C and allocating memory for arrays. So I can
          use a session array to track the list of pages served to the visitor.
          But what if they press the back button? How do I know to move back up
          one in my array to display a horizontal list of links for how they got
          to the category they are in? eg

          You are viewing category:
          Automotive>Tire s>CarTires

          Then they press back and then pick truck tires. I do not want the
          horizontal list to say
          Automotive>Tire s>CarTires>Truc kTires

          becaue car tires was never removed from the array or I didn't know to
          change a session variable called $currentListInd ex from 3 to 2 (or 2
          to 1 if arrays start with 0) when they pressed the back button. Make
          sense?

          Thanks,
          Peter

          Comment

          • Justin Koivisto

            #6
            Re: parsing order of php url?

            petermichaux@ya hoo.com wrote:
            [color=blue]
            > Thanks for the reply. I thought that using sessions would probably be a
            > better solution. The only thing is I won't know how many pages they
            > have visited so i would have to either make a big array and hope it
            > does not overflow or I have to make a last in first out stack. but then
            > I'm worried if they use the back button I will not know where they are.
            > Any references or links on how to do this?
            >
            > Peter
            >[/color]

            At each page, you could do something like:
            $_SESSION['trail'][]=$_GET['ProductID'];

            When they hit the back button, I believe that some browsers will
            actually add another entry into the array, so you might have something like:

            .... 13, 45, 13 ...

            Indicating that the user was on page 13, then clicked to 45, then hit
            the back button. Watch out though, many people like to open multiple
            windows (or tabs) when browsing, so that will give you some pretty awful
            results.

            --
            Justin Koivisto - justin@koivi.co m

            Comment

            • petermichaux@yahoo.com

              #7
              Re: parsing order of php url?

              Ahh. Multiple browsers.

              Perhaps I could write the series of categoryID used to get to the
              current category directly in the web page. Somehow this would be
              invisible to the user. Then when they click a new link their browser
              sends me this series and I can append to it. This is a job for
              javascript? And if they press the back button then the page they go
              back to will have the correct series for that page. Sound good?

              Comment

              • Chung Leong

                #8
                Re: parsing order of php url?

                Yes, the left to right evaluation order of GET variables is a
                documented feature of PHP.

                A more efficient method it seems, would be to concat the ids like so:



                Comment

                • Justin Koivisto

                  #9
                  Re: parsing order of php url?

                  petermichaux@ya hoo.com wrote:
                  [color=blue]
                  > Ahh. Multiple browsers.
                  >
                  > Perhaps I could write the series of categoryID used to get to the
                  > current category directly in the web page. Somehow this would be
                  > invisible to the user. Then when they click a new link their browser
                  > sends me this series and I can append to it. This is a job for
                  > javascript? And if they press the back button then the page they go
                  > back to will have the correct series for that page. Sound good?
                  >[/color]

                  If I am using some kind of breadcrumb, I tend to take the easy route:

                  Say I was viewing Truck tires (as in your previous example), my URI
                  would look like this:

                  /automotive/tires/truck/

                  Then for the breadcrumb, I'll just do something similar to:

                  <?php
                  $tmp=explode('/',$_SERVER['REQUEST_URI']);
                  $num_levels=cou nt($tmp);
                  $nav=array();
                  for($i=$num_lev els-1;$i>0;$i--){
                  if(empty($tmp[$i])){
                  // in case there were two slashes together
                  // in the URI, or if it ended with a slash.
                  // **this will not add the top level link "/"
                  array_pop($tmp) ;
                  continue;
                  }else{
                  // if URI started with a slash, then the first
                  // element will be empty, leaving us with the
                  // leading slash.
                  $nav[]='<a href="'.join('/',$tmp).'/">'.
                  ucwords($tmp[$i]).'</a>';
                  array_pop($tmp) ;
                  }
                  }
                  $nav=array_reve rse($nav);
                  echo join(" &raquo; ",$nav);
                  ?>

                  --
                  Justin Koivisto - justin@koivi.co m

                  Comment

                  • petermichaux@yahoo.com

                    #10
                    Re: parsing order of php url?

                    Thanks Justin! I think i will do something like what you suggested
                    along with Chung Leong's post. I will explode a couple times to isolate
                    the concat CategoryID and then explode on the comma to get an array of
                    category ID's for something like the following link



                    Sound ok?

                    Is there an easier way to get the concat CategoryID ("21,22,23")
                    without having to explode cleverly a couple times incase some more text
                    follows in the url?

                    Thanks again,
                    Peter

                    Comment

                    Working...