Dedication and passion goes to those who are able to push and merge a project.
Regards,
Straightlight
Programmer / Opencart Tester
Doesn't matter, webservers are stateless so everything is run at least once.
You should record in the session, as a session variable, whether the code has been run already or not.
Then you can make sure code is run once per session.
You should tell us what you're trying to do, because there might be a better way.
UK OpenCart Hosting | OpenCart Audits | OpenCart Support - please email info@antropy.co.uk
Right now I am using this code in my index.php to send myself android notification about what sites are referring visitors to my website.
Issue I have is that I usually get 2 even 3 notification per visitor sometimes.
Is there any way to edit this code so that it only send 1 notification per visitor/referrer?
Code: Select all
if (!empty($_SERVER['HTTP_REFERER'])) {
$refer = $_SERVER['HTTP_REFERER'];
}
$word1 = "google";
$word2 = "bing"
if (!empty($refer) and !strpos($refer, $word1) and !strpos($refer, $word2)) {
// Target URL
$url = "https://xdroid.net/api/message?k=k-8278286d&t=FROM&c={$refer}&u={$refer}";
// Fetching headers, aka visit/ping $url above
$headers = get_headers($url);
}
~ OC 3.0.3.2 and OCmods only ~
Code: Select all
if (!empty($_SERVER['HTTP_REFERER'])) {
$refer = $_SERVER['HTTP_REFERER'];
}
if (!isset($this->session->data['referer_check'])) {
$word1 = "google";
$word2 = "bing"
if (!empty($refer) and !strpos($refer, $word1) and !strpos($refer, $word2)) {
// Target URL
$url = "https://xdroid.net/api/message?k=k-8278286d&t=FROM&c={$refer}&u={$refer}";
// Fetching headers, aka visit/ping $url above
$headers = get_headers($url);
}
$this->session->data['referer_check'] = true;
}
so on rare occasions you may still see multiple messages, nothing you can do about that unless you identify bots and exclude them from this.
That being said, what control file should I put this PHP in if not /system/startup.php
~ OC 3.0.3.2 and OCmods only ~
v3.0.4.0 php 8.1
I'm here for a reason, if your response is contact a/the developer, just don't reply.
catalog/controller/common/footer.php file already use refer. You could simply expand it to your needs by creating an extension.supak111 wrote: ↑Fri Mar 29, 2024 4:00 amOk this is what I am doing:
Right now I am using this code in my index.php to send myself android notification about what sites are referring visitors to my website.
Issue I have is that I usually get 2 even 3 notification per visitor sometimes.
Is there any way to edit this code so that it only send 1 notification per visitor/referrer?
Code: Select all
if (!empty($_SERVER['HTTP_REFERER'])) { $refer = $_SERVER['HTTP_REFERER']; } $word1 = "google"; $word2 = "bing" if (!empty($refer) and !strpos($refer, $word1) and !strpos($refer, $word2)) { // Target URL $url = "https://xdroid.net/api/message?k=k-8278286d&t=FROM&c={$refer}&u={$refer}"; // Fetching headers, aka visit/ping $url above $headers = get_headers($url); }
Dedication and passion goes to those who are able to push and merge a project.
Regards,
Straightlight
Programmer / Opencart Tester
Joe1234 wrote: ↑Sat Mar 30, 2024 10:57 pmI'm currently doing something where I only want something to register once per visitor, so what I did was check the current ip against the users online in catalog/controller/common/footer.php. You may have to do something extra with it though depending on your needs and time span per visit which would be either extending the time the online user is tracked, or copying the online users to a different table and checking that and setting that table to reset at an extended amount of time like 24 hours or something. I think this method is the easiest to accomplish what you need. It runs with every page load I believe, but it's what you can tap into to get what you want. There may be a more efficient way that only loads once, but I don't know that, if you find out, let me know. Also note, If you go the route of adding a different table you could also add a counter column to see which IP is constantly hitting within the allotted reset time...hence probably a bot...and block them all together.
This would be a great little extension, care to share your code?
~ OC 3.0.3.2 and OCmods only ~
Replace catalog/model/tool/online.php contents with this:
Code: Select all
<?php
class ModelToolOnline extends Model {
public function addOnline($ip, $customer_id, $url, $referer) {
$this->db->query("DELETE FROM `" . DB_PREFIX . "customer_online` WHERE date_added < '" . date('Y-m-d H:i:s', strtotime('-1 hour')) . "'");
$this->db->query("REPLACE INTO `" . DB_PREFIX . "customer_online` SET `ip` = '" . $this->db->escape($ip) . "', `customer_id` = '" . (int)$customer_id . "', `url` = '" . $this->db->escape($url) . "', `referer` = '" . $this->db->escape($referer) . "', `date_added` = '" . $this->db->escape(date('Y-m-d H:i:s')) . "'");
//log the same ip address in a different table to hold it longer than one hour...this way if you use the online user report it isn't overburdened with 24 hours worth of visitors for you to comb through
//change the 25 to however long/short you want
$this->db->query("DELETE FROM `custom_country_ip` WHERE date_added < '" . date('Y-m-d H:i:s', strtotime('-25 hour')) . "'");
$this->db->query("REPLACE INTO `custom_country_ip` SET `ip_address` = '" . $this->db->escape($ip) . "', `date_added` = '" . $this->db->escape(date('Y-m-d H:i:s')) . "', `accessed` = '" . Null . "'");
}
public function Custom_CheckIP($ip) {
//check if ip was registered in the last 25 hours
$query = $this->db->query("SELECT ip_address FROM `custom_country_ip` WHERE ip_address = '" . $ip . "'");
if (isset($query->rows[0]['ip_address'])) {
return $query->rows[0]['ip_address'];
}
}
}
In catalog/controller/common/footer.php add the following before: $this->model_tool_online->addOnline($ip, $this->customer->getId(), $url, $referer);
The cookie is set so "real" visitors arent unnecessarily querying the database with every page load, and then for the bots it will check against the database for ips. Change the cookie time as needed.
Code: Select all
if(!isset($_COOKIE["CountryIP"])) {//if the cookie is not set
if (!empty($_SERVER['HTTP_CLIENT_IP'])) {
$return = $_SERVER['HTTP_CLIENT_IP'];
} elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) {
$return = $_SERVER['HTTP_X_FORWARDED_FOR'];
} else {
$return = $_SERVER['REMOTE_ADDR'];
}
$ip_recently_online = $this->model_tool_online->Custom_CheckIP($return);
$new_visit = True;
if (isset($ip_recently_online) && $ip_recently_online == $return) {
$new_visit = False;
}
if ($new_visit = True) {
//********************************
//Do whatever you need here.************************************************************************************************
//********************************
setcookie("CountryIP", "Cookie IP", 0 , "/", "example.com", TRUE);
}
}
Code: Select all
//Create country ip table if it doesn't exist
$this->db->query("CREATE TABLE IF NOT EXISTS `custom_country_ip` (`ip_address` VARCHAR(30), `date_added` VARCHAR(20), `accessed` INT(5), PRIMARY KEY (ip_address)) COMMENT='24hr IP list to prevent multiple checks checks.';");
v3.0.4.0 php 8.1
I'm here for a reason, if your response is contact a/the developer, just don't reply.
I will look into this, might be a better ideastraightlight wrote: ↑Sat Mar 30, 2024 11:42 pmcatalog/controller/common/footer.php file already use refer. You could simply expand it to your needs by creating an extension.
~ OC 3.0.3.2 and OCmods only ~
I literally gave you exactly that...which I already stated in my first post and you then requested lol. Either way, I came back to tell you disregard the whole increment count thing I was thinking about. I probably wont work, at least the way I have the query setup using "replace" in the query. It should work if you query in a different way though.
Your welcome lol.
v3.0.4.0 php 8.1
I'm here for a reason, if your response is contact a/the developer, just don't reply.
Sounds like you could use software like Matomo for this.
UK OpenCart Hosting | OpenCart Audits | OpenCart Support - please email info@antropy.co.uk
paulfeakins wrote: ↑Tue Apr 02, 2024 7:40 pmSounds like you could use software like Matomo for this.
Never heard of them before. Will look into it for sure
.
~ OC 3.0.3.2 and OCmods only ~
Users browsing this forum: No registered users and 18 guests