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" />
Related
I am trying to use Namecheap's API for domain information, although their API documentation doesn't explain very well and it would be the first time that I am using XML data, I'm trying to return the data from the XML file.
I am currently using a form to add variables and POST/GET data to this XML request, on submit, the XML page displays and that is the end of that.
I am wondering how it is possible to send and receive this data using PHP?
Here is what I have so far...
Very Simple:
<form action="https://api.namecheap.com/xml.response" method="POST">
<input type="hidden" id="ApiUser" name="ApiUser" value="user" />
<input type="hidden" id="UserName" name="UserName" value="user" />
<input type="hidden" id="ApiKey" name="ApiKey" value="###" />
<input type="hidden" id="Command" name="Command" value="namecheap.domains.check" />
<input type="hidden" id="ClientIp" name="ClientIp" value="<? echo $_SERVER['REMOTE_ADDR']; ?>" />
<input type="text" id="DomainList" name="DomainList" />
</form>
Like I said, this sends me straight through to the XML file. I am thinking that I probably need to perform a POST ISSET or something...
<?
if(isset($_POST['domain_check'])){
PERFORM XML STUFF HERE
}
?>
Yet I don't have a clue how to send or receive data in this way as I am a beginner. The data is returned like so:
<ApiResponse xmlns="http://api.namecheap.com/xml.response" Status="OK">
<Errors/>
<Warnings/>
<RequestedCommand>namecheap.domains.check</RequestedCommand>
<CommandResponse Type="namecheap.domains.check">
<DomainCheckResult Domain="test.com" Available="false" ErrorNo="0" Description="" IsPremiumName="false" PremiumRegistrationPrice="0" PremiumRenewalPrice="0" PremiumRestorePrice="0" PremiumTransferPrice="0" IcannFee="0" EapFee="0"/>
</CommandResponse>
<Server>PHX01APIEXT01</Server>
<GMTTimeDifference>--4:00</GMTTimeDifference>
<ExecutionTime>1.061</ExecutionTime>
</ApiResponse>
Please inform me with the best way to do this? Thanks.
To parse the response try using simple_xml,
$xml=simplexml_load_string($myXMLData) or die("Error: Cannot create object");
print_r($xml);
Try using cURL so you don't have to submit a form manually, I haven't tested this but this example should help get you going
<?php
$ch = curl_init();
$baseUrl = 'https://api.sandbox.namecheap.com/xml.response?ApiUser=ncuser&ApiKey=apikey&UserName=ncuser&ClientIp=121.22.123.22&Command=namecheap.domains.check&DomainList=domain1.com,domain2.com';
$url = $baseUrl . $query;
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
$output = curl_exec($ch);
if ($output === false) {
die(curl_error($ch));
}
//print_r(curl_getinfo($ch));
curl_close($ch);
return $output;
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
Let's imagine the following situation:
You have a simple php page with an html form that allows the user to enter the following data:
Phone Number
Text Message
Such as:
<form action="xml-file.xml" method="get">
<input type="text" id="to" name="to" value="" />
<input type="text" id="text" name="text" value="" />
<input type="submit" />
</form>
Now, you create an XML using this method that I've tested and works without a problem, and afterwards you want to send it via URL using this other method (CURL).
Unfortunately, I can't reach the CURL method, as I can't link the submit action to both create the XML and send it to an URL so it goes to a local server (www.example.xxx:1234) and afterwards processes that XML for sending an SMS.
That server sends a response if the format of the XML is the right one. My issue is, therefore, on the submission of the created XML.
Help?
Update 1: Adding the updated code. This allows me (with a chmod 777 onto the sms.xml file) to edit the xml file at will.
index.php
<html>
...
<form action="send.php" method="get">
<input type="text" id="to" name="to" value="" />
<input type="text" id="text" name="text" value="" />
<input type="submit">
</form>
...
</html>
send.php
<?php
$xml = simplexml_load_file("sms.xml"); // Load XML file
$xml->Title3 = $_GET['to']; // Updating <Title3> from GET method
$xml->Title5[0]->Title51Content = $_GET['text']; // Updating <Title51> from GET method
$xml->asXML('sms.xml'); // Saving the XML file
?>
sms.xml
<?xml version="1.0" encoding="UTF-8"?>
<Title1>
<Title2>Some Text</Title2>
<Title3>Variable 1</Title3>
<Title4>Some Text</Title4>
<Title5>
<Title51>Variable 2</Title51>
</Title5>
</Title1>
Side note: XML should have, when sending, the "Content-Type","application/x-www-form-urlencoded" header for returning something like this:
XML=%3C%3Fxml+version%3D%221.0%22+encoding%3D%22UTF-8%22%3F%3E%0A%3...
Thanks!
Return the XML as a string and post it?
...
$xml_post_string = 'XML='.urlencode($xml->asXML());
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'http://theurl.com');
curl_setopt($ch, CURLOPT_POST, TRUE);
curl_setopt($ch, CURLOPT_POSTFIELDS, $xml_post_string);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$response = curl_exec($ch);
curl_close($ch);
...
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.
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.