I have been trying to make Twitter reply code using PHP and it didn't work. When I run it it just post it as a tweet without the reply to the tweet id.
in_reply_to_status_id doesn't work when I run the code.
is there any solution?
<form action="<?php echo $PHP_SELF;?>" method="post">
<input type="submit" name="do"value="do"></input>
<input type="text" name="tweetid" placeholder="tweet id"></input>
<input type="text" name="message" placeholder="message"></input>
</form>
<?php
require_once('twitteroauth.php');
$connect=mysql_connect ("localhost","___","___");
mysql_select_db ("___");
if(isset($connect)){
$do=$_POST ['do'];
$message=$_POST ['message'];
$tweetid=$_POST ['tweetid'];
$consumerKey = '___';
$consumerSecret = '___';
$accessToken= '___';
$accessTokenSecret= '___';
if(isset($do)){
$tweet = new TwitterOAuth($consumerKey, $consumerSecret, $accessToken,$accessTokenSecret);
$tt=$tweet->post('statuses/update', array ('status'=>$message , 'in_reply_to_status_id' =>$tweetid));
}}
else {
print "error";
}
mysql_close ();
?>
Related
I have previously used reCaptcha v1 and all was good until the Google changes a few years ago. I've now been asked to update a site, and am having some problems even with a simple bit of test code. The example below is a single index.php page, which traps for 'POST' when a form is submitted.
The reCaptch tick box appears, and allows a tick, but when the form is submitted I only get the 'Check the reCAPTCHA box' response. It looks like '$captcha=$_POST['g-recaptcha-response'];' is 'blank'. I am using the correct codes, and am getting stats on the reCaptcha admin page, but it is also reporting:
We detected that your site isn't verifying reCAPTCHA solutions. This is required for the proper use of reCAPTCHA on your site. Please see our developer site for more information.
What am I missing to verify?
<head>
<title>Test Contact Form</title>
<script src="https://www.google.com/recaptcha/api.js" async defer></script>
</head>
<body>
<?php
if (isset($_POST['submit'])) {
echo "submit detected..<br>";
$full_name;$email;$subject;$message;$captcha;
if(isset($_POST['full_name'])){
$full_name=$_POST['full_name'];
}if(isset($_POST['email'])){
$email=$_POST['email'];
}if(isset($_POST['subject'])){
$subject=$_POST['subject'];
}if(isset($_POST['message'])){
$message=$_POST['message'];
}if(isset($_POST['g-recaptcha-response'])){
$captcha=$_POST['g-recaptcha-response'];
}
if(!$captcha){
echo 'Check the reCAPTCHA box.';
echo $full_name . "<br>";
echo $email . "<br>";
echo $subject . "<br>";
echo $captcha . "<br>";
exit;
}
$secretKey = "6LemhA8aFAKEDRSKVHsecretVzN7Uv1BVQnpS-LwbjOo";
$response=file_get_contents("https://www.google.com/recaptcha/api/siteverify?".$secretKey."&response=".$captcha."&remoteip=".$_SERVER['REMOTE_ADDR']);
if($response.success==false)
{
echo 'You are a robot!';
}else
{
echo "I'd be sending an email to " . $email . "<br>";
echo "because the secret key" . $secretKey . "<br>";
echo "and the response " . $captcha . "<br>";
echo "matched.";
}
} ELSE {
?>
<div class="contact-form">
<h3>Send me your message v1</h3>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
<div class="text-fields">
<span>Full Name *:</span>
<input name="full_name" type="text" class="text" value="Your Name">
</div>
<div class="text-fields">
<span>E-mail *:</span>
<input name="email" type="text" class="text" value="user#domain.com">
</div>
<div class="clearfix"> </div>
</div>
<div class="subject-field">
<span>Subject *:</span>
<input name="subject" type="text" class="text" value="Your Subject">
</div>
<div class="message-field">
<span>Message *:</span>
<textarea name="message"> </textarea>
</div>
<div class="g-recaptcha" data-sitekey="6LemhA8aFAKEJnoerEbOVLWEkeyYO3CcPo-HEIymP"></div>
<input type="submit" name="submit" value="Send" />
</form>
</div>
<?php } ?>
</body>
</html>
Captcha v2 Returns JSON Data (As seen on Official site) You should Decode json and then validate it.
$url = 'https://www.google.com/recaptcha/api/siteverify';
$data = array(
'secret' => 'YOUR_SECRET',
'response' => $_POST["g-recaptcha-response"]
);
$options = array(
'http' => array (
'method' => 'POST',
'content' => http_build_query($data)
)
);
$context = stream_context_create($options);
$verify = file_get_contents($url, false, $context);
$captcha_success=json_decode($verify);
if ($captcha_success->success==false) {
echo "<p>You are a bot! Go away!</p>";
} else if ($captcha_success->success==true) {
echo "<p>You are not not a bot!</p>";
}
there is also one problem in your code in " if($response.success==false)" you should write it as "if($response->success==false)"
I will comment after checking with your secrete id (Delete it afterword)
I suspect it's because you have an extra </div> after <div class="clearfix"> </div> – If you remove it, your code will probably work.
The extra closing div tag makes the browser believe that you're closing <div class="contact-form"> and since the <form> tag is inside of that, it tries fix your HTML and close that as well. However, that means that the remaining fields (subject, message) and reCAPTCHA are placed outside the <form>. reCAPTCHA only sets g-recaptcha-response if it's actually inside a <form>, no matter if the user successfully completes it or not.
An additional adjustment
You also need to decode the JSON returned from https://www.google.com/recaptcha/api/siteverify like so:
$response=json_decode(file_get_contents("https://www.google.com/recaptcha/api/siteverify?".$secretKey."&response=".$captcha."&remoteip=".$_SERVER['REMOTE_ADDR']), true);
if($response["success"]==false)
I'm working on password reset in core php.
I'm sending code variable from reset.php to resetPassword.php page like this:
reset.php
$code = uniqid(true);
$url = "http://".$_SERVER['HTTP_HOST'].dirname($_SERVER['PHP_SELF'])."/resetPassword.php?code=$code"
resetPassword.php
global $code;
if(!isset($_GET['code'])){
echo "There is No Code there !!!";
}
if(isset($_GET['code'])){
$code = $_GET['code'];
echo "The code is set at first , just at visit of the page ".$code;
}
// make sure there is row in the table that matches that passed code
$findEmail = mysqli_query($link,"SELECT `email` from resetpasswords WHERE `code` = '$code' ");
if(mysqli_num_rows($findEmail)==0){ // if no row found
echo "<h2 class = 'text text-center'>No Record regarding this email !</h2>";
exit();
}
// when form submits
if(isset($_POST['reset'])){
$password = md5($_POST['password']);
$confirm = md5($_POST['confirm']);
if($password!=$confirm){
echo "Password Don't matches !";
exit();
}
$row = mysqli_fetch_array($findEmail);
$email = $_POST['email'];
$updatePass = mysqli_query($link,"UPDATE `user` SET user_password = '$confirm' where email = '$email'");
if($updatePass){
$query = mysqli_query($link,"DELETE FROM resetpasswords where code = '$code' ");
exit('Password Updated, Please Login with the New Password');
}
else{
exit('Something went wrong');
}
}
On the same page resetPassword.php, I have the following code:
<form action="resetPassword.php" method="POST">
<div class="form-group">
<label for="password2">Password:</label>
<input type="password" class="form-control" name="password" id="password2" onkeyup="checkPass();">
</div>
<div class="form-group">
<label for="confirm2">Confirm Password:</label>
<input type="password" class="form-control" name="confirm" id="confirm2" onkeyup="checkPass();">
<span id="confirm-message2" class="confirm-message"></span>
</div>
<input type="hidden" value="<?php echo $code;?>">
<input type="submit" name="reset" value="Update Password" class="btn btn-success">
</form>
Problem:
The problem is when I submit the form , it goes all the way to the top of the page, and start executing the resetPassword.php page from the top, due to which for resetPassowrd.php page, it can't get that $code variable.
Because when I submit the form,the condition (!isset($_GET['code'])) at top of resetPassword.php becomes true and it gives me:
There is No Code there !!!
And I want to have that $code when I submit the form.
What I tried:
I tried to use hidden field with value of $code but that didn't worked.
please help me thanks
Consider the below points
1) Use prepared statements and parameterized queries.
2) Use password_hash() and password_verify() to secure your password.
3) In resetPassword.php page, if you submit the form with action="resetPassword.php" this will redirect to resetPassword.php. So replace your action with this
$full_url = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on' ? "https" : "http") . "://{$_SERVER['HTTP_HOST']}{$_SERVER['REQUEST_URI']}";
<form action="<?php echo $full_url ?>" method="POST">
You are missing name attribute in your hidden field and hence you are not able to find the value of $code.
Instead of
<input type="hidden" value="<?php echo $code;?>">
Try
<input type="hidden" value="<?php echo $code;?>" name="code" />
I have PHP and HTML files on my IIS site and am trying to get the output of a form shown on the same page. The issue I am running into is when I load the HTML page I am seeing the array information show as plain text on that page. I have form action = "" defined. Alternatively, when I have form action = "file.php" defined, I get the desired results, but on a new page. I took a look at the the link here but didn't seem to provide what I am looking for. I tried adding the tags on each line, which helped a bit but am still seeing the array as plain text. Here is what I have:
<form action="" method = "POST">
MAC Address of phone: <input type="text" name="phonemac"><br><br>
<input type="submit" value="Check Phone Status">
</form>
<?php
$host = "server.com";
$username = "*****";
$password = "*****";
$context =
stream_context_create(array('ssl'=>array('allow_self_signed'=>true)));
$client = new SoapClient("C:\inetpub\wwwroot\PhoneSetup\AXLAPI.wsdl",
array('trace'=>true,
'exceptions'=>true,
'location'=>"https://".$host.":8443/axl",
'login'=>$username,
'password'=>$password,
'stream_context'=>$context
));
$response = $client->getPhone(array("name"=>"$_POST[phonemac]"));
$array = json_decode(json_encode($response), true);
echo $array['return']['phone']['description'];echo '<br><br>';
echo $array['return']['phone']['name']; echo;
?>
</body>
</html>
This
$myArray = json_decode($data, true);
echo $myArray[0]['id']; // Fetches the first ID
echo $myArray[0]['c_name']; // Fetches the first c_name
// ...
I will write a example with your code
$array = json_decode(json_encode($response), true);
echo $array[0]['phone']
echo $array[0]['description'];
echo '</br></br>';
echo $array[0]['phone'];
echo $array[0]['name'];
your code would be like
<form action="" method = "POST">
MAC Address of phone: <input type="text" name="phonemac"><br><br>
<input type="submit" value="Check Phone Status">
</form>
<?php
$host = "server.com";
$username = "*****";
$password = "*****";
$context =
stream_context_create(array('ssl'=>array('allow_self_signed'=>true)));
$client = new SoapClient("C:\inetpub\wwwroot\PhoneSetup\AXLAPI.wsdl",
array('trace'=>true,
'exceptions'=>true,
'location'=>"https://".$host.":8443/axl",
'login'=>$username,
'password'=>$password,
'stream_context'=>$context
));
$response = $client->getPhone(array("name"=>"$_POST[phonemac]"));
$array = json_decode(json_encode($response), true);
echo $array[0]['phone']
echo $array[0]['description'];
echo '</br></br>';
echo $array[0]['phone'];
echo $array[0]['name'];
?>
<body>
</html>
I am struggling with the problem on my website. I should create an form to fill which will display new information/news. I have code like this:
<?php
include "0begin.php";
$title=$_POST["title"];
isset($title) or $title=$_GET["title"];
$msg=$_POST["msg"];
isset($msg) or $msg=$_GET["msg"];
?>
<h1>News</h1>
<form method="POST">
Title<br><input type=text input name="title" value=<?=$title?> ><br>
News<br>
<textarea input name="msg" cols=40 rows=5> </textarea><br>
<input type="submit">
<br><br>
</form>
<?php
$dateposted=date("YmdHis");
if (!empty($title) and !empty($msg)) {
$fp=fopen("/home/aqueen/public_html/news/".$dateposted."txt", "w");
fwrite($fp,$title,$msg);
fwirte($fp,$msg);
fclose($fp);
include "/home/aqueen/public_html/news/".$dateposted."txt"; }
?>
My questions:
1) How can I fix that code? It generates new file but without content inside.
2) It doesn't show the new file on the website /probably doesn't include it properly/
3) When it starts working- how I can let someone delete news from website without opening the code? /online/
Thank you in advance :)
Try this code:
<?php
//include "0begin.php";
$title = $_POST["title"];
$msg = $_POST["msg"];
?>
<h1>News</h1>
<form method="POST">
Title<br>
<input type="text" name="title"><br>
News<br>
<textarea name="msg" cols="40" rows="5"></textarea><br>
<input type="submit">
<br><br>
</form>
<?php
$dateposted=date("YmdHis");
if (!empty($title) and !empty($msg)) {
if (!file_exists('news/')) {
mkdir("news/", 0755);
}
if(file_exists($_SERVER['DOCUMENT_ROOT'] . "/news/")){
$pathGenerated = $_SERVER['DOCUMENT_ROOT'] . "/news/";
}
if(file_exists( "news/")){
$pathGenerated = "news/";
}
$pathGenerated = str_replace('//', '', $pathGenerated);
$fp=fopen($pathGenerated."".$dateposted.".txt", "w");
$textInsert = "Titolo: ".$title." \nMessaggio: ".$msg;
fwrite($fp,$textInsert);
fclose($fp);
include $pathGenerated."".$dateposted.".txt";
}
?>
Auto create folder /news/ if not exist.
I want to create php page for upload file into my dropbox.
I have got key and secret key from my dropbox account.
From here I got coding for dropbox but I did not get user id.
How can I get user id of dropbox.
https://www.dropbox.com/developers/core/start/php
list($accessToken, $dropboxUserId) = $webAuth->finish($authCode);
print "Access Token: " . $accessToken . "\n";
I assume you're using the standard PHP Dropbox SDK
$client = new Dropbox\Client($accessToken);
$info = $client->getAccountInfo();
echo $info["uid"];
<?php
error_reporting(E_ALL);
require_once("DropboxClient.php");
// you have to create an app at https://www.dropbox.com/developers/apps and enter details below:
$dropbox = new DropboxClient(array(
'app_key' => "",
'app_secret' => "",
'app_full_access' => true,
),'en');
handle_dropbox_auth($dropbox); // see below
// if there is no upload, show the form
if(empty($_FILES['the_upload'])) {
?>
<form enctype="multipart/form-data" method="POST" action="">
<p>
<label for="file">Upload File</label>
<input type="file" name="the_upload" />
</p>
<p><input type="submit" name="submit-btn" value="Upload!"></p>
</form>
<?php } else {
$upload_name = $_FILES["the_upload"]["name"];
echo "<pre>";
echo "\r\n\r\n<b>Uploading $upload_name:</b>\r\n";
$meta = $dropbox->UploadFile($_FILES["the_upload"]["tmp_name"], $upload_name);
print_r($meta);
echo "\r\n done!";
echo "</pre>";
}
to run before you have to authorized in dropbox apps