Confirm URL by looking up URL and return true or false (Java or asp)

I need a script that will generate the URL  "http://www.company.com/vallentin" from a form field "username=vallentin".
If result is "http://www.company.com/?username=vallentin" in the URL address it must return true and continue
If result is "http://www.company.com/" in the URL address it must return false and go to an error message.

Can it be done?
vallentin_68Asked:
Who is Participating?
 
NVRAMCommented:
vallentin_68 wrote:
> I need a script that will generate the URL  "http://www.company.com/vallentin" from a form field "username=vallentin".
> If result is "http://www.company.com/?username=vallentin" in the URL address it must return true and continue
> If result is "http://www.company.com/" in the URL address it must return false and go to an error message.

I'm having trouble understanding what you want - the first line seems straightforward; just append the value of username to a prefix to get the URL.

Do you mean the script should retrieve a page use the calculated URL and see if it indicates redirection?  
Do you mean to test the URL of the referring page?
Something else perhaps?

0
 
paulsidebottomCommented:
Assuming that you wish a form to post the value to another page and for this page to check the username then redirect, the following (rather crude!) ASP code should solve your problem...

-------------------Form.htm---------------

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title>Form Test</title>
</head>
<body>
<form action="formtest.asp" id="testForm" method="get" >
      <input type="text" name="username"/><input  value="Submit"
       type="submit" />
</form>
</body>
</html>

-------------------Formtest.asp---------------

<%
      if request.QueryString("username") = "vallentin" then
            response.write("http://www.company.com/" + request.querystring("username"))
            'response.Redirect("http://www.company.com/" + request.querystring("username"))
      else
            response.Write "Invalid user!"
                               'response.redirect("error.htm") <-- this will send them to an error page
      end if
%>

This assumes you wish to use ASP as your language of choice. In addition:

- The username will be displayed in the addressbar: you can prevent this from the client by using method="post" instead of "get"
- Any users who change the URL in the addressbar (e.g. http://www.company.com) will force a redirection to your error.htm page
- You can change the redirection locations by altering the response redirects in the ASP file
0
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
vallentin_68Author Commented:
The above asp does not do the trick. The script I need should do the following:

During a registration process to become a member of my site, I need to check if the person is a member of another site. The only way to check this is to look up a URL generated from their username during registration. In the form they must enter their username on the other site (fx. vallentin).

On submit the code must look up the URL "http://www.company.com/(username)".

If the person is a member of the other site it will redirect to the URL "http://www.company.com/?username=(username)"
If the person is not a member of the other site it will redirect to the URL "http://www.company.com/"

If the result is "http://www.company.com/?username=(username)" it should generate the answer "true"
If the result is "http://www.company.com/" it should generate the answer "false"
0
 
ApyrealCommented:
are you saying that the script must check whether the url exists?
0
 
vallentin_68Author Commented:
Yes, because if the url "http://www.company.com/?username=(username)" does not exist (and they are not a member) it will redirect to "http://www.company.com/"
0
 
ApyrealCommented:
you will have to use a dns lookup for that. i dont know the code but i am trying to get it. and yes, as far as i know, it is possible
0
 
ApyrealCommented:
0
 
vallentin_68Author Commented:
Perfect. Thank you
0
 
ApyrealCommented:
no, thank u. that is probably the first question someone has answered of mine without being forced to. thank u.
0
 
vallentin_68Author Commented:
Unfortunately http://www.asp101.com/articles/jason/reversedns/default.asp didn't work either.

My problem is that the ip address is the same whether the person is a member or not. The only difference in the site (php) is that when you look up the URL "http://www.company.com/(username)" the URL changes to "http://www.company.com/?username=(username)" if you are a member and to the companys main page "http://www.company.com/" if you are not a member.

Is it at all possible or do I have to check it manually with every sign up?
0
 
ApyrealCommented:
where do you store the names of all the users?
0
 
vallentin_68Author Commented:
My users are stored in a database (Access mdb) but I don't know how they are stored on the php-site where i need to check their membership. I do not have access to the company's server. I only have access to the public site.
0
 
NVRAMCommented:
Presumably, you can retrieve the page at http://www.company.com/johndoe - then check the header for an HTTP-EQUIV string.  You'll need to confirm that they are using this (just pull the page using telnet, wget or similar and look at the text, or run the following but print the 'shdr' string.)

So, presuing that they are using the HTML syntax like:
   <META http-equiv="Refresh" content="0;url=http://www.company.com/?username=johndoe">

then here's some Java code; you'll probably need to manipulate the strings to fit and may need to remove case sensitivity.

------------
    static boolean ValidUser( String prefix, String username )
      throws MalformedURLException, IOException
    {
      String _url = prefix + username;
      
      URL url = new URL( _url );
      InputStream is = url.openStream();
      InputStreamReader isr = new InputStreamReader( is );
      BufferedReader br = new BufferedReader( isr );

      char[] chdr = new char[4096];
      int    rval = isr.read( chdr, 0, chdr.length );
      String shdr = new String( chdr, 0, rval );
      
      return (0 <= shdr.indexOf( okstr ));
    }
0
 
NVRAMCommented:
Doh, I inadvertently dropped this line before posting:

      String okstr = prefix + "/?username=" + username;

Which belongs somewhat before the return line.
0
 
vallentin_68Author Commented:
The only META they use is: <META HTTP-EQUIV="imagetoolbar" CONTENT="no">
I expect this is not the same (I am not a java wizard...)

The only other difference in the code from members to nonmembers is this:

Members:
<!-- CLEAR IT -->
<div align="center"> <br>
<a href="#" onClick="MM_openBrWindow('https://www.company.com/signup/index.php?introducer=username','SIGNUP','scrollbars=yes,status=yes,resizable=yes,width=760,height=500')">
<img src='/media/en/btn_join_now.gif' width='139' height='32' border='0'></a></div>
<!-- UNCLER IT -->

Non members:
<!-- CLEAR IT -->
<div align="center"> <br>
 <a href="#" onClick="window.alert('Please go to the user that recommended you.')" >
<img src='/media/en/btn_join_now.gif' width='139' height='32' border='0'></a></div>
 <!-- UNCLER IT -->

Is it possible to create a response from this? (sorry, if I am asking stupid questions!)
0
 
NVRAMCommented:
Yes, that would work, too, and it should be easy.

Just fix the '_url' variable to be the URL of the page you need to read, and 'okstr' to be the equivalent of 'https://www.company.com/signup/index.php?introducer=username'.

The code I posted really just looks for the desired url in the HTML sent back, and your reply makes it seem that that is true.   But do make sure that the '4096' value is long enough that the desired URL is found when the username is valid.

Good luck.
0
 
vallentin_68Author Commented:
Dear NVRAM,
I am new at Expert Exchange and have probably made a mess of it, as I have already accepted an answer previously on this problem. I have made another question "Check membership in URL address on a php site from asp (or Java) and return true or false?". If you go and answer the new question like you have done just now, I will accept your answer and you will get your points.
With thanks
Vallentin_68
0
 
NVRAMCommented:
No problem at all, and thanks I hadn't expected points....
0
 
ApyrealCommented:
is there anyway i can give the points back? i didnt answer the question properly and dont want the points
0
All Courses

From novice to tech pro — start learning today.