I have added this basic login page to server for testing curl form submitting:
<?php
if(isset($_POST['submit'])){
$email = $_POST['email'];
$password = $_POST['password'];
if($email == "email#gmail.com"){
if($password == "123456"){
echo "Correctamundo!";
}else{
echo "Wrong pass";
}
}else{
echo "Wrong Email";
}
}
?>
<!DOCTYPE html>
<html>
<head>
<title>Login Form</title>
</head>
<body>
<form method="POST" action="">
<input type="email" name="email" value="">
<input type="password" name="password" value="">
<input type="submit" value="Submit" name="submit">
</form>
</body>
</html>
So if the email equals to email#gmail.com && the password was 123456, the Correctamundo message appears on the page.
Now with curl at another file I've added this:
<?php
$data = array(
"email" => "email#gmail.com",
"password" => "123456",
"form" => "submit"
);
$ch = curl_init("http://sitename.com/login.php");
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); // Allow Redirections
curl_setopt($ch, CURLOPT_POST, true); // Making a POST request
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_COOKIEJAR, 'cookie.txt'); // COOKIE-jar: To save data for cookie created for login process
curl_setopt($ch, CURLOPT_COOKIEFILE, 'cookie.txt');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); // TRUE means Don't just echo output the data instead we can store the Request response in some variable
$result = curl_exec($ch);
curl_close($ch);
echo $result;
?>
Now as you can see I have passed the correct credentials as $data array. But when I load the page, I don't get the Correctamundo message as success message.
So why is that? What am I doing wrong here?
Related
The Mailchimp API returns error 400 if I try to subscribe a user that is already subscribed. Then I found that if I unsubscribe and attempt to resubscribe again I also get error 400. Is there a way to differentiate between these cases?
Mailchimp's error documentation says that 400 is returned for different reasons (bad request, invalid resource, invalid action, JSON parse exception). There doesn't seem to be a way to get more specific messages, and certainly no way to determine whether the issue is that user is already subscribed vs. recently unsubscribed.
Any idea how to return more useful error messages?
Here is my test code (based on this reference):
<?php
$statusMsg = '';
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['subscribe'])) {
if (!empty($_POST['email']) && !filter_var($_POST['email'], FILTER_VALIDATE_EMAIL) === false) {
// input sanitation
array_walk_recursive($_POST, function(&$value) {
$value = htmlspecialchars(stripslashes(trim($value)));
});
$fname = $_POST['fname'];
$lname = $_POST['lname'];
$email = $_POST['email'];
// MailChimp API credentials
$apiKey = '<my test API key>';
$listId = '<my list id>';
// MailChimp API URL
$dataCenter = substr($apiKey,strpos($apiKey,'-') + 1);
$url = 'https://' . $dataCenter . '.api.mailchimp.com/3.0/lists/' . $listId . '/members/';
// member information
$json = json_encode([
'email_address' => $email,
'status' => 'subscribed',
'merge_fields' => [
'FNAME' => $fname,
'LNAME' => $lname
]
]);
// send a HTTP POST request with curl
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_USERPWD, 'user:' . $apiKey);
curl_setopt($ch, CURLOPT_HTTPHEADER, ['Content-Type: application/json']);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST');
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_POSTFIELDS, $json);
$result = curl_exec($ch);
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
// store the status message based on response code
if ($httpCode == 200) {
$statusMsg = '<p style="color: #34A853">You have successfully subscribed.</p>';
} else {
switch ($httpCode) {
case 400: // problem: this also happens when user is unsubscribed
$msg = 'You are already subscribed.';
break;
default:
$msg = 'Some problem occurred, please try again. Error code ' . $httpCode . '.';
break;
}
$statusMsg = '<p style="color: red;">'.$msg.'</p>';
}
} else {
$statusMsg = '<p style="color: red;">Please enter valid email address.</p>';
}
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Mailchimp API Test</title>
<link rel="stylesheet" href="style.css">
</head>
<body>
<main>
<div id="container">
<h1>Subscribe to our Newsletter</h1>
<?php echo $statusMsg; ?>
<form method="post">
<input type="text" name="subscribe" value="subscribe" aria-hidden="true" readonly hidden>
<p><label for="fname"> First Name:</label><br>
<input id="fname" type="text" name="fname" /></p>
<p><label for="lname"> Last Name:</label><br>
<input id="lname" type="text" name="lname" /></p>
<p><label for="email"> Email address:</label><br>
<input id="email" type="text" name="email" /></p>
<input type="submit" value="Submit" />
</form>
</div>
</main>
</body>
</html>
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
This site helped me out a lot last time I had an issue. I was wondering why this php code was not working. Any help would be appreciated. I am trying to make a custom user creation request with ZenDesk.
I got the request to work, but when I edited the code to fit it into the actual Instance of my CRM it does not even try to make a PHP request. I verified this should be possible if the code is correct. I Just can not figure out why it is not correct.
<?php
include("config.php");
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://url/api/v2/users.json");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, "{\"user\": {\"name\": \"$name\",
\"email\": \"$email\", \"phone\": \"$phone"}}");
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_USERPWD, "email" . ":" . "password");
$phone = phone;
$email = email;
$name = name;
$headers = array();
$headers[] = "Content-Type: application/json";
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$result = curl_exec($ch);
if (curl_errno($ch)) {
echo 'Error:' . curl_error($ch);
}
if ( !isset ($_POST['Name']) ||
!isset ($_POST['Name'] ||
!isset ($_POST['phone']
)
{
}
curl_close ($ch);
?>
<!DOCTYPE html>
<html>
<body>
<form
action="://url/agent/users/{{user.id}}/requested_tickets">
First name:<br>
<input type="text" name="name" value="name">
<br>
Last name:<br>
<input type="text" name="email" value="email">
<br><br>
<input type="text" name="phone" value="+15555555555">
<br><br>
<input type="submit" value="Submit">
</form>
<p>If you click the "Submit" button, the form-data will be sent to a
page
called "/action_page.php".</p>
</body>
</html>
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")
I know my curl script works correctly. I can hardcode the email and pass in curl and it works fine, but now I am trying to create a php script to input it and it doesn't work. I will post links and code below.
I am using the input email#ccc.com:passss.
http://cyber-hosted.com/CH/index.html
<html>
<head>
</head>
<body>
<form action="n.php" method="post">
<input type="text" name="mail />
<input type="password" name="pass" />
</form>
</body>
http://cyber-hosted.com/CH/n.php
<?php
$usermail = $_POST['Mail'];
$pass = $_POST['pass'];
$url = "https://secure.tesco.com/register/default.aspx?vstore=0";
//
$h = curl_init();
curl_setopt($h, CURLOPT_URL, $url);
curl_setopt($h, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($h, CURLOPT_POST, true);
curl_setopt($h, CURLOPT_POSTFIELDS, "form=fSignin&from=https%3A%2F%2Fsecure.tesco.com%2Fclubcard%2Fmyaccount%2Fhome.aspx&formData=bmV3UmVnPWZhbHNlJg%3D%3D&loginID=$usermail&password=$pass&seamlesswebtag=&confirm-signin.x=47&confirm-signin.y=18");
curl_setopt($h, CURLOPT_HEADER, true);
curl_setopt($h, CURLOPT_RETURNTRANSFER, true);
curl_setopt($h, CURLOPT_COOKIEJAR, 'cookies.txt');
curl_setopt($h, CURLOPT_COOKIEFILE, 'cookies.txt');
curl_setopt($h, CURLOPT_FOLLOWLOCATION, true);
//
$result = curl_exec($h);
echo $result;
?>
You typed mail with uppercase:
$usermail = $_POST['Mail'];
// here -----^
Change it to:
$usermail = $_POST['mail'];
Ah and I almost forgot the double quotes here:
<input type="text" name="mail />
<!-- here --------^ --->
It should be <input type="text" name="mail" />
Try giving the fields a value attribute
<input type="text" name="mail" value=""/>
<input type="password" name="pass" value=""/>
Also you are missing the submit button from your supplied code
<input type="submit" name="submit" value="Submit"/>
And finally you should URL encode the usermail and password parameters in the cURL request.