How to display number of visitors? - count

I have an application uploaded on a web server.
I want to display the total number of visitors who have been to my application link.
Any idea?

Check this code it uses cookie check and you can update parameters like for how long a visitor is considered unique :
http://discussion.accuwebhost.com/how-tos/479-how-write-simple-php-hit-counter-displays-number-visits-your-website.html

If you want to display visitors from data table from your server. Use
php
$con=mysql_connect("localhost", "username", "password"); if (!$con)
{ die('Could not connect: ' . mysql_error()); } echo "Connected to
MySQL"; mysql_select_db("adil") or die(mysql_error()); echo
"Connected to Database";
$result = mysql_query("SELECT * FROM test"); echo ""; while($row = mysql_fetch_array($result)) { echo
"" . $row['visitor'] . "" . "" . $row['col2'] .
""; // echo ""; } echo "";
mysql_close($con);

Related

How to prevent my bot from entering into a loop?

I created a functionality in my bot that allows to ping other computers, when the user pings more than 60 times the bot takes a long time to do it, and I think it does not respond to Telegram with an http 200 code, so Telegram sends it again the ping request and the loop never stops. I used this library to build my bot: https://github.com/Eleirbag89/TelegramBotPHP
The code to do it is very simple:
<?php
$telegram = new Telegram('token');
date_default_timezone_set('America/Bogota');
$chat_id = $telegram->ChatID();
$text = $telegram->Text();
$palabras = explode(" ", $text);
foreach ($palabras as $key) {
if (filter_var($key, FILTER_VALIDATE_IP)) {
$ip = $key;
$key = "";
}
if (is_numeric($key)){
$cant_paq=$key;
};
};
if (stristr($text, 'ping') && !empty($ip)) {
$numero = !empty($cant_paq) ? $cant_paq : 4;
exec("ping -c $numero $ip", $output, $status);
foreach ($output as $key) {
$resultPing .= $key . "\r\n";
}
$content = array('chat_id' => $chat_id, 'text' => $resultPing);
$telegram->sendMessage($content);
}
In the end, I managed to solve it myself, I searched all over the internet and found a clue from someone who had the same problem, adding http_response_code (200) was not enough. Now every time the something goes inside (stristr ($ text, 'ping') &&! empty ($ ip)) I clear the pending messages via drop_pending_updates parameter in the setWebhook method https://core.telegram.org/bots/api#setwebhook

Wordpress smtp mail from address is not working

i am using wp_mail_smtp for sending mail in WordPress and its working fine expect one thing i have define the from email : abc#mysite.com and from name: my site and username password for smtp authentication is : someemail#example.com and password of my mail id.
now problem is that when i sending the mail than i receive mail header like
mysite< someemail#example.com > and it should be mysite< abc#mysite.com > i have also set the filter for from name and from mail like below code
add_filter('wp_mail_from', 'new_mail_from');
add_filter('wp_mail_from_name', 'new_mail_from_name');
function new_mail_from($old) {
return 'abc#mysite.com';
}
function new_mail_from_name($old) {
return 'mysite.com';
}
and my mail code is
$headers = 'From: abc#mysite.com ' . "\r\n";
$to = "admin#test.com"
$send_subject = "Mail Subject"
$message .= "Some message";
wp_mail( $to, $send_subject, $message,$headers );
please tell me what i am doing wrong so that i can receive mail header correctly
Thanks

PHPMailer & WordPress "Post by Email" - not creating post

I'm creating a script for a client using their PHP 5.4.16 (updating is not in the scope of this project), and therefore PHPMailer 5.2.25. My script (below) works if I change the SetAddress to my personal Gmail account (I get the email with subject, body, and attachment (the latter being the reason for using PHPMailer)), but if I change the SetAddress to my WordPress "Post by Email" address, nothing seems to be delivered.
Questions:
Is there anything wrong with my script? Missing headers? Badly formatted email?
If my script is apparently OK, what other avenues of investigation might there be?
Thanks
<?php
echo "<p>" . date("h:i:sa");
?>
<?php
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
?>
<?php require_once($_SERVER['DOCUMENT_ROOT'] . '/../www/phpmailer/class.phpmailer.php'); ?>
<?php require_once($_SERVER['DOCUMENT_ROOT'] . '/../www/phpmailer/class.smtp.php'); ?>
<?php
$mail = new PHPMailer();
$mail->IsSMTP(); // enable SMTP
//$mail->SMTPDebug = 1; // debugging: 1 = errors and messages, 2 = messages only
$mail->SMTPAuth = true; // authentication enabled
$mail->SMTPSecure = 'tls'; // secure transfer enabled REQUIRED for Gmail
$mail->Host = "smtp.gmail.com";
$mail->Port = 587; // or 587
$mail->IsHTML(true);
$mail->Username = "my#gmail.com";
$mail->Password = "mypassword";
$mail->From = "my#gmail.com";
$mail->FromName = "Me";
//$mail->AddAddress("caju317davu#post.wordpress.com");
$mail->AddAddress("my#gmail.com");
$mail->AddReplyTo("my#gmail.com","developer");
$mail->AddAttachment($_SERVER['DOCUMENT_ROOT'] . '/../www/_assets/articles/223/610/7f10120230e612e03eea9aa54a48a68f.jpg', 'attachment.jpg');
$mail->Subject = "My test email";
$mail->Body = "Hi! This is my first successful post created through email.";
if(!$mail->Send()) {
echo 'Message was not sent.';
echo 'Mailer error: ' . $mail->ErrorInfo;
} else {
echo 'Message has been sent.';
}
?>
Now I am not sure if this will help at all but below is the code that I have for a working version of PHPMailer v5.2.9 that is running on a site using PHP version 5.4.16 so may help. The obvious differences I can see is the recipient's section don't have "set" or "Add" and also I can't seem to find the initiator ($mail->send();). Let me know if this helps and for any areas needing extra clarification.
$mail = new PHPMailer(true); // Passing `true` enables exceptions
try {
//Server settings
$mail->SMTPDebug = 0; // Enable verbose debug output
$mail->isSMTP(); // Set mailer to use SMTP
$mail->Host = 'smtp.host.co.uk'; // Specify main and backup SMTP servers
$mail->SMTPAuth = true; // Enable SMTP authentication
$mail->Username = 'mail#example.co.uk'; // SMTP username
$mail->Password = 'password'; // SMTP password
$mail->SMTPSecure = 'tls'; // Enable TLS encryption, `ssl` also accepted
$mail->Port = 587; // TCP port to connect to
//Recipients
$mail->setFrom('email#example.co.uk', 'Company Name');
$mail->addAddress($email); //Gets the email the enquiry form field contains
$mail->addReplyTo('email#example.co.uk', 'Company Name');
$body='<div style="background:#F6F6F6; font-family:Verdana, Arial, Helvetica,
sans-serif; font-size:12px; margin:0; padding:0;">
<p>Thank you for your enquiry, a member of the team will be in touch shortly to discuss your requirements. In the mean time, please double check the below details entered on our website. If any of these are incorrect or you wish to add to it, please contact us via email or over the phone.</p></div>';
//Content
$mail->isHTML(true);
$mail->Subject = $subject ;
$mail->Body = $body;
$mail->AltBody = strip_tags($body);
$mail->send();
echo $thankyou_text;
} catch (Exception $e) {
echo $failed_text;
echo 'Mailer Error: ' . $mail->ErrorInfo;
}
From a 'Happiness Engineer' at WordPress:
Hi there!
At WordPress.com we don't allow posts to be sent automatically from
scripts such as PHPMailer.
I guess that answers that! Now to forget PHPMailer, and try and get back to default PHP mail() :(
Sorry to have bothered you all

Fortumo reciept verificaton

Can anyone help to configure this its doing my nut in now.
This will be useful: https://developers.fortumo.com/cross-platform-mobile-payments/
I have the secret key and the widget set up i just need it add the stuff to my database e.g coins + 1 in a query but the code inserted into the successful payment bit wont run. So time to start again fresh.
Any help will be appreciated.
<?php
// check that the request comes from Fortumo server
if(!in_array($_SERVER['REMOTE_ADDR'],
array('1.2.3.4', '2.3.4.5'))) {
header("HTTP/1.0 403 Forbidden");
die("Error: Unknown IP");
}
// check the signature
$secret = ''; // insert your secret between ''
if(empty($secret) || !check_signature($_GET, $secret)) {
header("HTTP/1.0 404 Not Found");
die("Error: Invalid signature");
}
$sender = $_GET['sender'];//phone num.
$amount = $_GET['amount'];//credit
$cuid = $_GET['cuid'];//resource i.e. user
$payment_id = $_GET['payment_id'];//unique id
$test = $_GET['test']; // this parameter is present only when the payment is a test payment, it's value is either 'ok' or 'fail'
//hint: find or create payment by payment_id
//additional parameters: operator, price, user_share, country
if(preg_match("/completed/i", $_GET['status'])) {
// mark payment as successful
}
// print out the reply
if($test){
echo('TEST OK');
}
else {
echo('OK');
}
function check_signature($params_array, $secret) {
ksort($params_array);
$str = '';
foreach ($params_array as $k=>$v) {
if($k != 'sig') {
$str .= "$k=$v";
}
}
$str .= $secret;
$signature = md5($str);
return ($params_array['sig'] == $signature);
}
?>
The first lines of the code example validates that the request comes from Fortumo IP address, if not then it the script dies.
// check that the request comes from Fortumo server
if(!in_array($_SERVER['REMOTE_ADDR'],
array('1.2.3.4', '2.3.4.5'))) {
header("HTTP/1.0 403 Forbidden");
die("Error: Unknown IP");
}
Write to support#fortumo.com to get the latest IP addresses to validate (and replace the example values 1.2.3.4 with them).
Meanwhile you can comment out the ip check and continue building your script.

Client for Google API PHP Client and nested requires?

I'm trying to implement Google analytics api in a wordpress dashboard plugin.
Following the simplest implementation for using the Google API for PHP for the first time, its not working right away at practically the first step.
According to the tutorial README.md, my app, placed ajacent to the library folder, should load the library like so:
require_once 'Google/Client.php';
require_once 'Google/Service/Books.php';
$client = new Google_Client();
Now, the structure of the library within my app (plugin) is:
myapp.php
/Google
/Google/Client.php
/Google/otherfolders/otherfiles.php
and my app attempts to load the library per the require_once above. But of course the Client.php has many require_once calls itself such as:
require_once 'Google/Auth/AssertionCredentials.php';
Which seem to ignore its position -- already within /Google.
So I'm getting errors:
PHP Warning: require_once(Google/Auth/AssertionCredentials.php) [<a href='function.require-once'>function.require-once</a>]: failed to open stream: No such file or directory in <wpengine host path removed>/wp-content/plugins/mmstats/Google/Client.php on line 18
and
PHP Fatal error: require_once() [<a href='function.require'>function.require</a>]: Failed opening required 'Google/Auth/AssertionCredentials.php' (include_path='.:/usr/share/php:/usr/share/pear') in <wpengine host path removed>/wp-content/plugins/mmstats/Google/Client.php on line 18
This PHP is listed as "Beta" but surely I'm doing something wrong rather than this being a problem with Client.php
Any help appreciated!
The Google Director needs to be in the same directory as your file. If its not your going to have to edit all the required_once's yourself. Here is some working code for use with the Google Analytics API.
<?php
require_once 'Google/Client.php';
require_once 'Google/Service/Analytics.php';
session_start();
$client = new Google_Client();
$client->setApplicationName("Client_Library_Examples");
$client->setDeveloperKey("{devkey}");
$client->setClientId('{clientid}.apps.googleusercontent.com');
$client->setClientSecret('{clientsecret}');
$client->setRedirectUri('http://www.daimto.com/Tutorials/PHP/Oauth2.php');
$client->setScopes(array('https://www.googleapis.com/auth/analytics.readonly'));
//For loging out.
if ($_GET['logout'] == "1") {
unset($_SESSION['token']);
}
// Step 2: The user accepted your access now you need to exchange it.
if (isset($_GET['code'])) {
$client->authenticate($_GET['code']);
$_SESSION['token'] = $client->getAccessToken();
$redirect = 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF'];
header('Location: ' . filter_var($redirect, FILTER_SANITIZE_URL));
}
// Step 1: The user has not authenticated we give them a link to login
if (!$client->getAccessToken() && !isset($_SESSION['token'])) {
$authUrl = $client->createAuthUrl();
print "<a class='login' href='$authUrl'>Connect Me!</a>";
}
// Step 3: We have access we can now create our service
if (isset($_SESSION['token'])) {
print "<a class='logout' href='".$_SERVER['PHP_SELF']."?logout=1'>LogOut</a><br>";
$client->setAccessToken($_SESSION['token']);
$service = new Google_Service_Analytics($client);
// request user accounts
$accounts = $service->management_accountSummaries->listManagementAccountSummaries();
foreach ($accounts->getItems() as $item) {
echo "Account: ",$item['name'], " " , $item['id'], "<br /> \n";
foreach($item->getWebProperties() as $wp) {
echo ' WebProperty: ' ,$wp['name'], " " , $wp['id'], "<br /> \n";
$views = $wp->getProfiles();
if (!is_null($views)) {
foreach($wp->getProfiles() as $view) {
// echo ' View: ' ,$view['name'], " " , $view['id'], "<br /> \n";
}
}
}
} // closes account summaries
}
print "<br><br><br>";
print "Access from google: " . $_SESSION['token'];
?>
You can find a tutorial for this code at Google Oauth2 PHP, there is a little test app at the bottom where you can see it working.

Resources