Amazon remote log-in (PHP cURL) | Cookies - php

I'm trying to make a remote log-in for Amazon. So basically, an user will log-in through our local form. And if everything he filled in is correct, he will be logged in at Amazon.
`
if(isSet($_POST['submit']))
{
$account = $_POST["account"];
$pass = $_POST["pass"];
$ch = curl_init("https://www.amazon.com/ap/signin?_encoding=UTF8&openid.assoc_handle=usflex&openid.claimed_id=http%3A%2F%2Fspecs.openid.net%2Fauth%2F2.0%2Fidentifier_select&openid.identity=http%3A%2F%2Fspecs.openid.net%2Fauth%2F2.0%2Fidentifier_select&openid.mode=checkid_setup&openid.ns=http%3A%2F%2Fspecs.openid.net%2Fauth%2F2.0&openid.ns.pape=http%3A%2F%2Fspecs.openid.net%2Fextensions%2Fpape%2F1.0&openid.pape.max_auth_age=0&openid.return_to=https%3A%2F%2Fwww.amazon.com%2Fgp%2Fyourstore%2Fhome%3Fie%3DUTF8%26ref_%3Dnav_ya_signin");
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_COOKIESESSION, true );
curl_setopt($ch, CURLOPT_POSTFIELDS, "ap_email=" .$account."&ap_password=".$pass."");
curl_exec($ch);
if (curl_errno($ch))
{
print curl_error($ch);
}
else
{
curl_close($ch);
}
}
else
{
?>
<form method="POST" action="<?php echo $_SERVER['PHP_SELF']; ?>" name="login">
<table width="100%">
<tr align="center">
<td width="50%" align="right"><font color="navy">E-Mail</font></td>
<td width="50%" align="left"><input type="text" name="account" size="10"></td>
</tr>
<tr align="center">
<td width="50%" align="right" width="100"><font color="navy">Password</font></td>
<td width="50%" align="left"><input type="password" size="10" name="pass"></td>
</tr>
<tr>
<td> </td>
</tr>
<tr align="center">
<td colspan="2" align="center"><input name="submit" type="submit" value="Inloggen"></td>
</tr>
</table>
</form>
<?php } ?>`
This is the code I've used. And I'm getting the following error:
Please Enable Cookies to Continue
To continue shopping at Amazon.com, please enable cookies in your Web browser. Learn more about cookies and how to enable them.
Once you have enabled cookies in your browser, please click on the button below to return to the previous page.
How can I fix this error? I've tried everything.
I'm using XAMPP at the moment.

Just for marking as answer:
you have to 2 things:
1 - Request login page from server using get method
2 - Send login data using new session and with hidden inputs
to see the script : https://stackoverflow.com/a/7532730/889678

Related

Question marks when execute arabic letters in php

I want to build simple page to get exam results from university server.
First I built a form that send student number to university server and take you to university page. Here is the code:
<form action="https://exam.albaath-univ.edu.sy/exam-med/re.php" method="post" accept-charset="UTF-8">
<p style="text-align: center;">
<input name="number1" type="hidden" value="" />
<input name="nospy" type="hidden" value="" />
</p>
<table>
<tbody>
<tr>
<td>choose field</td>
<td>
<select name="nospy">
<option value="1">Med</option>
</select>
</td>
</tr>
<tr>
<td>enter your number</td>
<td style="text-align: right;"><input name="number1" size="20" type="text" /></td>
</tr>
<tr>
<td colspan="2" align="center"><input type="submit" value="show result" /></td>
</tr>
</tbody>
</table>
</form>
This code works perfectly.. The next step I tried to do is to make the form redirect to another page on my website. This page contains php code that take the information the send it to university server then get the response and print it in same page without going to university page.
The code was like this:
<?php
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
$nospy = $_POST['nospy'];
$number1 = $_POST['number1'];
// send the information to another PHP page using cURL
$url = 'https://example.com/other_page.php';
$post_data = array(
'nospy' => $nospy,
'number1' => $number1
);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($post_data));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
curl_close($ch);
// process the response from the other PHP page
// convert it to the Windows-1256 encoding
$response = iconv("UTF-8", "Windows-1256", $response);
// display the converted response in HTML
echo $response;
}
?>
This code also worked but the problem is that the results contains arabic names and php still give question marks instead of arabic letters.. I tried many solutions like converting text to utf-8 and window-1256 encoding... it doesnt work.. can anyone help
I need the results to support arabic letters
please try adding the following to the header to the returned output.
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

I use POST method for form but echo $_SERVER['REQUEST_METHOD'] result is GET

i have a problem that is i use POST method to post my form but when i echo $_SERVER['REQUEST_METHOD'] the result is GET, why?
this is my code
<div align="center">
<form action="../application/components/check.php" method="POST" >
<table align='center' cellspacing='20px;' class='menubg'>
<tr>
<td colspan='2'>
<div style='height:30px;'></div>
</td>
</tr>
<tr>
<td align='right' style='color:#ffffff; vertical-align:middle; font-family:arial; font-size:13px;'>User Name</td>
<td align='left'> <input type="text" name="uname" value="" onfocus="this.select()"/> </td>
</tr>
<tr>
<td align='right' style='color:#ffffff; vertical-align:middle; font-family:arial; font-size:13px;'>Password</td >
<td align='left'>
<input type="password" name="pass" value="" onfocus="this.select()"/> </td>
</tr>
<tr>
<td colspan='2' align='right'>
<input type='submit' value='ENTER'/>
</td>
</tr>
</table>
</form>
On check.php, i write like
if($_SERVER['REQUEST_METHOD'] == "POST") {
//code
}
it wont go in that, after that i try
echo $_SERVER['REQUEST_METHOD'] ;
the result return GET.
I have try another pc to run this code, it ok, but come to my pc then cannot,
my pc using xampp,so any different, and how to solve it??
Try if($_POST) to check if it's a POST. Since all pages have $_GET set, if($_GET) will not work. You can also try something like if(count($_GET)>0). That will tell you if there is any $_GET data.
That's because $_SERVER['REQUEST_METHOD'] contains the request method i.e. what method was used to access the page (which will be GET in nearly all cases where you're just requesting a webpage from a browser), NOT any POST or GET data that was submitted from a form. POST data that was submitted from a form should be interfaced with via $_POST.

php redirect to a page

Hello everyone i am trying to write a small addon for my script this is php code :
<?php
if (isset($_SESSION['uid'])) {
header('Location: /members');
} else {
echo '<table width="40%" border="0" align="center" cellpadding="5" cellspacing="2">
<tr align="center" valign="top">
<td bgcolor="#99CC00" class="thinbord"><font color="#FFFFFF"><strong>قسمت ورود کاربران</strong></font></td>
</tr>
<tr align="center" valign="top" bgcolor="#EEF7FF">
<td class="thinbord"><table width="100%" border="0" cellspacing="0" cellpadding="2">
<form action="/members/" method="post">
<tr>
<td height="25" align="center" valign="bottom" class="boxtext"><strong>email :</strong></td>
</tr>
<tr>
<td align="center" class="boxtext"><input type="text" name="email" size="20" maxlength="100"></td>
</tr>
<tr>
<td align="center" class="boxtext"><strong>پسورد:</strong></td>
</tr>
<tr>
<td align="center" class="boxtext"><input type="password" name="passwd" size="20" maxlength="20"></td>
</tr>
<tr>
<td align="center" class="boxtext"><input type="hidden" name="form" value="sent" >
<input name="submit" type="submit" value="login" ></td>
</tr>
<tr>
<td align="center" class="boxtext">lost your pass click here
<br>please check your spam</b></td>
</tr>
<tr>
<td align="center" class="boxtext">sign up</td>
</tr>
</form>
</table></td>
</tr>
</table>';
}?>
Its show even session uid available the script redirect the page to members and if it not available script show a table for login
The session start before i go this page on my index but its not work and not redirect the page to members.
I think this statement require something header('Location: /members');
header('Location: http://www.example.com/');
php.net say like that
The header string.
There are two special-case header calls. The first is a header that starts with the string "HTTP/" (case is not significant), which will be used to figure out the HTTP status code to send. For example, if you have configured Apache to use a PHP script to handle requests for missing files (using the ErrorDocument directive), you may want to make sure that your script generates the proper status code.
The second special case is the "Location:" header. Not only does it send this header back to the browser, but it also returns a REDIRECT (302) status code to the browser unless the 201 or a 3xx status code has already been set.
So, I think you require http:// on your code.
let do like that header('Location: http://www.google.com/');.So, if you redirect to google, code is correct. If not, you have to change something.

How to send SMS using PHP CURL function

I have an account in a website by which I can send sms to mobile phones. In order to do that at first I need to log in using my id and password and then a page shows up where I put the recipient's mobile number and then my message and finally hit the button to send the message.
Now one of my friends told me that I can send sms from my own application through this website using PHP Curl function. I didn't have any prior idea about CURL function so I googled it but I couldn't figure out how to do this. I have checked the HTML code of the login page and the page from where I can send the sms of that website and I am posting it below.
Would you please kindly show me how to send sms using CURL function or any other way.. through this website..
Thanks in Advance :)
Form1
<form name="form" action="/websms/index.php" method="POST">
<input type="hidden" name="HTMLForm_formname" value="form">
<table align="center" size="300" border="0" class="list">
<tr class="r1">
<th colspan="3" class="left">
<label id="label_login_title" for="login_title" class="HTMLForm-label">User Login</label>
</th>
</tr>
<tr>
<td align="right" valign="top">
<label id="label_mobile_no" for="mobile_no" class="HTMLForm-label">Mobile Number</label>
</td>
<td>
<input type="text" id="mobile_no" name="mobile_no" size="20" maxlength="11" value="" onkeypress="return checkNumberOnly(event)" class="HTMLForm-text">
</td>
</tr>
<tr>
<td align="right" valign="top">
<label id="label_password" for="password" class="HTMLForm-label">Password</label>
</td>
<td>
<input type="password" id="password" name="password" value="" class="HTMLForm-password" size="20">
</td>
</tr>
<tr>
<td colspan="3" align="center">
<input type="submit" id="submit" name="submit" value="Login" class="button_all_action">
<input type="hidden" id="submit_login" name="submit_login" value="1">
</td>
</tr>
</table>
</form>
Second Form
<form name="form" action="javascript:get(document.getElementById('form'));" method="POST">
<input type="hidden" name="HTMLForm_formname" value="form">
<table align="center" size="450" border="0" class="list">
<tr class="r2">
<th class="left">
<label id="label_send_to_no" for="send_to_no" class="HTMLForm-label">To</label>
</th>
<td class="left">
<textarea id="send_to_no" name="send_to_no" class="HTMLForm-textarea" onkeypress="checkValidGPNumner(document.form.send_to_no)" onchange="checkValidGPNumner(document.form.send_to_no)" onkeyup="checkValidGPNumner(document.form.send_to_no)" wrap="soft" style="width:250px;height:50px"></textarea>
</td>
</tr>
<tr class="r1">
<th class="left">
<label id="label_message" for="message" class="HTMLForm-label">Message</label>
</th>
<td class="left">
<textarea id="message" name="message" class="HTMLForm-textarea" onkeypress="textCounter(document.form.message,document.form.counter_message,160)" onchange="textCounter(document.form.message,document.form.counter_message,160)" onkeyup="textCounter(document.form.message,document.form.counter_message,160)" wrap="soft" style="width:250px;height:130px"></textarea>
<input type="text" id="counter_message" name="counter_message" size="5" value="" readonly="" class="HTMLForm-text"> <label id="label_char_remain" for="char_remain" class="HTMLForm-label">Character remained</label>
</td>
</tr>
<tr class="r2">
<td colspan="2" class="center">
<input type="submit" id="submit" name="submit" value="Send" class="button_all_action">
<input type="hidden" id="mid" name="mid" value="1">
<input type="hidden" id="submit_sms" name="submit_sms" value="1">
</td>
</tr>
</table>
</form>
Simple CURL Function to send sms:
function CURLsendsms($number, $message_body){
$api_params = $api_element.'?apikey='.$apikey.'&sender='.$sender.'&to='.$mobileno.'&message='.$textmessage;
$smsGatewayUrl = "http://springedge.com";
$smsgatewaydata = $smsGatewayUrl.$api_params;
$url = $smsgatewaydata;
$ch = curl_init(); // initialize CURL
curl_setopt($ch, CURLOPT_POST, false); // Set CURL Post Data
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$output = curl_exec($ch);
curl_close($ch); // Close CURL
// Use file get contents when CURL is not installed on server.
if(!$output){
$output = file_get_contents($smsgatewaydata);
}
}
You can indeed send SMS messages with cURL, but cURL is just one part of it. Using cURL, you'd make API calls to a provider like Twilio.
This is a solution using Twilio.
First of all you have to download the twilio library for PHP:
https://github.com/twilio/twilio-php/downloads
Then copy the Services folder in your Server and take in mind the location.
Now you have to create a simple program like the one below, (this is an example an easy php sms sender):
<?php //lets say that the name of this php is smsSender.php
$contactname = $_POST['name'];
$contactphone = $_POST['mobile_no'];
$message = $_POST['message'];
require 'Services/Twilio.php';//<<<<<<<<<HERE! make sure the path is ok.
$AccountSid = "AXXXXXX"; // this numbers you can find it in your twilio dashboard
$AuthToken = "TXXXXXXXXX";// also this number .
$client = new Services_Twilio($AccountSid, $AuthToken);
$people = array(
//"4566789903" => "Curious George",
$contactphone => $contactname,
);
foreach ($people as $number => $name) {
$sms = $client->account->sms_messages->create("7035960031",$number,
$message);
echo "Sent message to $name";
}
?>
So you will need to change in your forms the action like this:
<form name="form" action="smsSender.php" method="POST">
Note: if you are using a trial account, you will be only able to send to verified numbers in your account, but if you register a phone number (1USD/month) then you can send to any number and without the sandbox message).
IMPORTANT: Curl library must be installed in the php server, if you are using your own server, lets say in UBUNTU, this command will install those libraries:
sudo apt-get install curl libcurl3 libcurl3-dev php5-curl
After changing to this, the code worked great for me.
foreach ($people as $number => $name) {
$client->account->messages->sendMessage("+12055xxxxxx",$number,
$message);
I am not sure that you can send SMS's with CURL, however you can with PHP's mail function.
I have never done so however.
Curl basically used for scrapping contents from another web site, it doesnt have any function to send sms. You have to use other way.
there re few tools by which you can connect to your sms (text Server) from there you can send sms. you can use curl to get your sms replies or etc later part if you need and eager to use that.

How do I use curl to display a table on a page?

I want to use curl to retrieve a table from an external page. So far my code retrieves all data from the page. I have read that using preg_match or preg_replace is the way to go about it.
This is my code so far:
<?php
$ch = curl_init() or die(curl_error());
curl_setopt($ch, CURLOPT_URL,"http://www.megaupload.com/?d=XE30L1GA&w=631&h=392");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$data1=curl_exec($ch) or die(curl_error());
echo "<font color=black face=verdana size=3>".$data1."</font>";
echo curl_error($ch);
curl_close($ch);
?>
This is the data I want to retrieve from the page:
<FORM method="POST" id="captchaform">
<INPUT type="hidden" name="captchacode" value="1a589e0a53c54f937eb8">
<INPUT type="hidden" name="megavar" value="bed55b1a7a26e4bb0aa11df4188f58bda6958d72856a637ca55cbda4c24c89b97d52e39e3a2d1d26082273dec61e68416bd929d566cf63cd8441e9f6166d667618060608c5d63c9341e72fc036ea4ed1ec8d099bc488fa1f3c5df7228e10a0f79c4e5fb78fe41f0d9873194c56f94dfbcc008e4a7c8ebc58c8169d42cb98a9a86d8cb6dfbae8791b9dfcf5a3119f7941cc07e9ba48934ad9b5f865cd32e71bf6d3a3954ddc4e75925aaf2c0ec6d1dd884ccc4d299be3e41957a967e68a143af49d6b7ff7b36dac725f20214e58feb32662e09f5840ac76cff67f7d99e67ffb485d72382dd20cece80e4307dfef720a51734d7f9a4a363de0950d3d0e927423642a79b2e68ed177d2ad2d877c1c2052969ec61737749b05864b3a74d241981d6b89">
<TR>
<TD>Enter this </TD>
<TD width="100" align="center" height="40"><img src="http://wwwq32.megaupload.com/gencap.php?23243f17c2404dd4.gif" border="0" alt=""></TD>
<TD> here:</TD>
<TD><input type="text" name="captcha" id="captchafield" maxlength="4" style="border:solid 1px; border-color:#C4C4C4; background-color:#F9F9F9; width:50px; height:25px;"></TD>
</TR>
</FORM>
preg_*() is certainly not the way to do it. Use a HTML parser.

Categories