Skip to main content
October 25, 2006
Answered

Need to retrieve the actual text of a URL and store to a variable

  • October 25, 2006
  • 4 replies
  • 524 views
Looking for some advice here, I can do this in PHP but I'm too new to CF to know it yet. To pass from PHP to CF would mean sending these variables back through the web URL which I want to avoid.

Basically I have a precompiled java module that I have to use that returns a Y or N to verify authentication.
I need to create the following scenerio:

Display Form with username and password;
Capture username as UserID and password as Password
Retrieve Y or N from the screen from URL http:/intranet/servlet/WebLogin?UserID=XXX&Password=YYY
Store verification result as a global variable

My attempt at CF:
<cfform name="loginform" action="http:/intranet/servlet/WebLogin"
method="Get">
<table>
<tr>
<td>username:</td>
<td><cfinput type="text" name="UserID" required="yes"
message="A username is required"></td>
</tr>
<tr>
<td>password:</td>
<td><cfinput type="password" name="Password" required="yes"
message="A password is required"></td>
</tr>
</table>
<br>
<input type="submit" value="Log In">
</cfform>

--This code works to redirect the screen the URL displaying Y or N, but how I can't grab the result and store it =(


:My PHP code to do this (works completely)
<?PHP

$url = 'http:/intranet/servlet/WebLogin?UserID=XXX&Password=YYY';
$html = file_get_contents($url);
if(preg_match('/Y/', $html, $matches))
{
echo "success";
}
else
{
echo "no success";
}
?>


Thanks all
This topic has been closed for replies.
Correct answer
quote:

Originally posted by: nborton
... ...
Retrieve Y or N from the screen from URL http:/intranet/servlet/WebLogin?UserID=XXX&Password=YYY


Galloping Gargoyles!! There are so many things wrong here!

Anyway, if you are stuck with this approach, you will need to use cfhttp to get the result.

Something like the attached code should get you started.


Edit: fix IsDefined syntax error...

4 replies

October 26, 2006
Thanks,

I read through that commands syntax, but didn't get that out of it. And don't worry about the password going out, it's just going to be for all Mastercard verification =) I'll be able to encapsulate it in SSL, but unfortunately I can't call my JRUN instance from CF, and for reasons unknown to me, I can't have a license code to say both are ok on the same instance =(

Your solution to capture worked. Although your code as above did not run, I get a loginbtn is not defined in form. I noticed that when using a post form I get the same error if I try and reference form variables before the <form></form> sequence. Is there a server setting I should have on to allow this?
October 26, 2006
quote:

Originally posted by: nborton
Your solution to capture worked. Although your code as above did not run, I get a loginbtn is not defined in form. I noticed that when using a post form I get the same error if I try and reference form variables before the <form></form> sequence. Is there a server setting I should have on to allow this?



Sorry.... Hazards of not testing code.
I had a syntax error, <CFIF NOT IsDefined (FORM.loginBtn)> should have been <CFIF NOT IsDefined ("FORM.loginBtn")>
Correct answer
October 26, 2006
quote:

Originally posted by: nborton
... ...
Retrieve Y or N from the screen from URL http:/intranet/servlet/WebLogin?UserID=XXX&Password=YYY


Galloping Gargoyles!! There are so many things wrong here!

Anyway, if you are stuck with this approach, you will need to use cfhttp to get the result.

Something like the attached code should get you started.


Edit: fix IsDefined syntax error...
October 25, 2006
Thanks, but I'm either not understanding the output of this call or I'm asking the question wrongly. I can see using cgi.query_string instead of the method I've done with the form, but I don't see how that will let me capture the actual screen text, not the URL text. The screen itself will display a Y or N that will not be included in the URL.

If I'm not understanding can you throw up a quick outline of the syntax ?

Thanks again
Inspiring
October 25, 2006
cgi.query_string might be just the variable you are looking for.