How to redirect a page after 3 views

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • webandwe
    New Member
    • Oct 2006
    • 142

    How to redirect a page after 3 views

    Hi,

    I have page x. when you try to visit page x for the 3rd time it must go to page y?

    I have no idea how this work or should work, can someone please give me some ideas, as I say I don't even know the first line of coding as I never tried, seen or work with something like this.

    I will be able to do it with cookies, but if the persons disable his cookies then it will not work and I need to make it php.

    Kind Regards
    Louwrens
  • shoonya
    New Member
    • May 2007
    • 160

    #2
    okk

    if you dont want to use cookies then you may have to use data base
    because even the php sessions maintains the cookie
    you can have a temporary counter in database and increment it every time a user views the page
    and then redirect him accordingly

    but then even simple refreshing will increase the count

    shoonya

    Comment

    • Atli
      Recognized Expert Expert
      • Nov 2006
      • 5062

      #3
      I would recommend using Sessions. Although, as shoonya said, they use cookies, they will work even if cookies are disabled. Sessions can go as far as hashing the session ID into the URL before giving up.

      This is incredibly simple using Sessions. For example:
      [code=php]
      // Start session
      session_start() ;

      // Check if the session var exists.
      if(isset($_SESS ION['visitCount'])){
      // Increment the count
      $_SESSION['visitCount'] += 1;

      // Check if it has reached the max (3)
      if($_SESSION['visitCount'] >= 3) {
      header("Locatio n: www.google.com" );
      }
      }

      // Create the session var
      else {
      $_SESSION['visitCount'] = 1;
      }
      [/code]

      Comment

      • shoonya
        New Member
        • May 2007
        • 160

        #4
        @ atil

        how will the php session handler react, when the cookies are deleted while the session is alive ??

        shoonya

        Comment

        • webandwe
          New Member
          • Oct 2006
          • 142

          #5
          Thanks Atil,



          (this message is not to short)

          Comment

          • Atli
            Recognized Expert Expert
            • Nov 2006
            • 5062

            #6
            Happy to help.

            @ shoonya
            PHP, as a sever-side language, can manipulate HTTP Headers, and so it can use HTTP POST and GET to pass along the SESSIONID.
            It is not uncommon to see the PHPSESSIONID variable being passed in the URL when browsing a PHP page, as the Cookie is somewhat unreliable and can apparently be left out, which PHP reacts to by passing the ID by alternate means.

            Comment

            Working...