Question

for an computer science project we have to build a website that presents our time schedules. So basically what we have to do, is login to this site and get the information out of the page you're directed to. I've read a lot of posts and tried a lot with cURL, but nothing seems to work. I got the forms to be filled out, but it looks as if the 'submit' button isn't clicked. This is what I've got:

<?php
$url="http://rooster.sgnphp.nl/infoweb/index.php"; 
$post_data['user'] = '105353';
$post_data['paswoord'] = '105353';

foreach ( $post_data as $key => $value) 
{
    $post_items[] = $key . '=' . $value;
}
$postdata = implode ('&', $post_items);

$ch = curl_init($url);
curl_setopt ($ch, CURLOPT_URL, $url); 
curl_setopt ($ch, CURLOPT_SSL_VERIFYPEER, FALSE); 
curl_setopt ($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US;         rv:1.8.1.6) Gecko/20070725 Firefox/2.0.0.6"); 
curl_setopt ($ch, CURLOPT_TIMEOUT, 60); 
curl_setopt ($ch, CURLOPT_FOLLOWLOCATION, 1); 
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1); 
curl_setopt ($ch, CURLOPT_COOKIEJAR, cookie.txt); 
curl_setopt ($ch, CURLOPT_COOKIEFILE, cookie.txt); 
curl_setopt ($ch, CURLOPT_REFERER, $url); 
curl_setopt ($ch, CURLOPT_POSTFIELDS, $postdata); 
curl_setopt ($ch, CURLOPT_POST, 1); 
$result = curl_exec ($ch); 
echo $result;

curl_close($ch);
?>

The form which I tried to fill in looks like this:

<form action="/infoweb/index.php" method="post">
<input type="hidden" name="csrf" value="cec30a2ed764e956ed01f137e2f0705a">
<table>
  <tbody><tr>
    <td>
      Gebruikersnaam:
    </td>
    <td>
      <input class="mooi" style="color: #FF8080;" type="text" name="user" value="105353" onfocus="if (this.value =='username') this.value=''; this.style.color='#000000';" onkeydown="this.style.color='#000000';">
    </td>
  </tr>
  <tr>
    <td>
      Wachtwoord:
    </td>
    <td>
      <input class="mooi" style="margin-bottom: 2px; color: #FF8080;" type="password"     name="paswoord" value="105353" onfocus="if (this.value =='wachtwoord') this.value=''; this.style.color='#000000';" onkeydown="this.style.color='#000000';">
    </td>
  </tr>
  <tr>
    <td>
      <input type="hidden" name="login" value="loginform"> &nbsp;
    </td>
    <td>
      <input type="submit" class="mooi" value="inloggen"><br>
    </td>
  </tr>
</tbody></table>
</form>

So what happens is that the form is filled out, but I can't see the time schedule because (I think) I'm not officially logged in. Can anybody please help me? I really need to get this to work so I can get on with the rest of my project, but I've been stuck on this for days.

Thanks

Was it helpful?

Solution

Depending on how the login script works for that site depends on how you set up Curl.

At a glance I would guess that you would need to Curl the page first get a session started and save cookies then strip "csrf" input and then post your username and password.

From then on you would be able to Curl any link that requires you to be logged in.

If "you" built the site I'm sure you could make a a script that would do this for you?

OTHER TIPS

Note that the form has a hidden input:

<input type="hidden" name="login" value="loginform">

you need to send this value as well:

$post_data['login'] = 'loginform';
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top