Jump to content

Recommended Posts

Hello,

 

How can I make a webpage send me an email with the ip address of the person who visited the page?

 

I can easily make the page send a blank email but I would really like to include the ip address of the visitor too because I have a suspision someone is somehow getting into my admin pages.

 

<?php mail("email@address.com", "Someone visited this page!", "body of message"); ?>

 

 

Thanks

Tom :)

 

Link to comment
https://forums.phpfreaks.com/topic/132065-solved-sending-an-email-with-ip-info/
Share on other sites

Thanks for the info but that kicked up the following error...

 

Warning: session_start() [function.session-start]: Cannot send session cookie - headers already sent by (output started at /public_html/admin/index.php:1) in /public_html/admin/includes/functions/sessions.php on line 103

 

Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at /public_html/admin/index.php:1) in /public_html/admin/includes/functions/sessions.php on line 103

 

 

I am using Fedora core 8, Apache/2.2.9 (Unix) mod_ssl/2.2.9 OpenSSL/0.9.8b mod_bwlimited/1.4 and PHP/5.2.6

 

Tom

 

 

 

 

Hi Tom,

 

Where ever you are including that session page it is not at the top and you have some type of character outputted before the include. The session_start() has to be done before any data is output to the browser.

 

The code is correct, however your other code is messed up.

This is from the admin in creloaded so it shouldnt be an error in the code. it only kicks up the error when I add the ip email script to the top of the admin page

 

here is the the first 100 lines so you can see what I am doing.

 

maybe the ip email script needs to be placed further down?

 

<?php mail("email@address.com", "Someone visited this page!", "Users ip address is likely {$_SERVER['REMOTE_ADDR']}"); ?> 

 

<?php

require('includes/application_top.php');

 

//get path of directory containing this script

 

//Code to Check Backup Count

//$handle = opendir(DIR_FS_BACKUP."/ravi");

if ($handle = @opendir(DIR_FS_BACKUP))

{

  $count = 0;

  //loop through the directory

  $year="1900"; //please dont change this value

  $dayofyear="0"; //please dont change this value

  $lastbackupdate="";

  while (($filename = readdir($handle)) !== false)

  {

    //evaluate each entry, removing the . & .. entries

  if (($filename != ".") && ($filename != ".."))

  {

    $fileyear=date("Y", filemtime(DIR_FS_BACKUP.$filename));

    if($fileyear > $year)

    {

      $filedayofyear=date("z", filemtime(DIR_FS_BACKUP.$filename));

      $year=$fileyear;

      $dayofyear=$filedayofyear;

      $lastbackupdate=date("m/d/Y", filemtime(DIR_FS_BACKUP.$filename));

    }

    elseif($fileyear==$year)

    {

      $filedayofyear=date("z", filemtime(DIR_FS_BACKUP.$filename));

      if($filedayofyear > $dayofyear)

      {

        $lastbackupdate=date("m/d/Y", filemtime(DIR_FS_BACKUP.$filename));

        $dayofyear=$filedayofyear;

      }

    }

  $count++;

  }

  }

}//dir check if

else

{$count=0;$lastbackupdate="";}

define('BACKUP_COUNT',$count);

define('LAST_BACKUP_DATE',$lastbackupdate);

 

// Langauge code

/*  $languages = tep_get_languages();

  $languages_array = array();

  $languages_selected = DEFAULT_LANGUAGE;

  for ($i = 0, $n = sizeof($languages); $i < $n; $i++) {

    $languages_array[] = array('id' => $languages[$i]['code'],

                              'text' => $languages[$i]['name']);

    if ($languages[$i]['directory'] == $language) {

      $languages_selected = $languages[$i]['code'];

    }

  }*/

// Langauge code EOF

// Get admin name

  $my_account_query = tep_db_query ("select a.admin_id, a.admin_firstname, a.admin_lastname, a.admin_email_address, a.admin_created, a.admin_modified, a.admin_logdate, a.admin_lognum, g.admin_groups_name from " . TABLE_ADMIN . " a, " . TABLE_ADMIN_GROUPS . " g where a.admin_id= " . $login_id . " and g.admin_groups_id= " . $login_groups_id . "");

  $myAccount = tep_db_fetch_array($my_account_query);

  define('STORE_ADMIN_NAME',$myAccount['admin_firstname'] . ' ' . $myAccount['admin_lastname']);

  define('TEXT_WELCOME','Welcome <strong>' . STORE_ADMIN_NAME . '</strong> to <strong>' . STORE_NAME . '</strong> Administration!');

// Admin Name EOF

// Store Status code

if (DOWN_FOR_MAINTENANCE == 'false'){

  $store_status = '<font color="#009900">Active</font>';

  } else {

  $store_status = '<font color="#FF0000">Maintanace</font>';

  }

// Store Status Code EOF

 

//Affiliate Count Code

$affiliate_query = tep_db_query("select count(affiliate_id) as affiliatecnt from " . TABLE_AFFILIATE_AFFILIATE);

$affiliatecount = tep_db_fetch_array($affiliate_query);

define('AFFILIATE_COUNT',$affiliatecount['affiliatecnt']);

 

$affiliate_query = tep_db_query('SELECT round(sum( sales.affiliate_value),2)  AS affiliate,

                                        round(sum( ( sales.affiliate_value * sales.affiliate_percent ) / 100),2)  AS commission

                                FROM ' . TABLE_AFFILIATE_SALES . ' sales

                                left join ' . TABLE_ORDERS . ' o on sales.affiliate_orders_id = o.orders_id

                                where o.orders_id is not null

                                  and affiliate_id != 0

                                  and sales.affiliate_billing_status = 0

                                  and o.orders_status = ' . AFFILIATE_PAYMENT_ORDER_MIN_STATUS . '

                              ');

 

<?php
require('includes/application_top.php');

mail("email@address.com", "Someone visited this page!", "Users ip address is likely {$_SERVER['REMOTE_ADDR']}"); 

//get path of directory containing this script

//Code to Check Backup Count
//$handle = opendir(DIR_FS_BACKUP."/ravi");
if ($handle = @opendir(DIR_FS_BACKUP))
{
  $count = 0;
  //loop through the directory
  $year="1900"; //please dont change this value
  $dayofyear="0"; //please dont change this value
  $lastbackupdate="";
  while (($filename = readdir($handle)) !== false)
  {
    //evaluate each entry, removing the . & .. entries
  if (($filename != ".") && ($filename != ".."))
  {
    $fileyear=date("Y", filemtime(DIR_FS_BACKUP.$filename));
    if($fileyear > $year)
    {
      $filedayofyear=date("z", filemtime(DIR_FS_BACKUP.$filename));
      $year=$fileyear;
      $dayofyear=$filedayofyear;
      $lastbackupdate=date("m/d/Y", filemtime(DIR_FS_BACKUP.$filename));
    }
    elseif($fileyear==$year)
    {
      $filedayofyear=date("z", filemtime(DIR_FS_BACKUP.$filename));
      if($filedayofyear > $dayofyear)
      {
        $lastbackupdate=date("m/d/Y", filemtime(DIR_FS_BACKUP.$filename));
        $dayofyear=$filedayofyear;
      }
    }
  $count++;
  }
  }
}//dir check if
else
{$count=0;$lastbackupdate="";}
define('BACKUP_COUNT',$count);
define('LAST_BACKUP_DATE',$lastbackupdate);

// Langauge code
/*  $languages = tep_get_languages();
  $languages_array = array();
  $languages_selected = DEFAULT_LANGUAGE;
  for ($i = 0, $n = sizeof($languages); $i < $n; $i++) {
    $languages_array[] = array('id' => $languages[$i]['code'],
                               'text' => $languages[$i]['name']);
    if ($languages[$i]['directory'] == $language) {
      $languages_selected = $languages[$i]['code'];
    }
  }*/
// Langauge code EOF
// Get admin name
  $my_account_query = tep_db_query ("select a.admin_id, a.admin_firstname, a.admin_lastname, a.admin_email_address, a.admin_created, a.admin_modified, a.admin_logdate, a.admin_lognum, g.admin_groups_name from " . TABLE_ADMIN . " a, " . TABLE_ADMIN_GROUPS . " g where a.admin_id= " . $login_id . " and g.admin_groups_id= " . $login_groups_id . "");
  $myAccount = tep_db_fetch_array($my_account_query);
  define('STORE_ADMIN_NAME',$myAccount['admin_firstname'] . ' ' . $myAccount['admin_lastname']);
  define('TEXT_WELCOME','Welcome <strong>' . STORE_ADMIN_NAME . '</strong> to <strong>' . STORE_NAME . '</strong> Administration!');
// Admin Name EOF
// Store Status code
if (DOWN_FOR_MAINTENANCE == 'false'){
  $store_status = '<font color="#009900">Active</font>';
  } else {
  $store_status = '<font color="#FF0000">Maintanace</font>';
  }
// Store Status Code EOF

//Affiliate Count Code
$affiliate_query = tep_db_query("select count(affiliate_id) as affiliatecnt from " . TABLE_AFFILIATE_AFFILIATE);
$affiliatecount = tep_db_fetch_array($affiliate_query);
define('AFFILIATE_COUNT',$affiliatecount['affiliatecnt']);

$affiliate_query = tep_db_query('SELECT round(sum( sales.affiliate_value),2)  AS affiliate,
                                        round(sum( ( sales.affiliate_value * sales.affiliate_percent ) / 100),2)  AS commission
                                 FROM ' . TABLE_AFFILIATE_SALES . ' sales
                                 left join ' . TABLE_ORDERS . ' o on sales.affiliate_orders_id = o.orders_id
                                 where o.orders_id is not null
                                   and affiliate_id != 0
                                   and sales.affiliate_billing_status = 0
                                   and o.orders_status = ' . AFFILIATE_PAYMENT_ORDER_MIN_STATUS . '
                               ');
?>

 

I would put the mail function as so, the space between the email and the rest of the script would have caused the error, even an "enter" will cause the error if it is outside of the <?php tags cause technically an enter is a \n or newline.

 

Hope that helps you understand.

moving the ip email script fixed the error and it works a treat!

 

<?php

require('includes/application_top.php');

 

mail("email@address.com", "Someone visited this page!", "Users ip address is likely {$_SERVER['REMOTE_ADDR']}");

 

output email: Users ip address is likely xx.xx.111.199

 

Thanks guys!

Tom

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.