Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    Regular Coder
    Join Date
    Nov 2007
    Posts
    682
    Thanks
    319
    Thanked 1 Time in 1 Post

    Sessions and HTA

    I'm using a HTA file for a little application i'm coding. In the HTA code all there is is an iframe which is loading the main page (not needed now tbf I need to change it)

    Here is the main page code, I make ajax calls to ASP files to run Server Side code as ASP code doesn't seem to work if it's run in the HTA file.

    Code:
    <body onload="checkErrors();">
    <!--<input type="button" onClick="listDrives()" value="Search for devices"><br/ >-->
    	<div class="dialog" id="dialog" style="visibility:hidden;"></div>
        <div class="blackout" id="blackout" style="visibility:hidden;"></div>
        
        <div id="main">
            
        </div>
        <a href="#" onclick="checkLogin()">DO</a>
    	<div class="bottom_bar">&copy; Copyright Martyn Lee Ball - Nightclub Photography Sales Application</div>
    </body>
    </html>
    checkLogin()
    PHP Code:
    function checkLogin() {
        var 
    http xmlhttp();
        
    http.onreadystatechange = function() {
            if (
    http.readyState == && http.status == 200) {
                
    doc("main").innerHTML http.responseText;    
            } else {
                
    doc("main").innerHTML "Loading...";    
            }
        }
        
    http.open("GET""http://localhost/nightclub_photography/checkLogin.asp");
        
    http.send();

    checkLogin.asp
    PHP Code:
    <%
    uid session("uid")

    if 
    uid "" then
    %>
    <!--
    #include virtual="\nightclub_photography\login_page.asp"-->
    <%
    else
    %>
    <!--
    #include virtual="\nightclub_photography\content.asp"-->
    <%
    end if
    %> 
    If I load the iframe page into Internet Explorer or Chrome, the code DOES work and the session is infact set. It is also set when the call is made to the login.asp (below) page as I made it return the session variable as a string.

    PHP Code:
    <!--#include virtual="\nightclub_photography\asp\md5.asp"-->

    <%
    'Retreive the URL variables'
    email Trim(request.querystring("email"))
    password request.querystring("password")

    'Check the data has been entered into the fields'
    if email "" then
        response
    .write "Error: Please enter your email!"
        
    response.End
    End 
    If
    If 
    password "" then
        response
    .write "Error: Please enter a password!"
        
    response.End
    End 
    If

    query "select * from users WHERE email = '" email "'"

    'Create connection and load users database
    set conn=Server.CreateObject("ADODB.Connection")
    conn.Provider="Microsoft.ACE.OLEDB.12.0"
    conn.Open Server.MapPath("/nightclub_photography/data/database/users.mdb")

    set rs=Server.CreateObject("ADODB.recordset")
    rs.Open query, conn

    '
    Check if the username matchs in the database
    if rs.EOF then
        response
    .write("Error: Login details incorrect!")
    else
        if 
    md5(password) = rs.Fields("password"then
            
    'Fetch, and capitlize name
            full_name = ucase(mid(rs.Fields("fname"),1,1))&mid(rs.Fields("fname"),2)&" "
            full_name = full_name + ucase(mid(rs.Fields("sname"),1,1))&mid(rs.Fields("sname"),2)
            
            '
    Set session variables
            session
    ("perms") = rs.Fields("perms")
            
    application("uid") = full_name
            session
    ("sid") = session.SessionID
            
            Write message 
    and create cookies for session
            response
    .write("Message: Login Successful!")
        else
            
    response.write("Error: Login details incorrect!")
        
    end if
    end if
    %> 
    My issue is that once the ajax sends a request to the checkLogin.asp the session doesn't seem to exist :S

  • #2
    Regular Coder
    Join Date
    May 2012
    Location
    USA
    Posts
    102
    Thanks
    0
    Thanked 7 Times in 7 Posts
    The session value expires as soon as the Ajax request is sent, so you may encounter some issues during login.

  • #3
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,506
    Thanks
    77
    Thanked 4,378 Times in 4,343 Posts
    Quote Originally Posted by annaharris View Post
    The session value expires as soon as the Ajax request is sent, so you may encounter some issues during login.
    That's the dumbest comment you've made yet.

    It may be true that the AJAX request and the main page don't share the same session, but I guarantee that simply sending an AJAX request won't change the main page session timeout.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.


  •  

    Posting Permissions

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