Solved

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

Posted on 2004-05-03
20
312 Views
Last Modified: 2010-04-17
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?
0
Comment
Question by:vallentin_68
  • 7
  • 7
  • 5
  • +1
20 Comments
 
LVL 4

Expert Comment

by:NVRAM
ID: 10980737
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
 
LVL 1

Expert Comment

by:paulsidebottom
ID: 10980881
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
 

Author Comment

by:vallentin_68
ID: 10984448
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
 
LVL 1

Expert Comment

by:Apyreal
ID: 10984501
are you saying that the script must check whether the url exists?
0
 

Author Comment

by:vallentin_68
ID: 10984526
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
 
LVL 1

Expert Comment

by:Apyreal
ID: 10984543
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
 
LVL 1

Accepted Solution

by:
Apyreal earned 500 total points
ID: 10984553
0
 
LVL 1

Expert Comment

by:Apyreal
ID: 10984573
0
 

Author Comment

by:vallentin_68
ID: 10984741
Perfect. Thank you
0
 
LVL 1

Expert Comment

by:Apyreal
ID: 10984756
no, thank u. that is probably the first question someone has answered of mine without being forced to. thank u.
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 

Author Comment

by:vallentin_68
ID: 10985710
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
 
LVL 1

Expert Comment

by:Apyreal
ID: 10985789
where do you store the names of all the users?
0
 

Author Comment

by:vallentin_68
ID: 10986153
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
 
LVL 4

Expert Comment

by:NVRAM
ID: 10988024
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
 
LVL 4

Expert Comment

by:NVRAM
ID: 10988075
Doh, I inadvertently dropped this line before posting:

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

Which belongs somewhat before the return line.
0
 

Author Comment

by:vallentin_68
ID: 10988660
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
 
LVL 4

Expert Comment

by:NVRAM
ID: 10988872
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
 

Author Comment

by:vallentin_68
ID: 10989354
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
 
LVL 4

Expert Comment

by:NVRAM
ID: 10989434
No problem at all, and thanks I hadn't expected points....
0
 
LVL 1

Expert Comment

by:Apyreal
ID: 10993305
is there anyway i can give the points back? i didnt answer the question properly and dont want the points
0

Featured Post

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Delphi Mdi application Child forms get behind control 7 111
sumDigits  challenge 7 60
mapAB Challlenge 35 84
Not needed 13 53
This is about my first experience with programming Arduino.
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now