Post by supak111 » Mon Dec 30, 2024 3:50 am

Trying to make OC3 send me an email every time an admin logs-in... and not really sure how to go about this.

I know how to send an email with PHP, but what file would I put the send email php code in?
What admin file is only accessed once per admin login?

I would probably add this to a free ocmod.
Last edited by supak111 on Thu Jan 02, 2025 3:25 pm, edited 1 time in total.

~ OC 3.0.3.2 and OCmods only ~


User avatar
Active Member

Posts

Joined
Fri Feb 13, 2015 12:09 pm

Post by by mona » Mon Dec 30, 2024 4:25 am

common/login
probably best using an event in this senario

DISCLAIMER:
You should not modify core files .. if you would like to donate a cup of coffee I will write it in a modification for you.


https://www.youtube.com/watch?v=zXIxDoCRc84


User avatar
Expert Member

Posts

Joined
Mon Jun 10, 2019 9:31 am

Post by Joe1234 » Tue Dec 31, 2024 2:41 am

Code: Select all

<?xml version="1.0" encoding="utf-8"?>
<modification>
  <name>MY CUSTOM: Admin Last Login Time</name>
  <version>1.0</version>
  <author>Just Me</author>
  <code>MY_CUSTOM_Admin_Last_Login_Time</code>

  <file path="admin/controller/marketplace/modification.php">
    <operation>
      <search><![CDATA[function refresh]]></search>
      <add position="after"><![CDATA[
		// -----------------------------modified - after begin MY CUSTOM: Admin Last Login Time
		//Add last login column to the database if it doesn't exist....for last admin login

		$this->db->query("ALTER TABLE `" . DB_PREFIX . "user` ADD COLUMN IF NOT EXISTS `last_login` VARCHAR(250) NULL AFTER `date_added`");

		//------------------------------modified - after end MY CUSTOM: Admin Last Login Time
			]]></add>
    </operation>
  </file>  
  
 
  
  
  <file path="admin/controller/user/user.php">
    <operation>
      <search><![CDATA[foreach ($results as $result) {]]></search>
      <add position="after"><![CDATA[
			if ($result['last_login'] == '0000-00-00 00:00:00') {
				$last_login_time = "";
			} else {
				$last_login_time = date($this->language->get('datetime_format'), strtotime($result['last_login']));
			}
			]]></add>
    </operation>
    <operation>
      <search><![CDATA['date_added' => date($this->language->get('date_format_short'), strtotime($result['date_added'])),]]></search>
      <add position="after"><![CDATA[
			'last_login' => $last_login_time,
			]]></add>
    </operation>
  </file>
  <file path="admin/view/template/user/user_list.twig">
    <operation>
      <search><![CDATA[<a href="{{ sort_date_added }}">{{ column_date_added }}</a>]]></search>
      <add position="after" offset="1"><![CDATA[
                  <td class="text-left">{% if sort == 'last_login' %}
                    <a href="{{ sort_last_login }}" class="{{ order|lower }}">Last Login</a>
                    {% else %}
                    <a href="{{ sort_last_login }}">Last Login</a>
                    {% endif %}</td>
			]]></add>
    </operation>
    <operation>
      <search><![CDATA[<td class="text-left">{{ user.date_added }}</td>]]></search>
      <add position="after"><![CDATA[
				  <td class="text-left">{{ user.last_login }}</td>
			]]></add>
    </operation>
  </file>
  <file path="admin/model/user/user.php">
    <operation>
      <search><![CDATA[public function addUser($data)]]></search>
      <add position="before"><![CDATA[
	public function custom_adminLogTime() {

		$this->db->query("UPDATE " . DB_PREFIX . "user SET last_login = '" . $this->db->escape(date('Y-m-d H:i:s')) . "' WHERE username = '" . $this->request->post['username'] . "'");

	}
			]]></add>
    </operation>
  </file>
  <file path="admin/controller/common/login.php">
    <operation>
      <search><![CDATA[$this->response->redirect($this->request->post['redirect']]]></search>
      <add position="before"><![CDATA[
				//Set the time that the admin logged in
				$login_time = date('d-m-Y H:i:s');

				$this->model_user_user->custom_adminLogTime($login_time);

				//Get the logged admin info
				$logged_admin = $this->model_user_user->getUserByUsername($this->request->post['username']);

				//Send an email notification upon login if it isn't my email address
				if ($logged_admin['email'] != "PUT-YOUR-EMAIL-HERE") {//-----------------------------------------------PUT-YOUR-EMAIL-HERE

					$email_template = $this->request->post['username'] . " logged in on " . $login_time . "<br><br>IP: " . $logged_admin['ip'];
					$subject = "Admin Login Notification";

					$mail_data['subject'] = $subject;
					$mail_data['text_welcome'] = html_entity_decode($email_template, ENT_QUOTES, 'UTF-8');

					$mail = new Mail($this->config->get('config_mail_engine'));
					$mail->parameter = $this->config->get('config_mail_parameter');
					$mail->smtp_hostname = $this->config->get('config_mail_smtp_hostname');
					$mail->smtp_username = $this->config->get('config_mail_smtp_username');
					$mail->smtp_password = html_entity_decode($this->config->get('config_mail_smtp_password'), ENT_QUOTES, 'UTF-8');
					$mail->smtp_port = $this->config->get('config_mail_smtp_port');
					$mail->smtp_timeout = $this->config->get('config_mail_smtp_timeout');

					$mail->setFrom($this->config->get('config_email'));
					$mail->setSender(html_entity_decode($this->config->get('config_name'), ENT_QUOTES, 'UTF-8'));
					$mail->setSubject(html_entity_decode($subject, ENT_QUOTES, 'UTF-8'));
					$mail->setHtml($this->load->view('mail/customer_deny', $mail_data));

					$mail->setTo($this->config->get('config_email'));
					$mail->send();

				}
			]]></add>
    </operation>
  </file>
</modification>


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.


Active Member

Posts

Joined
Sat Jan 01, 2022 5:47 am

Post by nonnedelectari » Tue Dec 31, 2024 8:36 am

supak111 wrote:
Mon Dec 30, 2024 3:50 am
Trying to make OC3 send me an email every time an admin logs-in... and not really sure how to go about this.

I know how to send an email with PHP, but what file would I put the send email php code in?
What admin file is only accessed once per admin login?

I would probably add this to a free ocmod.
just copy and adapt the logic of one of the admin mail events like admin/controller/mail/transaction.php and set the trigger on model admin/model/user/user/deleteLoginAttempts/before, that function is called when a user successfuly signs in.

Active Member

Posts

Joined
Thu Mar 04, 2021 6:34 pm

Post by supak111 » Tue Dec 31, 2024 10:18 am

Tried the OCmod above but didn't seem to work. No email received upon login in...
Also made my admin page white/bland first time I login in after installation... PS but admin page starter to work on the seconds login. Still the code above does not send emails...

I do see that it did add a column: last_login to oc_user table that just says null
Last edited by supak111 on Wed Jan 01, 2025 9:08 am, edited 1 time in total.

~ OC 3.0.3.2 and OCmods only ~


User avatar
Active Member

Posts

Joined
Fri Feb 13, 2015 12:09 pm

Post by nonnedelectari » Tue Dec 31, 2024 10:42 am

Joe1234 wrote:
Tue Dec 31, 2024 2:41 am

Code: Select all

<?xml version="1.0" encoding="utf-8"?>
<modification>
  <name>MY CUSTOM: Admin Last Login Time</name>
  <version>1.0</version>
  <author>Just Me</author>
  <code>MY_CUSTOM_Admin_Last_Login_Time</code>

  <file path="admin/controller/marketplace/modification.php">
    <operation>
      <search><![CDATA[function refresh]]></search>
      <add position="after"><![CDATA[
		// -----------------------------modified - after begin MY CUSTOM: Admin Last Login Time
		//Add last login column to the database if it doesn't exist....for last admin login

		$this->db->query("ALTER TABLE `" . DB_PREFIX . "user` ADD COLUMN IF NOT EXISTS `last_login` VARCHAR(250) NULL AFTER `date_added`");

		//------------------------------modified - after end MY CUSTOM: Admin Last Login Time
			]]></add>
    </operation>
  </file>  
  
 
  
  
  <file path="admin/controller/user/user.php">
    <operation>
      <search><![CDATA[foreach ($results as $result) {]]></search>
      <add position="after"><![CDATA[
			if ($result['last_login'] == '0000-00-00 00:00:00') {
				$last_login_time = "";
			} else {
				$last_login_time = date($this->language->get('datetime_format'), strtotime($result['last_login']));
			}
			]]></add>
    </operation>
    <operation>
      <search><![CDATA['date_added' => date($this->language->get('date_format_short'), strtotime($result['date_added'])),]]></search>
      <add position="after"><![CDATA[
			'last_login' => $last_login_time,
			]]></add>
    </operation>
  </file>
  <file path="admin/view/template/user/user_list.twig">
    <operation>
      <search><![CDATA[<a href="{{ sort_date_added }}">{{ column_date_added }}</a>]]></search>
      <add position="after" offset="1"><![CDATA[
                  <td class="text-left">{% if sort == 'last_login' %}
                    <a href="{{ sort_last_login }}" class="{{ order|lower }}">Last Login</a>
                    {% else %}
                    <a href="{{ sort_last_login }}">Last Login</a>
                    {% endif %}</td>
			]]></add>
    </operation>
    <operation>
      <search><![CDATA[<td class="text-left">{{ user.date_added }}</td>]]></search>
      <add position="after"><![CDATA[
				  <td class="text-left">{{ user.last_login }}</td>
			]]></add>
    </operation>
  </file>
  <file path="admin/model/user/user.php">
    <operation>
      <search><![CDATA[public function addUser($data)]]></search>
      <add position="before"><![CDATA[
	public function custom_adminLogTime() {

		$this->db->query("UPDATE " . DB_PREFIX . "user SET last_login = '" . $this->db->escape(date('Y-m-d H:i:s')) . "' WHERE username = '" . $this->request->post['username'] . "'");

	}
			]]></add>
    </operation>
  </file>
  <file path="admin/controller/common/login.php">
    <operation>
      <search><![CDATA[$this->response->redirect($this->request->post['redirect']]]></search>
      <add position="before"><![CDATA[
				//Set the time that the admin logged in
				$login_time = date('d-m-Y H:i:s');

				$this->model_user_user->custom_adminLogTime($login_time);

				//Get the logged admin info
				$logged_admin = $this->model_user_user->getUserByUsername($this->request->post['username']);

				//Send an email notification upon login if it isn't my email address
				if ($logged_admin['email'] != "PUT-YOUR-EMAIL-HERE") {//-----------------------------------------------PUT-YOUR-EMAIL-HERE

					$email_template = $this->request->post['username'] . " logged in on " . $login_time . "<br><br>IP: " . $logged_admin['ip'];
					$subject = "Admin Login Notification";

					$mail_data['subject'] = $subject;
					$mail_data['text_welcome'] = html_entity_decode($email_template, ENT_QUOTES, 'UTF-8');

					$mail = new Mail($this->config->get('config_mail_engine'));
					$mail->parameter = $this->config->get('config_mail_parameter');
					$mail->smtp_hostname = $this->config->get('config_mail_smtp_hostname');
					$mail->smtp_username = $this->config->get('config_mail_smtp_username');
					$mail->smtp_password = html_entity_decode($this->config->get('config_mail_smtp_password'), ENT_QUOTES, 'UTF-8');
					$mail->smtp_port = $this->config->get('config_mail_smtp_port');
					$mail->smtp_timeout = $this->config->get('config_mail_smtp_timeout');

					$mail->setFrom($this->config->get('config_email'));
					$mail->setSender(html_entity_decode($this->config->get('config_name'), ENT_QUOTES, 'UTF-8'));
					$mail->setSubject(html_entity_decode($subject, ENT_QUOTES, 'UTF-8'));
					$mail->setHtml($this->load->view('mail/customer_deny', $mail_data));

					$mail->setTo($this->config->get('config_email'));
					$mail->send();

				}
			]]></add>
    </operation>
  </file>
</modification>

This:

Code: Select all

				//Set the time that the admin logged in
				$login_time = date('d-m-Y H:i:s');

				$this->model_user_user->custom_adminLogTime($login_time);
with this:

Code: Select all

	public function custom_adminLogTime() {

		$this->db->query("UPDATE " . DB_PREFIX . "user SET last_login = '" . $this->db->escape(date('Y-m-d H:i:s')) . "' WHERE username = '" . $this->request->post['username'] . "'");
makes no sense.

Active Member

Posts

Joined
Thu Mar 04, 2021 6:34 pm

Post by supak111 » Tue Dec 31, 2024 10:45 am

just copy and adapt the logic of one of the admin mail events like admin/controller/mail/transaction.php and set the trigger on model admin/model/user/user/deleteLoginAttempts/before, that function is called when a user successfuly signs in.
Total noob, don't really understand how to do this with events. Ive looked into events but they just seem confusing to me

~ OC 3.0.3.2 and OCmods only ~


User avatar
Active Member

Posts

Joined
Fri Feb 13, 2015 12:09 pm

Post by nonnedelectari » Tue Dec 31, 2024 7:09 pm

supak111 wrote:
Tue Dec 31, 2024 10:45 am
just copy and adapt the logic of one of the admin mail events like admin/controller/mail/transaction.php and set the trigger on model admin/model/user/user/deleteLoginAttempts/before, that function is called when a user successfuly signs in.
Total noob, don't really understand how to do this with events. Ive looked into events but they just seem confusing to me
Well, then you would have to request some commercial support which should be relatively cheap as this is pretty straightforward.

Active Member

Posts

Joined
Thu Mar 04, 2021 6:34 pm

Post by paulfeakins » Tue Dec 31, 2024 7:33 pm

supak111 wrote:
Mon Dec 30, 2024 3:50 am
Trying to make OC3 send me an email every time an admin logs-in...
Probably just create an OCMOD to add to this file:
/admin/controller/common/login.php

Just below line 15 which is:

Code: Select all

$this->session->data['user_token'] = token(32);
Add some code to email you and job done.

UK OpenCart Hosting | OpenCart Audits | OpenCart Support - please email info@antropy.co.uk


User avatar
Legendary Member
Online

Posts

Joined
Mon Aug 22, 2011 11:01 pm
Location - London Gatwick, United Kingdom

Post by nonnedelectari » Tue Dec 31, 2024 8:11 pm

paulfeakins wrote:
Tue Dec 31, 2024 7:33 pm
supak111 wrote:
Mon Dec 30, 2024 3:50 am
Trying to make OC3 send me an email every time an admin logs-in...
Probably just create an OCMOD to add to this file:
/admin/controller/common/login.php

Just below line 15 which is:

Code: Select all

$this->session->data['user_token'] = token(32);
Add some code to email you and job done.
Add some code to email you and job done.
Well that should do it.

Active Member

Posts

Joined
Thu Mar 04, 2021 6:34 pm

Post by jrr » Wed Jan 01, 2025 3:00 am

Joe1234 wrote:
Tue Dec 31, 2024 2:41 am

Code: Select all

<?xml version="1.0" encoding="utf-8"?>
<modification>
  <name>MY CUSTOM: Admin Last Login Time</name>
  <version>1.0</version>
  <author>Just Me</author>
  <code>MY_CUSTOM_Admin_Last_Login_Time</code>

  <file path="admin/controller/marketplace/modification.php">
    <operation>
      <search><![CDATA[function refresh]]></search>
...

Unfortunately your code doesn't work for 3.0.4.0 - there is no ![CDATA[function refresh]]> in file path="admin/controller/marketplace/modification.php, and it isn't there in 3.0.3.6 either...

Unfortunate as this would have solved my similar question...

jrr
Active Member

Posts

Joined
Mon Nov 20, 2017 1:48 pm

Post by Joe1234 » Wed Jan 01, 2025 4:58 am

@supak111, So it works for you or no? You stated two different things. I see you are using 3.0.3.2, that may be the issue. I made this on 3.0.3.8 and using it on 3.0.3.9. Either way, it is a simple mod and should be easily adaptable to most versions.

@jrr, that function is only utilized to automate the addition of the table column upon install. You can simply remove that part of the mod and add the column manually in your database.

@nonnedelectari, true, I made an edit and forgot to clean up old code.

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.


Active Member

Posts

Joined
Sat Jan 01, 2022 5:47 am

Post by jrr » Wed Jan 01, 2025 1:26 pm

paulfeakins wrote:
Tue Dec 31, 2024 7:33 pm
supak111 wrote:
Mon Dec 30, 2024 3:50 am
Trying to make OC3 send me an email every time an admin logs-in...
Probably just create an OCMOD to add to this file:
/admin/controller/common/login.php

Just below line 15 which is:

Code: Select all

$this->session->data['user_token'] = token(32);
Add some code to email you and job done.
Ah, yes, thanks Paul - but those of us who can't code their way out of a wet paper bag are kinda stuck... (ducking) which is why folks like you, Johnathan, Mona, MaxD, and so many others are handy to have around!

I think I have a chance of solving this riddle if I look at how emails are sent for error messages, etc. once I figure out what user_token is - and how to set that to 'admin' or other login person I want to get an email notification about their logging in.

However tonight is New Years Eve, so HAPPY NEW YEAR folks! I hope 2025 is good for you and your families and friends!

jrr
Active Member

Posts

Joined
Mon Nov 20, 2017 1:48 pm

Post by supak111 » Wed Jan 01, 2025 10:32 pm

Joe1234 wrote:
Wed Jan 01, 2025 4:58 am
@supak111, So it works for you or no? You stated two different things. I see you are using 3.0.3.2, that may be the issue. I made this on 3.0.3.8 and using it on 3.0.3.9. Either way, it is a simple mod and should be easily adaptable to most versions.
No it does not send email upon admin login and I do not see any errors in the oc_error.log

What I meant in previous post is that my admin page started working again. At first right after the install of the odmod, my admin page was blank (white... nothing on it), but on second admin login the admin page was back to normal.

~ OC 3.0.3.2 and OCmods only ~


User avatar
Active Member

Posts

Joined
Fri Feb 13, 2015 12:09 pm

Post by supak111 » Thu Jan 02, 2025 12:19 am

Thanks to everyone contributing this is what I came up with..
Just:
-replace the email address with your email address
-zip it
-rename it: admin_login_email.ocmod.zip
-and install it

Simple, but does the job ツ

Code: Select all

<?xml version="1.0" encoding="utf-8"?>
<modification>
    <name>Send email on Admin Login</name>
    <code>Send email On Admin Login</code>
    <version>1.0</version>
    <author>opencart.com username: MyOpe</author>
    <link>https://forum.opencart.com/viewtopic.php?p=876242</link>
    <file path="admin/controller/common/login.php">
        <operation error="skip">
            <search>
                <![CDATA[$this->session->data['user_token'] = token(32);]]>
            </search>
            <add position="after">
                <![CDATA[

$ip_address = '';
if (!empty($_SERVER['HTTP_CLIENT_IP'])) {
    $ip_address = $_SERVER['HTTP_CLIENT_IP'];
} elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) {
    $ip_address = $_SERVER['HTTP_X_FORWARDED_FOR'];
} else {
    $ip_address = $_SERVER['REMOTE_ADDR'];
}

if (!empty($_SERVER['HTTP_REFERER'])) {                  
    $refer = $_SERVER['HTTP_REFERER'];
} else {
    $refer = 'referrer not found';
}

$to = "YOUR@EMAIL.HERE"; //the address the email is being sent to
$subject = "Admin LOGIN"; //the subject of the message
$msg = "Admin LOGIN
<br><br>
Admin:  {$this->request->post['username']}<br>
Referer:  {$refer}<br>
From IP:  <a href='https://whatismyipaddress.com/ip/{$ip_address}'>https://whatismyipaddress.com/ip/{$ip_address}</a><br>"; //the message of the email

// Set content-type header for sending HTML email 
$headers = "MIME-Version: 1.0" . "\r\n"; 
$headers .= "Content-type:text/html;charset=UTF-8" . "\r\n"; 

// Additional headers 
$headers .= 'From: YOURNAME <noreply@YOUR.EMAIL>' . "\r\n";

mail($to, $subject, $msg, $headers); //send the email

]]>
            </add>
        </operation>
    </file>
</modification>

~ OC 3.0.3.2 and OCmods only ~


User avatar
Active Member

Posts

Joined
Fri Feb 13, 2015 12:09 pm

Post by jrr » Thu Jan 02, 2025 10:36 am

Interesting, but I'm not getting the username defined on my 3.0.4.0 system.
Is there another way to retrieve the login name than:

Code: Select all

Admin:  {$this->request->post['username']}
I'm simply stuffing this after line 23 in ../admin/controller/common/login.php

Code: Select all

$ip_address = '';
if (!empty($_SERVER['HTTP_CLIENT_IP'])) {
    $ip_address = $_SERVER['HTTP_CLIENT_IP'];
} elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) {
    $ip_address = $_SERVER['HTTP_X_FORWARDED_FOR'];
} else {
    $ip_address = $_SERVER['REMOTE_ADDR'];
}

if (!empty($_SERVER['HTTP_REFERER'])) {                  
    $refer = $_SERVER['HTTP_REFERER'];
} else {
    $refer = 'referrer not found';
}

$to = "jrr@flippers.com"; //the address the email is being sent to
$subject = "Admin LOGIN"; //the subject of the message
$msg = "Admin LOGIN
<br><br>
Admin:  {$this->request->post['username']}<br>
Referer:  {$refer}<br>
From IP:  <a href='https://(stuff)/admin/ip/{$ip_address}'>https://(stuff)/admin/ip/{$ip_address}</a><br>"; //the message of the email

// Set content-type header for sending HTML email 
$headers = "MIME-Version: 1.0" . "\r\n"; 
$headers .= "Content-type:text/html;charset=UTF-8" . "\r\n"; 

// Additional headers 
$headers .= 'From: JRR <noreply@flippers.com>' . "\r\n";

mail($to, $subject, $msg, $headers); //send the email
And it is working but the response for username is "" (blank)

jrr
Active Member

Posts

Joined
Mon Nov 20, 2017 1:48 pm

Post by supak111 » Thu Jan 02, 2025 12:20 pm

Not sure why it's not working on your 3.0.4.0. Login.php file is pretty much the same as my 3.0.3.2.

Maybe someone else can tell us how to pull username another way.

PS put your code after line 15

Code: Select all

$this->session->data['user_token'] = token(32);

~ OC 3.0.3.2 and OCmods only ~


User avatar
Active Member

Posts

Joined
Fri Feb 13, 2015 12:09 pm

Post by jrr » Thu Jan 02, 2025 2:28 pm

supak111 wrote:
Thu Jan 02, 2025 12:20 pm
Not sure why it's not working on your 3.0.4.0. Login.php file is pretty much the same as my 3.0.3.2.

Maybe someone else can tell us how to pull username another way.

PS put your code after line 15

Code: Select all

$this->session->data['user_token'] = token(32);
Right you are!

Putting the script after line 15 has it working as it should - emails now show login name and IP address.

Must be like real estate - location, location, location!

However in your original xml creation you have this:

Code: Select all

            <search>
                <![CDATA[$this->session->data['user_token'] = token(32);]]>
            </search>
            <add position="after">
                <![CDATA[
Which doesn't work - and I don't know how to fix it so the xml file will load using installer as an ocmod.

I think the <![CDATA[ bit is incomplete or incorrect - I've tried variations <![CDATA[$this->session->data['user_token'] = token(32);]]> or <$this->session->data['user_token'] = token(32);> to no avail...but that is just me flailing around.

Thanks!

John :-#)#

jrr
Active Member

Posts

Joined
Mon Nov 20, 2017 1:48 pm

Post by supak111 » Thu Jan 02, 2025 3:23 pm

You use the code below if you are making an ocmod for installation through admin->extensions->installer page...
If you are hardcoding the code into the login.php file directly (hardcoding is never really recommended), you don't need the code below, and you don't need a bunch of other code from my original file

Code: Select all

 <search>
                <![CDATA[$this->session->data['user_token'] = token(32);]]>
            </search>
            <add position="after">
                <![CDATA[

~ OC 3.0.3.2 and OCmods only ~


User avatar
Active Member

Posts

Joined
Fri Feb 13, 2015 12:09 pm

Post by nonnedelectari » Thu Jan 02, 2025 5:03 pm

Just for the sake of being complete:

this:

Code: Select all

$ip_address = $_SERVER['HTTP_X_FORWARDED_FOR'];
is not correct as that variable can contain multiple comma-separated ip addresses from intermediate proxies.
That should be taken into account.

Code: Select all

$ip_address = '';
if (!empty($_SERVER['HTTP_CLIENT_IP'])) {
	$ip_address = $_SERVER['HTTP_CLIENT_IP'];
} elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) {
	$ip_list = explode(',',$_SERVER['HTTP_X_FORWARDED_FOR']);
	$ip = trim($ip_list[0]);
	if (filter_var ($ip, FILTER_VALIDATE_IP)) $ip_address = $ip;
}
if ($ip_address === '') $ip_address = $_SERVER['REMOTE_ADDR'];

Active Member

Posts

Joined
Thu Mar 04, 2021 6:34 pm
Who is online

Users browsing this forum: Bing [Bot], Majestic-12 [Bot] and 57 guests