KriptSkitty
KriptSkitty

Reputation: 16

Why can't I submit form? PHP cURL

I am trying to write a script that will get my data usage for the month, and to navigate the url I am using cURL. Unfortunately, I am not familiar with it. This is my code so far:

<?php

$url = 'https://apps.nwtel.ca/cable_usage/login.jsp' ;
$id = "------------" ;

$ch = curl_init() ;
curl_setopt( $ch, CURLOPT_URL, "$url" ) ;
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true ) ;
curl_setopt( $ch, CURLOPT_POST, true ) ;
curl_setopt( $ch, CURLOPT_SSL_VERIFYPEER, false ) ;
curl_setopt( $ch, CURLOPT_FOLLOWLOCATION, true ) ;

$data = array(
    'MAC' => "$id",
    'submit_btn' => 'submit'
) ;

curl_setopt( $ch, CURLOPT_POSTFIELDS, $data ) ;
$output = curl_exec( $ch ) ;
curl_close( $ch ) ;

echo "$output\n" ;

?>

For some reason though, this does not work. I've tried so many variations, but the output is always the same. It gives me the original page. Does anyone know what I am doing wrong? I've been banging my head on this for hours.

Thanks!

Upvotes: 0

Views: 1836

Answers (1)

Jose Vega
Jose Vega

Reputation: 10258

I am not 100% sure, but after looking at that source of the url, I feel like you should be curling the action of the form, not the page the form is located in. You are simulating a submit, therefore you should try to submit the forms content to the action of the form.

<form method="post" action="j_security_check" id="usage_login">
    <input type="hidden" name="j_target_url" value="secured/index.jsp" />
    <div class="form_input">
    <label for="MAC">HFC or CM MAC Address:</label>
    <input type="Text" name="MAC" id="MAC" onKeyPress="onKeyPress(this.form)" />
    <a href="#mac_num_help" title="Your HFC or CM MAC Address is located on the sticker on the bottom of your modem" class="help">MAC Address Help</a>
    <input type="hidden" name="j_username" id="j_username" />
    </div>
    <div class="form_input">
    <input type="hidden" name="j_password" id="j_password" maxlength="6" size="7" value="123456" />
    </div>
    <div class="form_input">
    <label for="submit_btn">&nbsp;</label>
    <input type="submit" name="submit_btn" id="submit_btn" value="Submit" onclick="fixAndSubmit(this.form)" />
    </div>
</form>

Try changing:

$url = 'https://apps.nwtel.ca/cable_usage/login.jsp' ;

to

$url = 'https://apps.nwtel.ca/cable_usage/j_security_check' ;

also change

$data = array(
    'MAC' => "$id",
    'submit_btn' => 'submit'
) ;

to

$data = array(
    'MAC' => "$id",
    'submit_btn' => 'submit',
    'j_password' => '123456',
    'j_username' => '3D3D3D3D3D3D' //should be your MAC address all capitalize without using special characters
    'j_target_url' => 'secured/index.jsp'
) ;

Upvotes: 2

Related Questions