Jump to content

How to access a password protected site?

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
4 replies to this topic

#1
willem55

willem55

    Newbie

  • Members
  • Pip
  • 2 posts
I would like to get access to a secure site via php in order to gather some information. The good thing is that I have the right username & password.

I'm using curl for signing in. With some sites it works. For example, here's the code:
$username = "*******";
$password = "********";
 
   $ch = curl_init();
   curl_setopt($ch, CURLOPT_URL, "site url" ); 
   curl_setopt($ch, CURLOPT_POST, 1 );
   curl_setopt($ch, CURLOPT_POSTFIELDS, 'username='.$username.'&password='.$password.'&act=login');
   curl_setopt ($ch, CURLOPT_COOKIEJAR, 'cookie.txt');
   $store = curl_exec ($ch);
 
   curl_setopt($ch, CURLOPT_URL, "site url" ); 
   curl_setopt($ch, CURLOPT_POST, 1 );
   curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
   $str = curl_exec($ch);
   print $str;
   curl_close ($ch);

But the problem comes up with sites where the "form" redirects (OnClick) to a javascript. For instance:

input type="image" src="enter.jpg" border="0" onClick="Some script"

So, here's the question: can I start the javascript with curl? And if not then how can I "sign in" in order to gather wanted information?

Edited by Jordan, 20 July 2008 - 04:53 AM.
Added code tags


#2
Guest_Jordan_*

Guest_Jordan_*
  • Guests
No, CURL doesn't have the ability to execute or follow JavaScript. You can, however, parse the results and simulate the logic yourself in your script. Most JavaScript functions (in combination with a form) check that the form entries are valid before submitting. It is easy enough to determine what they do, if you post the code (HTML Source or JavaScript) I can tell you how to formulate your CURL. statement.

#3
willem55

willem55

    Newbie

  • Members
  • Pip
  • 2 posts
I wanted to add that I'm an official user and have no intent to hack something. But here's the code:


<html>

<script language="javascript">

function securePicker()

   {

   for (i = 0; i < document.loginform.length; i++) 

     { 

     if ( document.loginform.elements[i].name == "account_type" )

	   {

	   var SelectBtn = document.loginform.elements[i];

	   

	   if ( SelectBtn.value == "MID" )

	      {

		  

		  document.loginform.action = 'https://www.samplepage.com' + '/main.cfm';

		  

		  }

	   }

     } 

   }

</script>


<body>

<table>

 <form action="main.cfm" method="post" name="loginform">

 <tr >

  <td > EMail</td>

  <td ><input type="text" class="form" name="email" ></td>

</tr>

<tr>

 <td >Pass:</td>

 <td class=smalltext width=88 align=left><input type="password" class="form" name="password" ></td>

</tr>

<tr>

 <td>  </td>

 <td ><input type="image" src="img/enter.jpg"  onClick="securePicker(); return true;"></td>

</tr></form>

</table>			

</body>

</html>




#4
Guest_Jordan_*

Guest_Jordan_*
  • Guests
Site URL should be "https://www.samplepage.commain.cfm". This will work in your CURL script.

#5
jessje

jessje

    Learning Programmer

  • Members
  • PipPipPip
  • 64 posts
what is the use of this script? if you are allowed on the site can't you make a db connection or something?