Fully edited topic
My file Follow_Button.php
:
<?php
require_once '.././app/autoload.php';
$TwitterUsers = new TwitterUsers;
require_once '.././app/TwitterOAuthHelper.php';
$helper = new TwitterOAuthHelper;
$row = $TwitterUsers->selectUserAll();
foreach ($row as $fetch) {
$helper->friend($fetch['id_user']);
}
My method:
public function friend($user_id) {
$access_token = $_SESSION['twitter_access_token'];
$connection = new TwitterOAuth(CONSUMER_KEY, CONSUMER_SECRET, $access_token['oauth_token'], $access_token['oauth_token_secret']);
$friend = $connection->post("friendships/create", [
"user_id" => $user_id,
'follow' => true
]);
if ($user_id === $this->signedIn()->id) {
return false;
}
return $friend;
}
I wanted to limit the PHP code, receive 1 follower every 10 seconds, and count with javascript
and when I finished executing the code the reactivate button again:
<a href="" onclick="return getPhpAjax();" class="text-none">
<button type="button" data-loading-text="Ganhando seguidores..." id="getFollow" class="btn btn-success btn-block">
<i class="fa fa-refresh"></i> Ganhar seguidores agora
</button>
</a>
<script type="text/javascript">
function getPhpAjax() {
$.ajax({
url:'./app/Follow_Button.php',
complete: function (response) {
$("#getFollow").click(function() {
var $btn = $(this);
$btn.button('loading');
});
},
error: function () {
alert('Erro');
}
});
return false;
}
</script>