This topic is locked
[SOLVED]

 Login form and running code before allowing user to logo

5/24/2011 11:56:10
ASPRunnerPro General questions
B
beachldy author

On the login page, I'm wanting to add code to check a string in a table and compare it to a string in the current url displayed.
I'm getting a syntax error on the function called curPageURL() and don't know why. This code is in "before login" on the login page.
----------------------------------------------------------------------------------------------------

strSQL = "SELECT KP from tblK"

set rs = CreateObject("ADODB.Recordset")

rs.Open strSQL, dbConnection

if not rs.eof then

session("Key")= rs("KP")

else

session("Key") = ""

end if

rs.Close : set rs = Nothing
Dim dash, underscore, plus,Ot

Dim dt, tp, webst, msg
dash = instr(Session("Key"),"-")

underscore = instr(Session("Key"),"_")

plus = instr(Session("Key"),"+")

ot = instr(Session("Key"),"#")
dt = mid(session("Key"),dash + 1,6)

tp= mid(session("Key"),underscore +1,1)

webst = mid(session("Key"),plus + 1, ot)
'**

function curPageURL()

dim s, protocol, port
if Request.ServerVariables("HTTPS") = "on" then

s = "s"

else

s = ""

end if
protocol = strleft(LCase(Request.ServerVariables("SERVER_PROTOCOL")), "/") & s
if Request.ServerVariables("SERVER_PORT") = "80" then

port = ""

else

port = ":" & Request.ServerVariables("SERVER_PORT")

end if
curPageURL = protocol & "://" & Request.ServerVariables("SERVERNAME") &

port & Request.ServerVariables("SCRIPT_NAME")

end function

'****

function strLeft(str1,str2)

strLeft = Left(str1,InStr(str1,str2)-1)

end function
'****

If Session("Key") <> "" then

If Instr(curPageURL(),webst) <> 0 then

msg = "Invalid"

beforelogin= false

Else

msg = "Validated"

beforelogin = true

End If

Else:

msg = "NA"

End If

-----------------------------------------------------------------------------
Then I'm also wanting to display a message on the page if login is not permitted.

Response.Write(msg)...but not sure where to put it. I'm learning where code goes a bit at a time, but still a newbie at it. Any help would be appreciated.

Sergey Kornilov admin 5/24/2011

I would suggest to move your ASP functions to a separate ASP file. Here is how you can do this: http://xlinesoft.com/asprunnerpro/docs/how_to_add_external_files.htm

B
beachldy author 5/24/2011

I moved both functions to a file named Reg.asp. When I add the include_asp in the login form under any event, (there is no "before table initialized" event), I get this error:
File could not be opened.

/Project5/include/aspfunctions.asp, line 2852
Evidently, I have to put my code in aspfunctions.asp?

B
beachldy author 5/24/2011

I put the code in the aspfunctions.asp page.
But I get this error:
Type mismatch: 'curPageURL'
code is same as above (less the functions, which were moved to aspfunctions.asp).
Maybe there's an easier way to get the current URL of a page?

B
beachldy author 5/24/2011

Never mind about the last 2 replies. Thanks.

B
beachldy author 5/24/2011

Ok, I added the code the aspfunctions.asp, but whatever I add to that just disappears after I build the project. SO, we're back to not getting my asp code to work in a separate page OR within aspfunctions.asp.