plastik77 Posted July 27, 2007 Share Posted July 27, 2007 Probably a ridiculous question...but I've got a php script running on a web email form which checks the captcha entry entered by the user is correct. The form handling script i've been using is actually an ASP file, therefore the form action directs to the ASP file. Is there any way I can call the PHP script to validate the captcha entry before directing to the ASP file? I'm doubtful this is possible, but would be grateful for any feedback before I go off looking for an ASP captcha script. Many thanks. Quote Link to comment Share on other sites More sharing options...
Adrianphp Posted July 27, 2007 Share Posted July 27, 2007 Probably a ridiculous question...but I've got a php script running on a web email form which checks the captcha entry entered by the user is correct. The form handling script i've been using is actually an ASP file, therefore the form action directs to the ASP file. Is there any way I can call the PHP script to validate the captcha entry before directing to the ASP file? I'm doubtful this is possible, but would be grateful for any feedback before I go off looking for an ASP captcha script. Many thanks. the captcha PHP script that generates the picture should store the value of the validation code in a cookie, then the ASP script should check for the cookie and compare it with the value of the verification field. hope this helps??? Quote Link to comment Share on other sites More sharing options...
plastik77 Posted July 27, 2007 Author Share Posted July 27, 2007 thanks for the reply - i'm fairly new to PHP (and haven't used ASP before), so i'm not quite sure how to do what you suggest. here are a few snippets of the relevant code as it stands - the captcha script works in isolation, as does the asp script, but i'm obviously not combining them properly. any further help would be greatly appreciated <?php session_start(); $ts = time(); ?> ......... <script language="JavaScript"><!-- ts = <?= $ts ?>; </script> ...... <form method="post" onSubmit="return validateFormOnSubmit(this)" action="http://www.staloysius.org/html/request_prospectus/sendmail.asp"> //captcha display and input fields <img id="__code__" src="code.php?id=<?= $ts ?>" /><br><a href="no_matter" onClick="document.getElementById('__code__').src = 'code.php?id=' + ++ts; return false">click for new code</a></p> <p><input type="text" name="code" /> <input name="Submit" type="submit" class="style6" value="Send Enquiry"> </form> <? if (isset($_POST['code'])) { if (md5(strtoupper($_POST['code'])) != $_SESSION['__img_code__']) echo "Invalid submission!"; } ?> Quote Link to comment Share on other sites More sharing options...
Adrianphp Posted July 27, 2007 Share Posted July 27, 2007 i see... so you cannot modify the ASP code. in this case maybe you should try using a client-side Captcha validator like http://www.archreality.com/jcap/index.shtml other solutions may be using a dummy page between the form and the ASP file to have a server-side validator process or using AJAX, but these are more complicated ways. Quote Link to comment Share on other sites More sharing options...
plastik77 Posted July 27, 2007 Author Share Posted July 27, 2007 sorry adrian - i do actually have access to the ASP script....here it is, although i'm not sure how to retrieve the cookie from the captcha script <% option explicit function getTextFromFile(path) dim fso, f, txt set fso = createobject("Scripting.FileSystemObject") if not fso.fileexists(path) then getTextFromFile = "" exit function end if set f = fso.opentextfile(path,1) if f.atendofstream then txt = "" else txt = f.readall f.close set f = nothing set fso = nothing getTextFromFile = txt end function dim redir, mailto, mailfrom, subject, item, body, cc, bcc, message, html, template, usetemplate, testmode redir = request.form("redirect") mailto = request.form("mailto") mailfrom = request.form("mailfrom") subject = request.form("subject") template = request.form("template") if len(template) > 0 then template = getTextFromFile(server.mappath(template)) if len(template) > 0 then usetemplate = true else usetemplate = false dim msg : set msg = server.createobject("CDONTS.NewMail") if usetemplate and lcase(request.form("html")) = "yes" then msg.bodyformat = 0 '(html) msg.mailformat = 0 '(mime) end if msg.subject = subject msg.to = mailto msg.from = mailfrom if len(cc) > 0 then msg.cc = cc if len(bcc) > 0 then msg.bcc = bcc if not usetemplate then body = body & message & vbcrlf & vbcrlf else body = template end if for each item in request.form select case item case "redirect", "mailto", "cc", "bcc", "subject", "message", "template", "html", "testmode" case else if not usetemplate then if item <> "mailfrom" then body = body & item & ": " & request.form(item) & vbcrlf & vbcrlf else body = replace(body, "[$" & item & "$]", replace(request.form(item),vbcrlf,"<br>")) end if end select next if usetemplate then 'remove any leftover placeholders dim rx : set rx = new regexp rx.pattern = "\[\$.*\$\]" rx.global = true body = rx.replace(body, "") end if msg.body = body if testmode then if lcase(request.form("html")) = "yes" then response.write "<pre>" & vbcrlf response.write "Mail to: " & mailto & vbcrlf response.write "Mail from: " & mailfrom & vbcrlf if len(cc) > 0 then response.write "Cc: " & cc & vbcrlf if len(bcc) > 0 then response.write "Bcc: " & bcc & vbcrlf response.write "Subject: " & subject & vbcrlf & string(80,"-") & "</pre>" response.write body else response.write "<html><head><title>Sendmail.asp Test Mode</title></head><body><pre>" & vbcrlf response.write "Mail to: " & mailto & vbcrlf response.write "Mail from: " & mailfrom & vbcrlf if len(cc) > 0 then response.write "Cc: " & cc & vbcrlf if len(bcc) > 0 then response.write "Bcc: " & bcc & vbcrlf response.write "Subject: " & subject & vbcrlf & vbcrlf response.write string(80,"-") & vbcrlf & vbcrlf & "<span style=""color:blue;"">" response.write body & "</span>" & vbcrlf & vbcrlf response.write string(80,"-") & vbcrlf & "**END OF EMAIL**</pre></body></html>" end if else msg.send response.redirect redir end if set msg = nothing %> Quote Link to comment Share on other sites More sharing options...
plastik77 Posted July 30, 2007 Author Share Posted July 30, 2007 thanks for your help adrian - i decided to use the client side captcha script you provided and this works fine. i'll leave the php/asp link up for another day. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.