Jump to content

[SOLVED] PHP captcha script on form...with form handler being an ASP file - possible?


plastik77

Recommended Posts

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.

Link to comment
Share on other sites

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???

 

Link to comment
Share on other sites

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!";

  }

?>

 

 

Link to comment
Share on other sites

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

%>

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.