Login in to PHP site using Java.


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 5 of 5

Thread: Login in to PHP site using Java.

  1. #1
    Join Date
    Mar 2008
    Posts
    3

    Login in to PHP site using Java.

    So , i ve been trying vigorously the past days to succesfully login into a web site using java but nothing seemed to be working for me.

    All i want to do is login, get the data from the site and analyze them in the way that i want.

    But login in is just a pain.

    So login form is :
    Code:
    <form name="login" action="login.php" method="post" target="_top"><input type="hidden" name="PHPSESSID" value="166c592c10598cfc0e8d2be5226cf33f" />
              E-mail: <input type="text"     size="27" maxlength="65" class="custom" name="email" title="Your E-Mail"   value="Your E-Mail"   onfocus="javascript:handleFocus(this);"><br><br>
            Password: <input type="password" size="27" maxlength="20" class="custom" name="pass"  title="Your Password" value="Your Password" onfocus="javascript:handleFocus(this);"><br><br>
            <input type="image" src="img/login2.jpg?PHPSESSID=166c592c10598cfc0e8d2be5226cf33f" value="Submit" name="submit" style="margin-right:60px;">
            <input type="hidden" name="submit" value="Submit">
        </form>
    And i am trying the following
    Code:
     public void tryLog() {
            try {
                // setup url connection. use POST to send forms data
                //url = new URL(HOUSE);
               
                urlConn = (HttpURLConnection) url.openConnection();
    
                urlConn.setRequestMethod("POST");
                urlConn.setDoInput(true);
                urlConn.setDoOutput(true);
                urlConn.setUseCaches(false);
                urlConn.setAllowUserInteraction(true);
                urlConn.setFollowRedirects(true);
                urlConn.setInstanceFollowRedirects(true);
                urlConn.setRequestProperty("content-type-Type", "text/html; charset=iso-8859-1");
                out = new DataOutputStream(urlConn.getOutputStream());
              //  String content = "email=" + URLEncoder.encode(EMAIL_ID, "ISO-8859-1") + "&pass=" + URLEncoder.encode(PASS_WORD, "ISO-8859-1") + "&action=login";
                 String content = "email=" + EMAIL_ID + "&pass=" + PASS_WORD + "&action=login.php";
                System.out.println(content + "\n" + "sending form to HTTP server ...");
                out.writeBytes(content);
               System.out.println(urlConn.getPermission());
                setCookie(urlConn.getHeaderField("Set-Cookie"));
                //System.out.println("sessionid: " + session_id);
    
                out.flush();
                out.close();
                // get input connection
                in = new BufferedReader(new InputStreamReader(urlConn.getInputStream()));
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    I am trying to login with this and then get the website content
    Code:
     public String getString() {
            String all = "";
            try {
                BufferedReader in = new BufferedReader(
                        new InputStreamReader(url.openStream()));
                String inputLine;
    
    
                while ((inputLine = in.readLine()) != null) {
                    all += inputLine + "\n";
                // System.out.println(inputLine);
                }
    
                in.close();
    
            } catch (MalformedURLException e) {     // new URL() failed
                System.out.println(e);
            } catch (IOException e) {               // openConnection() failed
                System.out.println(e);
            }
            return all;
        }
    And to read the content of the site


    Anyway, what ever i try all i get is the login page.
    How can i by pass this and actually get the first page when i login.

  2. #2
    Join Date
    Apr 2007
    Location
    Sterling Heights, Michigan
    Posts
    8,666
    What site are you trying to log in to?
    I don't answer coding questions via PM or Email. Please post a thread in the appropriate forum section.
    Please use [Code]your code goes in here[/Code] tags when posting code.
    Before posting your question, did you look here?
    Got a question on Linux? Visit our Linux sister site.
    Modifications Required For VB6 Apps To Work On Vista

  3. #3
    Join Date
    Mar 2008
    Posts
    3
    just a game site , where the first page has only a form.

    Then i want to get some data from there.

    But do not worry i am not going to cheat
    Site : www.tiipsi.com

  4. #4
    Join Date
    Apr 2007
    Location
    Sterling Heights, Michigan
    Posts
    8,666
    Well, I'm sure the folks that own, run and operate the site would be willing to help you out with this.
    I don't answer coding questions via PM or Email. Please post a thread in the appropriate forum section.
    Please use [Code]your code goes in here[/Code] tags when posting code.
    Before posting your question, did you look here?
    Got a question on Linux? Visit our Linux sister site.
    Modifications Required For VB6 Apps To Work On Vista

  5. #5
    Join Date
    Mar 2008
    Posts
    3
    Sure .... he hardly has time to make some updates and **** have time for mine.
    Besides who guarantees that he know how to do that ?

Similar Threads

  1. How to automatically login to web site
    By Calculon101 in forum .NET
    Replies: 10
    Last Post: 08-25-2006, 03:51 AM
  2. Connecting to java chat server from php
    By prasad in forum Java
    Replies: 0
    Last Post: 05-15-2006, 10:45 AM
  3. PHP / Cold Fusion / Java / Microsoft / MYSQL
    By grouptech in forum Careers
    Replies: 0
    Last Post: 02-21-2006, 08:43 AM
  4. Login (Java Servlet/Database)
    By cappo in forum Java
    Replies: 1
    Last Post: 04-26-2005, 07:16 PM
  5. Best Java Development environment
    By H. Wilson in forum Java
    Replies: 6
    Last Post: 04-14-2000, 12:25 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center