Now Delicious is closing down, I tried to make a PHP form for a few friends to use to download there bookmarks:
Vising this url: https://api.del.icio.us/v1/posts/all
You get prompted for a username and password then presented with XML, I want to automate the download of the XML returned.
<?php
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_USERPWD, "$username:$password");
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
$output = curl_exec($ch);
$info = curl_getinfo($ch);
curl_close($ch);
$username = $_POST['username'];
$password = $_POST['password'];
$url = "https://api.del.icio.us/v1/posts/all"
?>
<form ACTION="<?php echo $PHP_SELF;?>" name="bookmarkform" METHOD="POST" align="center">
<table>
<tr>
<td>
<label>Username</label>
</td>
<td>
<input NAME="username" tabindex="1">
</td>
</tr>
<tr>
<td>
<label>Password</label>
</td>
<td>
<input NAME="password" tabindex="2">
</td>
</tr>
<tr>
<td>
</td>
<td>
<input TYPE="submit" tabindex="3" value="Submit!">
</td>
</tr>
</table>
</form>
Im missing something here but cant see what? Any help appreciated : )
Well, I'm not familiar with Delicious API, but my first suggestions is not to use undefined variables:
<?php
$username = $_POST['username'];
$password = $_POST['password'];
$url = "https://api.del.icio.us/v1/posts/all"
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_USERPWD, "$username:$password");
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
$output = curl_exec($ch);
$info = curl_getinfo($ch);
curl_close($ch);
?>
Related
I just developed a sample of firebase with apps server in my live webserver.
I tried it on my localhost pc (offline) and firebase notification are sent on virtual devices android.
But when i try to install apk file into my phone devices and transfer PHP file into my live server (i.e www.aaa.com).
Firebase notification does not work at all. it doesn't send into my phone devices.
Am i missing something on the code ? . The code as below. Thanks.
<?php
require "connect.php";
global $con;
if(isset($_POST['Submit'])){
$message = $_POST['message'];
$title = $_POST['title'];
$path_to_fcm = 'https://fcm.googleapis.com/fcm/send';
$server_key = "SERVER KEY HERE";
echo "Data sent ! <br/>";
$sql = "SELECT fcm_token FROM fcm_info";
$result = mysqli_query($con, $sql);
$row = mysqli_fetch_row($result);
$key = $row[0];
$headers = array('Authorization:key=' .$server_key, 'Content-Type:application/json');
$fields = array('to' => $key, 'notification' => array('title' => $title, 'body'=> $message));
$payload = json_encode($fields);
$curl_session = curl_init();
curl_setopt($curl_session, CURLOPT_URL, $path_to_fcm);
curl_setopt($curl_session, CURLOPT_POST, true);
curl_setopt($curl_session, CURLOPT_HTTPHEADER, $headers);
curl_setopt($curl_session, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl_session, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl_session, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4);
curl_setopt($curl_session, CURLOPT_POSTFIELDS, $payload);
$result = curl_exec($curl_session);
curl_close($curl_session);
mysqli_close($con);
}
?>
<!DOCTYPE html>
<html>
<head>
<title>Send Notification</title>
</head>
<body>
<form action='send_notification.php' method="POST">
<table>
<tr>
<td>Title : </td>
<td><input type="text" name="title" required="required" /></td>
</tr>
<tr>
<td>Message : </td>
<td><input type="text" name="message" required="required" /></td>
</tr>
<tr>
<td><input type="submit" name="Submit" value="Send notification"></td>
</tr>
</table>
</form>
</body>
</html>
<?php
$ch = curl_init("https://fcm.googleapis.com/fcm/send");
$header=array('Content-Type: application/json',
"Authorization: key=YOUR KEY");
curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
curl_setopt( $ch,CURLOPT_SSL_VERIFYPEER, false );
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, "{ \"notification\": { \"body\": \"Weather Forecast\",
\"title\": \"YOur title\",
\"to\" : \"YOUR DEVICE REG TOKEN\"}"
curl_exec($ch);
curl_close($ch);
?>
go to your firebase console the project settings> select second tab 'cloud messaging' there would be your server key which your will need in your php file ;)
now i'm work with telegram API. i want send an image with this API but my code doesnt work, when i run it, i have a blank response.
here is my code :
<?php
$comment= $_POST['tag'];
$url = 'https://api.telegram.org/botMY_BOT_ID/sendPhoto';
try {
$curl_connection = curl_init($url);
curl_setopt($curl_connection, CURLOPT_POST, true);
curl_setopt($curl_connection, CURLOPT_HTTPHEADER, array(
"Content-Type:multipart/form-data"));
curl_setopt($curl_connection, CURLOPT_URL, $url);
curl_setopt($curl_connection, CURLOPT_POSTFIELDS, http_build_query(array('chat_id'=>'chatid','photo' => "#"."maldini.jpg")));
//curl_setopt($curl_connection, CURLOPT_INFILESIZE, filesize("path/to/maldini.jpg"));
curl_setopt($curl_connection, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl_connection, CURLOPT_SSL_VERIFYPEER, false);
//Data are stored in $data
$data = curl_exec($curl_connection);
curl_close($curl_connection);
} catch(Exception $e) {
return $e->getMessage();
}
?>
but, when i try send image with just html, i works perfectly. here is my html code :
<form method="POST" action="https://api.telegram.org/botMY_BOT_ID/sendPhoto" enctype="multipart/form-data">
<label>
<span>chat_id :</span>
<input id="chat_id" type="text" name="chat_id" value="chat_id" />
</label>
<label>
<span>caption :</span>
<input id="caption" type="text" name="caption"/>
</label>
<label>
<span>photo</span>
<input id="photo" type="file" name="photo" />
</label>
<label>
<span> </span>
<input type="submit" class="button" value="sendPhoto" />
</label>
</form>
whats wrong??? any help would be appreciate, thanks in advance :)
just need to pass chat_id with the url, try this code
<?php
$url = "https://api.telegram.org/bot<bot_id>/sendPhoto?chat_id=".$chat_id ;
$post_fields = array('chat_id' => $chat_id,'photo'=> "/path/to/image.png");
$ch = curl_init();
curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-Type:multipart/form-data"));
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_fields);
$output = curl_exec($ch);
echo "<pre>"; print_r($output);
?>
Please help, i spent 3 days now for solving of this problem.
I try get authorization and show after page like "/index.php?page=xml", but I get only login page, some cookies saved to local server.
Here is PHP curl code:
<?php
$login = 'XX';
$password = 'XX';
$site = 'http://site';
$cookies = dirname(__FILE__) . '/cookies.txt';
$automatic = curl_init();
curl_setopt($automatic, CURLOPT_USERAGENT, $user_agent);
curl_setopt($automatic, CURLOPT_REFERER, "http://google.com/");
curl_setopt($automatic, CURLOPT_TIMEOUT, 10);
curl_setopt($automatic, CURLOPT_URL, $site . '/index.php?page=index');
curl_setopt($automatic, CURLOPT_RETURNTRANSFER, true);
curl_setopt($automatic, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($automatic, CURLOPT_POST, true);
curl_setopt($automatic, CURLOPT_POSTFIELDS, "user.auth.login=$login&user.auth.pass=$password");
curl_setopt($automatic, CURLOPT_COOKIEFILE, $cookies);
curl_setopt($automatic, CURLOPT_COOKIEJAR, $cookies);
curl_exec($automatic);
curl_setopt($automatic, CURLOPT_URL, $site. '/index.php?page=xml');
$demo = curl_exec($automatic);
curl_close($automatic);
echo $demo;
?>
Cookies.txt:
site FALSE / FALSE 1429273488 def.sess.number 2a86dcf7d2a896f323fb2931337efe60
The site form:
<form name=enterform action="/index.php?page=index" method=post>
<table border=0 cellspacing=0 cellpadding=2 width=740>
<tr>
<td valign=bottom bgcolor=#01568D width=80>
<input type=input maxlength=32 size=9 class="logindata" name="user.auth.login" value="" onKeyDown="return TrapKeyDown(event);" onKeyPress="return TrapKeyPress(event);"><br>
<input type=password maxlength=32 size=9 class="logindata" name="user.auth.pass" onKeyDown="return TrapKeyDown(event);" onKeyPress="return TrapKeyPress(event);">
</td>
</tr>
<tr>
<td bgcolor=#01568D height=40 colspan=2 align=right valign=bottom><font class="startbuttons">LOGIN</font> </td>
</tr>
</table>
</form>
Whagt I do wrong?
I am trying to create a remote login to one website using mine. The users will need to enter their username and password on my site, and if they are registered to my website, their login credentials will be sent to another website and a page will be retrieved.
I am stuck at sending the users' data to the original site. The original site's viewsource is this..
<form method=post>
<input type="hidden" name="action" value="logon">
<table border=0>
<tr>
<td>Username:</td>
<td><input name="username" type="text" size=30></td>
</tr>
<tr>
<td>Password:</td>
<td><input name="password" type="password" size=30></td>
</tr>
<td></td>
<td align="left"><input type=submit value="Sign In"></td>
</tr>
<tr>
<td align="center" colspan=2><font size=-1>Don't have an Account ?</font> <font size=-1 color="#0000EE">Sign UP Now !</font></td>
</tr>
</table>
This is located at http://www.example.com/index.php
I have tried this code, but not works. This I got from someone who has answered at another question.
<?php
$username="username";
$password="password";
$url="http://www.example.com/index.php";
$postdata = "username=".$username."&password=".$password;
$ch = curl_init();
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_REFERER, $url);
curl_setopt ($ch, CURLOPT_POSTFIELDS, $postdata);
curl_setopt ($ch, CURLOPT_POST, 1);
$result = curl_exec ($ch);
header('Location: track.html');
//echo $result;
curl_close($ch);
?>
Any help would be appreciated, Thanks in advance.
This is unsecure, but it's a way to do it
<?php
if (isset($_POST['username']))
{
file_get_contents("http://otherwebsite/page.php?login=".$_POST['username']."&password=".$_POST['password'])
}
?>
I am trying to pass data from an HTML form POST using curl, does anyone know how to do this?
My code: (dtda.php)
<?php
// HTTP authentication
$url = "http://siteapi.com.br:9988/api";
$ch = curl_init();
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_USERPWD, "Teste:123456");
$result = curl_exec($ch);
curl_close($ch);
echo $result;
?>
My second code HTML: (sending.html)
<form name="myform" id="myform" action="http://endereco.com.br/dtda.php" method="post" >
<input type="text" name="op" value="event"/>
<input type="text" name="seq" value="45" />
<input type="text" name="type" value="nexttrack" />
<input type="text" name="priority" value="1" />
<input type="submit" style="padding-left:10px; padding-right:10px" class="button compact" onclick="javascript:openlive()" value="Ativar agendamento" /><p></form> <br /><br />
</form>
As I pass the form data to the "endereco.com.br/dtda.php" ?
try
$url = "http://siteapi.com.br:9988/api";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS,
http_build_query(array('yourData' => $data)));
// receive server response ...
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$server_output = curl_exec ($ch);
curl_close ($ch);
If you want to forward the posted data to another URL, you can add it like this:
curl_setopt($ch, CURLOPT_POSTFIELDS, file_get_contents('php://input'));