?
Solved

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

Posted on 2004-05-03
20
Medium Priority
?
332 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

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

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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this post we will learn how to make Android Gesture Tutorial and give different functionality whenever a user Touch or Scroll android screen.
This article will show how Aten was able to supply easy management and control for Artear's video walls and wide range display configurations of their newsroom.
An introduction to basic programming syntax in Java by creating a simple program. Viewers can follow the tutorial as they create their first class in Java. Definitions and explanations about each element are given to help prepare viewers for future …
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
Suggested Courses

770 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