Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Login to remote site with username & password

Status
Not open for further replies.

xxtravel

Programmer
Aug 24, 2002
22
0
0
MV
hi,

i am trying to write a simple script to access a website where we can send SMS to our country mobile numbers.

at first we have to login to their website using a username & password. After login, we can enter a mobile number and a message and the message arrives at the phone.

i am trying to write a Email to SMS script using this website and now i am having problem accesing this website from my script.

can anyone help to to go through this.

OK, if i put the below URL in my browser, i get automaticaly login to the site.

Code:
[URL unfurl="true"]http://websms.dhimobile.com.mv/cgi-bin/websms/index.pl?username=$username&password=$password[/URL]


after few secons, if i put the below URL in the same browser i receive SMS to my mobile.

Code:
[URL unfurl="true"]http://websms.dhimobile.com.mv/cgi-bin/websms/send_message.pl?mobilenumber=$mobilenumber&message=$message[/URL]


but all this when i do it my self by hand, but i want this to be handle by the script.

pls. help me.

chao, xtravel
 
you need to post the information from a form

Code:
<form action="[URL unfurl="true"]http://websms.dhimobile.com.mv/cgi-bin/websms/index.pl"[/URL] action="get">
<input type="text" name="username"><br>
<input type="password" name="password"><br>
<input type"text" name="mobilenumber"><br>
<textarea name="message" cols="20" rows="5"></textarea>

should output the desired result if you combine your 2 scripts together!





Regards,

Martin

Gaming Help And Info:
 
I think it would be better for your PHP script to POST to that other SMS url rather than GET, because of trying to send the message over a URL (when it includes a password)... so the following is an example of that... though the PHP call to fputs($fp, "POST $path HTTP/1.1\n"); could easily be changed to use a GET method, while leaving the mypage.html post'ing to your php function.

NOTE: the http_post() php method I include here is not original to me, I saw it in some forum years ago, but I don't know who to give credit to.

mypage.html:
Code:
<html>
<form method="POST" action="sendmsg.php">

<input name="username"><br>
<input name="password" type="password"><br>
<input name="mobilenumber"><br>
<textarea name="message" cols=20 rows=10></textarea><br>
<input type="submit" value="Send Message">

</form>
</html>

sendmsg.php:
Code:
<?php

function http_post($host, $path, $payload, $referer = '') {
  // open HTTP connection
  $fp = fsockopen($host,80);
  if ($fp) {
    // send request's header information
    fputs($fp, "POST $path HTTP/1.1\n");
    fputs($fp, "Host: $host\n");
    if (!empty($referer)) {
      fputs($fp, "Referer: $referer\n");
    }
    fputs($fp, "Content-type: application/x-[URL unfurl="true"]www-form-urlencoded\n");[/URL]
    fputs($fp, "Content-length: ".strlen($payload)."\n");
    fputs($fp, "Connection: close\n\n");
    // send request's payload
    fputs($fp, "$payload\n");
    // recieve request's response
    while (!feof($fp)) {
      $result .= fgets($fp, 128);
    }
    // close HTTP connection
    fclose($fp);
    // return result
    return $result;
  } 
  else {
    // return failure flag
    return false;
  }
}

$username = $_POST["username"];
$password = $_POST["password"];
$mobilenumber = $_POST["mobilenumber"];
$message = $_POST["message"];

if (!http_post("websms.dhimobile.com.mv","/cgi-bin/websms/index.pl","username=$username&password=$password")) {
  echo "Oops, couldn't login.";
}
elseif (!http_post("websms.dhimobile.com.mv","/cgi-bin/websms/send_message.pl","mobilenumber=$mobilenumber&message=$message")) {
  echo "Oops, the message couldn't be sent.";
}
else echo "Thank you, your message was sent!";

?>
 
I bet they're using sessions and a cookie. You need to get the cookie when it gives it and present it back to the server when you send the message.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top