Notices

Great community. Great ideas.

Welcome to ASP/Free, a community dedicated to helping beginners and professionals alike in improving their knowledge of Microsoft's development and administration technologies. Sign up today to gain access to the combined insight of tens of thousands of members.

Thread: Incrementing a session variable on page load

Results 1 to 4 of 4
Share This Thread →
  1. #1
    AndrewT is offline Contributing User
    Join Date
    Mar 2008
    Posts
    341
    Rep Power
    8

    Incrementing a session variable on page load

    Can anyone tell me how I might be able to increment a session variable by 1 each time a page loads. I want to find a way to keep track of how many times a user accesses a set of pages then once they have reached a certain number to be able to re-directed them elsewhere. I have an idea to put something like the code below on each page but am not sure how to make the session variable increment?

    Code:
    <% If Session("User_Restricted") > 0 Then %>
    
    Add 1 to Session("User_Restricted")
    
    <% ElseIf Session("User_Restricted") = 10 Then %>
    
    Do this
    
    <% Else %>
    
    Do nothing
    
    <% End If %>

  2. #2
    gk53's Avatar
    gk53 is online now Contributing User
    Join Date
    Mar 2005
    Location
    Columbus, OH
    Posts
    1,542
    Rep Power
    278
    like that
    Code:
    <% 
    If Session("User_Restricted") ="" then
          Session("User_Restricted") =0
    end if
    
    Session("User_Restricted")  = Session("User_Restricted")  + 1
    
    If Session("User_Restricted") = 10 Then 
           response.redirect "overLimit.asp"
    end if
    %>
    GK
    __________________________________________________ _____
    if you found this post is useful click Give Rep button (bottom side on this reply ) and agree

  3. #3
    sqlconfused is offline Contributing User
    Join Date
    Oct 2012
    Posts
    49
    Rep Power
    2
    The thing is if someone closes the browser they can go back for 10 more views. I gather you want something like Plenty of Fish where you can view profiles xx number of times and then for the next 15 minutes are redirected to one page (in the POF case a Signup page).

    I had such a script written before, it logged the IP addresses in a database and purged them after 15 minutes. Alas the code is long gone but it's certainly not difficult to do if you need code samples.

  4. #4
    gk53's Avatar
    gk53 is online now Contributing User
    Join Date
    Mar 2005
    Location
    Columbus, OH
    Posts
    1,542
    Rep Power
    278
    in this case would be better to set cookies with number of retries and last retry time. and work on that. logging ip addresses did not give you actual computer. If it is from local network all computers will have the same ip... So you count attempts not from computer, but from router...

Share This Thread →

Become Part of This Conversation

Join NowFor Free!

Similar Threads

  1. Session in Page Load problems
    By akpaga in forum .NET Development
    Replies: 3
    Last Post: November 4th, 2010, 03:12 AM
  2. Passing session variable from login page..
    By captainzorro in forum ASP Development
    Replies: 0
    Last Post: March 27th, 2008, 02:28 PM
  3. Setting session variable when loading page..
    By peoplayer in forum ASP Development
    Replies: 2
    Last Post: May 2nd, 2006, 12:47 PM
  4. Replies: 3
    Last Post: May 9th, 2005, 05:32 AM
  5. How to load external web page into an array/variable
    By jnmunsey in forum ASP Development
    Replies: 3
    Last Post: April 20th, 2005, 02:24 PM

ASP Free Advertisers and Affiliates