Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.php > #7362 > unrolled thread

How to cURL a JSP page

Started byAnkur Sinha <ankur218@gmail.com>
First post2012-10-27 20:12 -0700
Last post2012-10-28 22:12 +0000
Articles 5 — 4 participants

Back to article view | Back to comp.lang.php


Contents

  How to cURL a JSP page Ankur Sinha <ankur218@gmail.com> - 2012-10-27 20:12 -0700
    Re: How to cURL a JSP page "J.O. Aho" <user@example.net> - 2012-10-28 09:43 +0100
      Re: How to cURL a JSP page Ankur Sinha <ankur218@gmail.com> - 2012-10-28 05:23 -0700
        Re: How to cURL a JSP page Jerry Stuckle <jstucklex@attglobal.net> - 2012-10-28 10:04 -0400
    Re: How to cURL a JSP page Denis McMahon <denismfmcmahon@gmail.com> - 2012-10-28 22:12 +0000

#7362 — How to cURL a JSP page

FromAnkur Sinha <ankur218@gmail.com>
Date2012-10-27 20:12 -0700
SubjectHow to cURL a JSP page
Message-ID<caa0fa90-2b34-4d39-b6d1-d99322fbbbc4@googlegroups.com>
I am trying to cURL my university login page. I want users to enter their university id and pass in my website, my website will curl to university website, authenticate and then allow them to login or give error accordingly. But my university portal is a jsp page. And after having posted in StackOverflow and other forums before, this is what I came up with. I need further help on where I am going wrong and how to rectify it. 

[code]
<form class="form-horizontal" action="curl.php" method="POST">
        <div class="control-group">
            <label class="control-label" for="inputEmail">Username</label>
            <div class="controls">
                <input type="text" id="inputEmail" placeholder="Username">
            </div>
        </div>
        <div class="control-group">
            <label class="control-label" for="inputPassword">Password</label>
            <div class="controls">
                <input type="password" id="inputPassword" placeholder="Password">
            </div>
        </div>
        <div class="control-group">
            <div class="controls">
                <label class="checkbox">
                    <input type="checkbox"> Remember me
                </label>
                <button type="submit" class="btn">Sign in</button>
            </div>
        </div>
    </form>
[/CODE]

Now this is my curl.php file:

[CODE]
<?php
    $address = "http://evarsity.srmuniv.ac.in/srmswi/usermanager/youLogin.jsp"; //site URL
    $post = "username=txtRegNumber&pass=txtPwd"; //Parameters to be sent. Written like GET.
    $welcomeMessage = "Welcome..."; //This is the message that is displayed when a login is successful

    $options = array(
       CURLOPT_USERAGENT => 'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)', 
       CURLOPT_POST => true, //using post
       CURLOPT_URL => $address,  //where to go
       CURLOPT_POSTFIELDS => $post, //input params
       CURLOPT_RETURNTRANSFER => true, //Returns a string value of the request
       CURLOPT_SSL_VERIFYPEER => false, //Avoid SSL problems
       CURLOPT_COOKIEFILE => 'cookie.txt', //Save cookies
       CURLOPT_COOKIEJAR => 'cookies.txt' //Cookies located
       CURLOPT_USERPWD ==> [username]:[password]); 


          if (strpos($content, $welcomeMessage) !== false){ 
          /*
          Do whatever,I don't know what to do here though
          */
          }

      curl_close($ch); //close connections
    ?>
[/CODE]

Please let me know where I am going wrong, why I am not able to login and after logging in, how to log out.

Thank you. 

[toc] | [next] | [standalone]


#7364

From"J.O. Aho" <user@example.net>
Date2012-10-28 09:43 +0100
Message-ID<af49i3FdtpnU1@mid.individual.net>
In reply to#7362
On 28/10/12 04:12, Ankur Sinha wrote:
> I am trying to cURL my university login page. I want users to enter their university id and pass in my website,
> my website will curl to university website, authenticate and then allow them to login or give error accordingly.

There are quite many people who won't do that, login in to a site from a 
third party page, as this can cause login credentials be stolen.


> But my university portal is a jsp page.

This don't make any difference how curl works.

> And after having posted in StackOverflow and other forums before, this
> is what I came up with. I need further help on where I am going wrong and how to rectify it.
>
> [code]
> <form class="form-horizontal" action="curl.php" method="POST">
>          <div class="control-group">
>              <label class="control-label" for="inputEmail">Username</label>
>              <div class="controls">
>                  <input type="text" id="inputEmail" placeholder="Username">

You will not send any useful data to your curl page, see examples at 
w3schools: http://www.w3schools.com/html/html_forms.asp

>              </div>
>          </div>
>          <div class="control-group">
>              <label class="control-label" for="inputPassword">Password</label>
>              <div class="controls">
>                  <input type="password" id="inputPassword" placeholder="Password">

You will not send any useful data to your curl page, see examples at 
w3schools: http://www.w3schools.com/html/html_forms.asp


>              </div>
>          </div>
>          <div class="control-group">
>              <div class="controls">
>                  <label class="checkbox">
>                      <input type="checkbox"> Remember me
>                  </label>
>                  <button type="submit" class="btn">Sign in</button>
>              </div>
>          </div>
>      </form>
> [/CODE]
>
> Now this is my curl.php file:
>
> [CODE]
> <?php
>      $address = "http://evarsity.srmuniv.ac.in/srmswi/usermanager/youLogin.jsp"; //site URL
>      $post = "username=txtRegNumber&pass=txtPwd"; //Parameters to be sent. Written like GET.

You need to set the login name and password, in this case you just using 
static values txtRegNumber / txtPwd, you need to assign those dynamically.
See http://www.php.net/manual/en/language.variables.basics.php

>      $welcomeMessage = "Welcome..."; //This is the message that is displayed when a login is successful
>
>      $options = array(
>         CURLOPT_USERAGENT => 'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)',
>         CURLOPT_POST => true, //using post
>         CURLOPT_URL => $address,  //where to go
>         CURLOPT_POSTFIELDS => $post, //input params
>         CURLOPT_RETURNTRANSFER => true, //Returns a string value of the request
>         CURLOPT_SSL_VERIFYPEER => false, //Avoid SSL problems
>         CURLOPT_COOKIEFILE => 'cookie.txt', //Save cookies
>         CURLOPT_COOKIEJAR => 'cookies.txt' //Cookies located
>         CURLOPT_USERPWD ==> [username]:[password]);
>

You need to make the connection to the site, see example at php.net:
http://www.php.net/manual/en/function.curl-init.php

>            if (strpos($content, $welcomeMessage) !== false){
>            /*
>            Do whatever,I don't know what to do here though
>            */
>            }

You should make error checks, see examples at php.net:
http://www.php.net/manual/en/function.curl-errno.php
http://www.php.net/manual/en/function.curl-error.php

When you confirm that you have logged in, you have to be sure that the 
string you look for don't include HTML tags.

>        curl_close($ch); //close connections
>      ?>
> [/CODE]
>
> Please let me know where I am going wrong, why I am not able to login and after logging in, how to log out.

Drop the cookie, if you want the university web server to know it, make 
a curl request to the logout link/page.


Good luck with your school assignment.

-- 

  //Aho

[toc] | [prev] | [next] | [standalone]


#7365

FromAnkur Sinha <ankur218@gmail.com>
Date2012-10-28 05:23 -0700
Message-ID<af6c3c65-68e8-40b0-af95-a767a64cf4f5@googlegroups.com>
In reply to#7364
On Sunday, 28 October 2012 14:13:48 UTC+5:30, J.O. Aho  wrote:
> On 28/10/12 04:12, Ankur Sinha wrote:
> 
> > I am trying to cURL my university login page. I want users to enter their university id and pass in my website,
> 
> > my website will curl to university website, authenticate and then allow them to login or give error accordingly.
> 
> 
> 
> There are quite many people who won't do that, login in to a site from a 
> 
> third party page, as this can cause login credentials be stolen.
> 
> 
> 
> 
> 
> > But my university portal is a jsp page.
> 
> 
> 
> This don't make any difference how curl works.
> 
> 
> 
> > And after having posted in StackOverflow and other forums before, this
> 
> > is what I came up with. I need further help on where I am going wrong and how to rectify it.
> 
> >
> 
> > [code]
> 
> > <form class="form-horizontal" action="curl.php" method="POST">
> 
> >          <div class="control-group">
> 
> >              <label class="control-label" for="inputEmail">Username</label>
> 
> >              <div class="controls">
> 
> >                  <input type="text" id="inputEmail" placeholder="Username">
> 
> 
> 
> You will not send any useful data to your curl page, see examples at 
> 
> w3schools: http://www.w3schools.com/html/html_forms.asp
> 
> 
> 
> >              </div>
> 
> >          </div>
> 
> >          <div class="control-group">
> 
> >              <label class="control-label" for="inputPassword">Password</label>
> 
> >              <div class="controls">
> 
> >                  <input type="password" id="inputPassword" placeholder="Password">
> 
> 
> 
> You will not send any useful data to your curl page, see examples at 
> 
> w3schools: http://www.w3schools.com/html/html_forms.asp
> 
> 
> 
> 
> 
> >              </div>
> 
> >          </div>
> 
> >          <div class="control-group">
> 
> >              <div class="controls">
> 
> >                  <label class="checkbox">
> 
> >                      <input type="checkbox"> Remember me
> 
> >                  </label>
> 
> >                  <button type="submit" class="btn">Sign in</button>
> 
> >              </div>
> 
> >          </div>
> 
> >      </form>
> 
> > [/CODE]
> 
> >
> 
> > Now this is my curl.php file:
> 
> >
> 
> > [CODE]
> 
> > <?php
> 
> >      $address = "http://evarsity.srmuniv.ac.in/srmswi/usermanager/youLogin.jsp"; //site URL
> 
> >      $post = "username=txtRegNumber&pass=txtPwd"; //Parameters to be sent. Written like GET.
> 
> 
> 
> You need to set the login name and password, in this case you just using 
> 
> static values txtRegNumber / txtPwd, you need to assign those dynamically.
> 
> See http://www.php.net/manual/en/language.variables.basics.php
> 
> 
> 
> >      $welcomeMessage = "Welcome..."; //This is the message that is displayed when a login is successful
> 
> >
> 
> >      $options = array(
> 
> >         CURLOPT_USERAGENT => 'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)',
> 
> >         CURLOPT_POST => true, //using post
> 
> >         CURLOPT_URL => $address,  //where to go
> 
> >         CURLOPT_POSTFIELDS => $post, //input params
> 
> >         CURLOPT_RETURNTRANSFER => true, //Returns a string value of the request
> 
> >         CURLOPT_SSL_VERIFYPEER => false, //Avoid SSL problems
> 
> >         CURLOPT_COOKIEFILE => 'cookie.txt', //Save cookies
> 
> >         CURLOPT_COOKIEJAR => 'cookies.txt' //Cookies located
> 
> >         CURLOPT_USERPWD ==> [username]:[password]);
> 
> >
> 
> 
> 
> You need to make the connection to the site, see example at php.net:
> 
> http://www.php.net/manual/en/function.curl-init.php
> 
> 
> 
> >            if (strpos($content, $welcomeMessage) !== false){
> 
> >            /*
> 
> >            Do whatever,I don't know what to do here though
> 
> >            */
> 
> >            }
> 
> 
> 
> You should make error checks, see examples at php.net:
> 
> http://www.php.net/manual/en/function.curl-errno.php
> 
> http://www.php.net/manual/en/function.curl-error.php
> 
> 
> 
> When you confirm that you have logged in, you have to be sure that the 
> 
> string you look for don't include HTML tags.
> 
> 
> 
> >        curl_close($ch); //close connections
> 
> >      ?>
> 
> > [/CODE]
> 
> >
> 
> > Please let me know where I am going wrong, why I am not able to login and after logging in, how to log out.
> 
> 
> 
> Drop the cookie, if you want the university web server to know it, make 
> 
> a curl request to the logout link/page.
> 
> 
> 
> 
> 
> Good luck with your school assignment.
> 
> 
> 
> -- 
> 
> 
> 
>   //Aho

I am making this for my college out of my own interest after conducting a survey. So this is not my assignment and people said they won't sign up freshly and they wanted to login using existing ids and passwords provided by the university. 

[toc] | [prev] | [next] | [standalone]


#7366

FromJerry Stuckle <jstucklex@attglobal.net>
Date2012-10-28 10:04 -0400
Message-ID<k6je13$t53$1@dont-email.me>
In reply to#7365
On 10/28/2012 8:23 AM, Ankur Sinha wrote:
> On Sunday, 28 October 2012 14:13:48 UTC+5:30, J.O. Aho  wrote:
>> On 28/10/12 04:12, Ankur Sinha wrote:
>>
>>> I am trying to cURL my university login page. I want users to enter their university id and pass in my website,
>>
>>> my website will curl to university website, authenticate and then allow them to login or give error accordingly.
>>
>>
>>
>> There are quite many people who won't do that, login in to a site from a
>>
>> third party page, as this can cause login credentials be stolen.
>>
>>
>>
>>
>>
>>> But my university portal is a jsp page.
>>
>>
>>
>> This don't make any difference how curl works.
>>
>>
>>
>>> And after having posted in StackOverflow and other forums before, this
>>
>>> is what I came up with. I need further help on where I am going wrong and how to rectify it.
>>
>>>
>>
>>> [code]
>>
>>> <form class="form-horizontal" action="curl.php" method="POST">
>>
>>>           <div class="control-group">
>>
>>>               <label class="control-label" for="inputEmail">Username</label>
>>
>>>               <div class="controls">
>>
>>>                   <input type="text" id="inputEmail" placeholder="Username">
>>
>>
>>
>> You will not send any useful data to your curl page, see examples at
>>
>> w3schools: http://www.w3schools.com/html/html_forms.asp
>>
>>
>>
>>>               </div>
>>
>>>           </div>
>>
>>>           <div class="control-group">
>>
>>>               <label class="control-label" for="inputPassword">Password</label>
>>
>>>               <div class="controls">
>>
>>>                   <input type="password" id="inputPassword" placeholder="Password">
>>
>>
>>
>> You will not send any useful data to your curl page, see examples at
>>
>> w3schools: http://www.w3schools.com/html/html_forms.asp
>>
>>
>>
>>
>>
>>>               </div>
>>
>>>           </div>
>>
>>>           <div class="control-group">
>>
>>>               <div class="controls">
>>
>>>                   <label class="checkbox">
>>
>>>                       <input type="checkbox"> Remember me
>>
>>>                   </label>
>>
>>>                   <button type="submit" class="btn">Sign in</button>
>>
>>>               </div>
>>
>>>           </div>
>>
>>>       </form>
>>
>>> [/CODE]
>>
>>>
>>
>>> Now this is my curl.php file:
>>
>>>
>>
>>> [CODE]
>>
>>> <?php
>>
>>>       $address = "http://evarsity.srmuniv.ac.in/srmswi/usermanager/youLogin.jsp"; //site URL
>>
>>>       $post = "username=txtRegNumber&pass=txtPwd"; //Parameters to be sent. Written like GET.
>>
>>
>>
>> You need to set the login name and password, in this case you just using
>>
>> static values txtRegNumber / txtPwd, you need to assign those dynamically.
>>
>> See http://www.php.net/manual/en/language.variables.basics.php
>>
>>
>>
>>>       $welcomeMessage = "Welcome..."; //This is the message that is displayed when a login is successful
>>
>>>
>>
>>>       $options = array(
>>
>>>          CURLOPT_USERAGENT => 'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)',
>>
>>>          CURLOPT_POST => true, //using post
>>
>>>          CURLOPT_URL => $address,  //where to go
>>
>>>          CURLOPT_POSTFIELDS => $post, //input params
>>
>>>          CURLOPT_RETURNTRANSFER => true, //Returns a string value of the request
>>
>>>          CURLOPT_SSL_VERIFYPEER => false, //Avoid SSL problems
>>
>>>          CURLOPT_COOKIEFILE => 'cookie.txt', //Save cookies
>>
>>>          CURLOPT_COOKIEJAR => 'cookies.txt' //Cookies located
>>
>>>          CURLOPT_USERPWD ==> [username]:[password]);
>>
>>>
>>
>>
>>
>> You need to make the connection to the site, see example at php.net:
>>
>> http://www.php.net/manual/en/function.curl-init.php
>>
>>
>>
>>>             if (strpos($content, $welcomeMessage) !== false){
>>
>>>             /*
>>
>>>             Do whatever,I don't know what to do here though
>>
>>>             */
>>
>>>             }
>>
>>
>>
>> You should make error checks, see examples at php.net:
>>
>> http://www.php.net/manual/en/function.curl-errno.php
>>
>> http://www.php.net/manual/en/function.curl-error.php
>>
>>
>>
>> When you confirm that you have logged in, you have to be sure that the
>>
>> string you look for don't include HTML tags.
>>
>>
>>
>>>         curl_close($ch); //close connections
>>
>>>       ?>
>>
>>> [/CODE]
>>
>>>
>>
>>> Please let me know where I am going wrong, why I am not able to login and after logging in, how to log out.
>>
>>
>>
>> Drop the cookie, if you want the university web server to know it, make
>>
>> a curl request to the logout link/page.
>>
>>
>>
>>
>>
>> Good luck with your school assignment.
>>
>>
>>
>> --
>>
>>
>>
>>    //Aho
>
> I am making this for my college out of my own interest after conducting a survey. So this is not my assignment and people said they won't sign up freshly and they wanted to login using existing ids and passwords provided by the university.
>

I agree with J.O.  You'll find a lot more people won't sign in using the 
credentials from another site.  Only those with no concept of security 
will do it the way you want.

-- 
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================

[toc] | [prev] | [next] | [standalone]


#7374

FromDenis McMahon <denismfmcmahon@gmail.com>
Date2012-10-28 22:12 +0000
Message-ID<k6kakn$fiu$1@dont-email.me>
In reply to#7362
On Sat, 27 Oct 2012 20:12:03 -0700, Ankur Sinha wrote:

> I am trying to cURL my university login page. I want users to enter
> their university id and pass in my website, my website will curl to
> university website, authenticate and then allow them to login or give
> error accordingly.

As an example, look at the mechanism that e.g. "verified by visa" uses to 
enable customers to enter their verification credentials when making 
online transactions without those credentials being captured by the 
trader or payment processing website.

Rgds

Denis McMahon

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.php


csiph-web