Results 1 to 6 of 6

Thread: Losing Session variable on Post

  1. #1
    Join Date
    Jan 2007
    Columbia, MD

    Losing Session variable on Post

    I have been wrestling with this and getting nowhere so I decided to research and ask. The research did not turn up anything so here goes. I have a form that carries a session variable to another form and works fine. I want to have the user keep submitting that form to enter food preferences until they have entered all they choose. When I submit to the same asp page all of a sudden the Session variables disappear. Is there some rule somewhere that posting to the same page erases session variables? Flummoxed!

  2. #2
    Join Date
    Jun 2012
    Dark Side of the Moon
    Session variables should be kept for the entire time the use is connected to the server, or the session times out. Without code, which you should post up if you need more help, I would say that either something is clearing the item, or the session is clearing out. Try to use a global.asa file and put in Session.Timeout = number of minutes you want to keep session. Most default to 20 minutes, but you can set it to whatever you want. If it isn't that, then you will need to look over your code and make sure something isn't resetting them. If you are adding the info to the same variable make sure you are using Session("myitem") = Session("myitem") & mynewstuff . Also you may want to look into cookies, if you have forms with additions over many pages, make the user save the info on their system, then your server doesn't do all the work, and all the info is stored until you need it. Check out this link for help on cookies: http://www.w3schools.com/asp/asp_cookies.asp

  3. #3
    Join Date
    Jan 2008
    My guess is you are setting the variable on that page whether it is already set or not. Like burnme said, you need to post your code.

    You may need to do something like:

    if sessionvalue = "" then
    set sessionvalue here
    end if

  4. #4
    Join Date
    Jan 2007
    Columbia, MD

    losing session variable

    Here is the code guys, thanks for looking at it.

    <%@ Language="VbScript"%>

    <!--#include file="./your_db_path.asp"-->

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">


    <TITLE>Kitchen Karate Add Food Preferences</TITLE>
    <link rel="stylesheet" type="text/css" href="./auth.css">
    <script type="text/javascript" src="js/validateAm.js"></script>
    If Request.ServerVariables("REQUEST_METHOD") = "POST" Then

    'Add choice entered below to a record in database HERE

    'for debug
    Response.Write("Session Fcount is:")
    Response.Write("Session Fmembers is:")

    if (Request.Form("B2")="Finished adding items") then

    'if this person's food is added, check if they are the last person and send to final page
    If (Session("Fcount")= Session("Fmembers")) then
    Response.redirect "http://www.kitchenkarate.com/Members/d_PrintList.asp"
    Response.redirect "http://www.kitchenkarate.com/Members/d_AddFmember.asp"

    end if
    Response.redirect "http://www.kitchenkarate.com/Members/d_AddFoods.asp"
    end if



    <BODY bgColor="#FFFFFF" Background="">

    <span style="width:317px;height:97px;display:inline-block;
    "><img style="
    " src="../images/header-logo-kitchen-karate.png" width="477" height="96" border="0" alt=""></span>
    Kitchen Karate shopping guide

    <style>input{border:solid 1px black}</style>

    <Center><H1><Font Color="#000000">Add Food </Font></H1>
    <% 'set Food = Preference in Foods table %>
    <table border=0 width=420><tr><td>
    <p>This is where you rate food to store your preferences for future use.</td></tr></table>
    <Table border="1" cellpadding="0" cellspacing="0" Align="Center" borderColor="#000000" Background="" >

    <Form Name="Aform" Method="Post" Action="d_AddFoods.asp">

    <input type="hidden" name="Password" value='<%=Session("psw")%>'>
    <TD><Font Face="Arial" Color="#000000">Family of</Font></TD>
    <TD><INPUT Type="text" name="Nuser" value='<%=Session("Uname")%>' ></TD>
    <TD><Font Face="Arial" Color="#000000">FamilyMember</Font></TD>
    <TD><INPUT Type="text" Id="FamilyMembers" name="FamilyMember" value='<%=Session("Fcount")%>' >of <%=Session("Fmembers")%></TD>
    <TD><Font Face="Arial" Color="#000000">Food Item</Font></TD>
    <TD>Preference </TD>
    <TD><select id="food_sel" onclick="document.getElementById('field14').value=
    document.getElementById('food_sel').value;qty14.value='1'" name="txtfood_sel" value="0">
    <option value="Asparagus">Asparagus</option>
    <option value="Broccholi">Broccholi</option>
    <option value="Carrots"> Carrots</option>

    <option value="Chicken">Chicken</option>
    <option value="Pork">Pork</option>
    <option value="Beef">Beef</option>
    <input type="radio" name="Preference" value="1">Avoid<input type="radio" name="Asparagus" value="2">Like<input type="radio" name="Asparagus" value="3">Love


    <TD Align="Center" Colspan="2"><INPUT Type="submit" Value="Add Item" name="B1"></TD>

    <INPUT Type="submit" Value="Finished adding items" name="B2">

    'for debug
    Response.Write("Session Fcount is:")
    Response.Write("Session Fmembers is:")
    End If%>

  5. #5
    Join Date
    Jan 2007
    Columbia, MD

    resolved I found it!

    I was searching for a clue in a php forum on session variables and I saw this:
    "Note that this only affects relative URLs, so if your site includes the http:// part in its URLs it will not work for you."
    I looked and sure enough I had put full URL's in my Response.redirect statements and that is what erased the session and the variables. I changed them to relative and the variables stayed put!

  6. #6
    Join Date
    Jun 2012
    Dark Side of the Moon
    Yep that will do it, when you call out to full path you are asking for it to load it up as if it is new, so you were killing your session by loading a new one.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



X vBulletin 4.2.2 Debug Information

  • Page Generation 0.17680 seconds
  • Memory Usage 2,895KB
  • Queries Executed 15 (?)
More Information
Template Usage (32):
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_global_above_footer
  • (1)ad_global_below_navbar
  • (1)ad_global_header1
  • (1)ad_global_header2
  • (1)ad_navbar_below
  • (1)ad_showthread_firstpost_sig
  • (1)ad_showthread_firstpost_start
  • (1)ad_thread_first_post_content
  • (1)ad_thread_last_post_content
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)headinclude_bottom
  • (6)memberaction_dropdown
  • (1)navbar
  • (4)navbar_link
  • (1)navbar_moderation
  • (1)navbar_noticebit
  • (1)navbar_tabs
  • (2)option
  • (6)postbit
  • (6)postbit_onlinestatus
  • (6)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available (6):
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files (26):
  • ./showthread.php
  • ./global.php
  • ./includes/class_bootstrap.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/functions_navigation.php
  • ./includes/class_friendly_url.php
  • ./includes/class_hook.php
  • ./includes/class_bootstrap_framework.php
  • ./vb/vb.php
  • ./vb/phrase.php
  • ./includes/functions_facebook.php
  • ./includes/functions_calendar.php
  • ./includes/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_notice.php
  • ./packages/vbattach/attach.php
  • ./vb/types.php
  • ./vb/cache.php
  • ./vb/cache/db.php
  • ./vb/cache/observer/db.php
  • ./vb/cache/observer.php 

Hooks Called (72):
  • init_startup
  • friendlyurl_resolve_class
  • init_startup_session_setup_start
  • database_pre_fetch_array
  • database_post_fetch_array
  • init_startup_session_setup_complete
  • global_bootstrap_init_start
  • global_bootstrap_init_complete
  • cache_permissions
  • fetch_postinfo_query
  • fetch_postinfo
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • load_show_variables
  • load_forum_show_variables
  • global_state_check
  • global_bootstrap_complete
  • global_start
  • style_fetch
  • global_setup_complete
  • showthread_start
  • showthread_getinfo
  • strip_bbcode
  • friendlyurl_clean_fragment
  • friendlyurl_geturl
  • forumjump
  • cache_templates
  • cache_templates_process
  • template_register_var
  • template_render_output
  • fetch_template_start
  • fetch_template_complete
  • parse_templates
  • fetch_musername
  • notices_check_start
  • notices_noticebit
  • process_templates_complete
  • friendlyurl_redirect_canonical
  • showthread_post_start
  • showthread_query_postids
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • memberaction_dropdown
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • build_navigation_data
  • build_navigation_array
  • check_navigation_permission
  • process_navigation_links_start
  • process_navigation_links_complete
  • set_navigation_menu_element
  • build_navigation_menudata
  • build_navigation_listdata
  • build_navigation_list
  • set_navigation_tab_main
  • set_navigation_tab_fallback
  • navigation_tab_complete
  • fb_like_button
  • showthread_complete
  • page_templates