error with curl on post - php

this is my index
<body>
<form id="form1" method="post" name="entrar" action="procesar.php">
<p>Usuario
<label for="username">:</label>
<input type="text" name="username" id="username">
</p>
<p>
<label for="pass">Clave:</label>
<input type="password" name="pass" id="pass">
</p>
<p>
<input type="submit" name="entrar" id="button" value="Enviar">
</p>
</form>
</body>
this is de code of procesa.php when check the values username and pass
<?php
if($_POST['entrar']){
$user = $_POST['username'];
$pass = $_POST['pass'];
if($user == 'gato' && $pass == 'gato'){
setcookie('control','1234',time()+30000,'/','www.onlinelatino.org');
header("Location: sitio.php");
}
else{
header("Location: error.php");
}
}
else{
echo "error inclucion no valida";
}
?>
later go to here
<!doctype html>
<html>
<head><title>Welcome</title></head>
<body>
<?php
$control = $_COOKIE['control'];
if($control == 1234){
?>
<h1>Hola mundo</h1>
<h2>Como estas</h2>
<?php
}
else{
echo "No estas logado";
}
?>
</body>
</html>
this work fine but i wanna access to site when a robots this is a code
<?php
$parametros_post = 'username='.urlencode("gato").'&pass='.urlencode("gato").'&entrar'.urlencode("Enviar");
$cookie_file = "cookie.txt";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "http://www.onlinelatino.org/curl/procesar.php");
curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 5.01 Windows NT 5.0)");
curl_setopt($ch, CURLOPT_HTTPHEADER, array("Accept-Language: es-es, en"));
curl_setopt($ch, CURLOPT_POST, TRUE);
curl_setopt($ch, CURLOPT_POSTFIELDS, $parametros_post);
curl_setopt($ch, CURLOPT_HEADER, FALSE);
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie_file);
curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie_file);
$result = curl_exec($ch);
$error = curl_error($ch);
curl_close($ch);
echo $result;
echo $error;
?>
but no start the sesion with the cookie
only say say this "error inclucion no valida" this are on procesar.php
the link of the example is this
http://www.onlinelatino.org/curl/index.html
and the robot is this
http://www.onlinelatino.org/curl/bot.php
I don't have idea when are the error

'&entrar'.urlencode("Enviar")
You're missing an =
'&entrar='.urlencode("Enviar")

Related

instagram profile scraper - redirect to login page [PHP]

i have an script and its work without problems on local host.
here is my code ...
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
</head>
<body>
<?php
if(isset($_POST['username'])){
$username=$_POST['username'];
//echo $username;
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,"https://www.instagram.com/$username/?__a=1");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10);
curl_setopt($ch, CURLOPT_TIMEOUT,10);
// curl_setopt($ch, CURLOPT_FAILONERROR,true);
// curl_setopt($ch, CURLOPT_ENCODING,"");
// curl_setopt($ch, CURLOPT_VERBOSE, true);
// curl_setopt($ch, CURLINFO_HEADER_OUT, true);
// curl_setopt($ch, CURLOPT_HEADER, true);
$result = curl_exec($ch);
curl_close($ch);
$json=json_decode($result);
//var_dump($json);
$insta_profile_picture= $json->graphql->user->profile_pic_url_hd;
}
else{
}
?>
<form method="post" action="">
<input type="text" name="username" placeholder="Type Your Username of Instagram " style="width:300px;height: 30px;border-radius: 4px;">
<input type="submit" name="submit" style="width:300px;height: 35px;border-radius: 4px;">
</form>
<?php
if(isset($_POST['username'])){
if($insta_profile_picture){
//echo $insta_profile_picture;
$imageData = base64_encode(file_get_contents($insta_profile_picture));
echo '<img src="data:image/jpeg;base64,'.$imageData.'">';}
else{
echo "something wrong";
}
}
else{
echo "please select your username on top input for checking profile photo";
}
?>
</body>
</html>
but it not work on my server and with tracking the result i understand its redirect to https://www.instagram.com/accounts/login/
please help me
tnx a lot for your helping

ask about send image failed using telegram API?

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);
?>

PHP - Curl - Form Issues

I have a script to check if a email:password is in my site, But I want to be able to mass check this by being able to copy and paste a bunch of Email:password's into seperate lines in a textarea, when you do that and click submit it will seperate Email from the :pass aswell as pass with email: and put them into a variable and check them with curl one by one. No idea where I would start with this but for the email:pass seperation im guessing explode()?
PHP:
<?php
if(isset($_POST['email']) && isset($_POST['pass'])){
$URL = 'http://example.com/api/?checkere='.$_POST['email'].'&checkerp='.$_POST['pass'];
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $URL);
curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.95 Safari/537.36');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
$page = curl_exec($ch);
if (strpos($page, '<title>Works</title>') !== false) {
file_put_contents('output.txt',$_POST['email'].':'.$_POST['pass'].' is Working!');
} else {
file_put_contents('output.txt',$_POST['email'].':'.$_POST['pass'].' is Invalid!');
}
}
?>
API:
<?php
if(isset($_GET['email']) && isset($_GET['pass'])) {
$email=$_GET['email'];
$pass=$_GET['pass'];
$url='https://example.com/Login';
$cookie="cookie.txt";
$ch2 = curl_init();
curl_setopt ($ch2, CURLOPT_URL, $url);
curl_setopt ($ch2, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt ($ch2, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.31 (KHTML, like Gecko) Chrome/26.0.1410.64 Safari/537.31");
curl_setopt ($ch2, CURLOPT_TIMEOUT, 60);
curl_setopt ($ch2, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt ($ch2, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt ($ch2, CURLOPT_RETURNTRANSFER, 1);
curl_setopt ($ch2, CURLOPT_COOKIEJAR, $cookie);
curl_setopt ($ch2, CURLOPT_REFERER, $url);
$result2 = curl_exec ($ch2);
curl_close($ch2);
$expA=explode('name="authURL" value="',$result2);
$expB=explode('"/>',$expA[1]);
$auth=$expB[0];
$postdata = http_build_query( array('email' => urlencode($email), 'password' => $pass, 'authURL' => urlencode($auth)));
$postdata = http_build_query( array('email' => $email, 'password' => $pass, 'authURL' => $auth, 'RememberMe' => ''));
$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 NT 6.1) AppleWebKit/537.31 (KHTML, like Gecko) Chrome/26.0.1410.64 Safari/537.31");
curl_setopt ($ch, CURLOPT_TIMEOUT, 60);
curl_setopt ($ch, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt ($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt ($ch, CURLOPT_COOKIEFILE, $cookie);
curl_setopt ($ch, CURLOPT_COOKIEJAR, $cookie);
curl_setopt ($ch, CURLOPT_REFERER, $url);
curl_setopt ($ch, CURLOPT_POSTFIELDS, $postdata);
curl_setopt ($ch, CURLOPT_POST, 1);
$result = curl_exec ($ch);
echo $result;
curl_close($ch);
}
?>
My Current HTML:
<!DOCTYPE html>
<html lang="en" class="no-js">
<head>
<title>Account Checker</title>
<!-- Meta Data -->
<?php include('../../metadata.php'); ?>
<!-- Stylesheets -->
<?php include('../../assets/css/stylesheets.php'); ?>
</head>
<body>
<!-- Menu -->
<?php include('../../ui/menu.php'); ?>
<!-- Notifications -->
<?php include('../../ui/notifications.php'); ?>
<!-- Content -->
<div class="footer" style="overflow:auto;"><div class="container"><div class="footer_top">
<div class="wow"><h1>Account Checker</h1></div>
<div class="wow">
<form action="output.php" method="post"><span>
<i><img src="//example.com/assets/img/login.png" alt=""></i>
<input type="text" placeholder="Email" id="minime_url_textbox" name="email">
<br>
<i><img src="//example.com/assets/img/login.png" alt=""></i>
<input type="text" placeholder="Password" id="minime_url_textbox" name="pass">
<label class="btn1 btn2 btn-2 btn-2g"> <input name="submit" type="submit" id="submit" value="Check"> </label>
<div class="clearfix"> </div>
</span></form>
</div></div>
<div class="copy wow">
<?php include('../../ui/footer.php'); ?>
</div>
</div></div>
<!-- Javascript -->
<?php include('../../assets/scripts/javascript.php'); ?>
</body>
</html>
The referenced output.php in just contains the first PHP mentioned above.
How could I do this? Couldnt find any helpful information online.

curl sending information POST method

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'));

php curl - send post values (with header: location)

is the first time that I compile with a curl: i'm trying to use it to send post values with header. i did many tests, but probably I mistake something because I in output don't see my post vars.
form page:
<html>
<form action="analize.php" method="post">
<input type="text" name="people" value="" />
<input type="submit" value="Send" />
</form>
</html>
analize.php:
<?php
$url = 'test.php';
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_POST, true);
curl_exec($ch);
curl_close($ch);
header('Location: ' . $url);
exit;
?>
test.php:
<?php
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'analize.php');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch,CURLOPT_HEADER,true);
curl_exec($ch);
$post = curl_getinfo($ch);
curl_close($ch);
var_dump($post);
?>

Categories