Jump to content

Landing page auto email notification to web master


ozziemate

Recommended Posts

Hi Guys, Gals,

First post here and should be really easy for someone who knows anything about php scripts [ not like me a I know very little] Hopefully I might learn something at this forum...looks real cool!

Simply need a bit of script that sends an email when the page landed on is downloaded.

The email is simply to inform the web master [me] that someone has downloaded the page with out having to plow through stat software.

 

Possibly including the viewers IP address and browser type. No need for database.

Any help would be appreciated.

 

 

is the page a php script? you could add this to the top of it

$message = "IP: ".$_SERVER['REMOTE_ADDR']."\r\n";
$message = "User_agent: ".$_SERVER["HTTP_USER_AGENT"]."\r\n";
$message = wordwrap($message, 70);
mail('[email protected]', 'Someone downloaded '.basename(__FILE__), $message);

 

Scott.

Just a bit of a different approach to ratcateme's code, with also some headers for the mail().

 

<?php
$page = pathinfo($_SERVER['PHP_SELF'], PATHINFO_BASENAME);
$ip = gethostbyname($REMOTE_ADDR);
$useragent = $_SERVER['HTTP_USER_AGENT'];

$headers  = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers .= 'To: Admin <[email protected]>' . "\r\n";
$headers .= 'From: Site Guard <[email protected]>' . "\r\n";

$subject = 'Someone visited: ' . $page;

$body = 'Someone visited: ' . $page . "\r\n";
$body .= 'IP: ' . $ip;
$body .= 'User Agent: ' . $useragent;

mail('[email protected]', $subject, $message, $headers);
?>

Hey thanks guys...but

The best thing to to to same time is to show the template I want it to be inserted into and if you could post the amended version it wil be self explanitory

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"

"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

 

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">

{* Change lang="en" to the language of your site *}

 

<head>

 

<title>{sitename} - {title}</title>

{* The sitename is changed in Site Admin/Global settings. {title} is the name of each page *}

 

{metadata}

{* Don't remove this! Metadata is entered in Site Admin/Global settings. *}

 

{stylesheet}

{* This is how all the stylesheets attached to this template are linked to *}

 

{cms_selflink dir="start" rellink=1}

{cms_selflink dir="prev" rellink=1}

{cms_selflink dir="next" rellink=1}

{* Relational links for interconnections between pages, good for accessibility and Search Engine Optmization *}

 

 

{literal}

<script type="text/JavaScript">

<!--

//pass min and max -measured against window width

function P7_MinMaxW(a,b){

var nw="auto",w=document.documentElement.clientWidth;

if(w>=b){nw=b+"px";}if(w<=a){nw=a+"px";}return nw;

}

//-->

</script>

<!--[if lte IE 6]>

<style type="text/css">

#pagewrapper {width:expression(P7_MinMaxW(1000,1000));}

#container {height: 1%;}

</style>

<![endif]-->

{/literal}

{* The min and max page width for Internet Explorer is set here. For other browsers it's in the stylesheet "Layout: Left sidebar + 1 column" *}

 

 

<!--[if IE]>

<script type="text/javascript" src="modules/MenuManager/CSSMenu.js"></script>

<![endif]-->

{* The above JavaScript is required for CSSMenu to work in IE *}

 

</head>

 

<body>

 

<div id="pagewrapper">

 

    {* start accessibility skip links *}

    <ul class="accessibility">

      <li>{anchor anchor='menu_vert' title='Skip to navigation' accesskey='n' text='Skip to navigation'}</li>

      <li>{anchor anchor='main' title='Skip to content' accesskey='s' text='Skip to content'}</li>

    </ul>

    {* end accessibility skip links *}

 

 

    <hr class="accessibility" />

    {* Horizontal ruler that is hidden for visual browsers by CSS *}

 

 

   {* Start Header, with logo image that links to the default start page. Logo image is changed in the stylesheet  "For template: Left menu + 1 column" *}

   <div id="header">

           <h1>{cms_selflink page="home" text="$sitename"}</h1>

   <hr class="accessibility" />

   </div>

   {* End Header *}

 

 

   

   {* Start Content (Navigation and Content columns) *}

   <div id="content">

 

      {* Start Navigation *}

      <div id="sidebar">

         <h2 class="accessibility">Navigation</h2>

         </br>

</br></br>

 

 

 

 

 

 

{menu template='cssmenu.tpl'}

</br>

{global_content name='sponsors001'}

</br>

</br>

{global_content name='sponsors002'}

</br>

</br>

{global_content name='sponsors003'}

</br>

</br>

{global_content name='sponsors004'}

 

      <hr class="accessibility" />

      </div>

      {* End Navigation *}

 

 

      {* Start Content Area *}

      <div id="main">

         <div style="float: right;"></div>

         

                  {content} <br />

 

         

      <hr class="accessibility" />

      </div>

  {* End Content Area *}

 

 

   </div>

   {* End Content *}

{* Start Footer. Edit the footer in the Global Content Block called "footer" *}

   <div id="footer">

       {global_content name='footer'}

</div>   

   {* End Footer  *}

 

 

 

 

</div>{* end pagewrapper *}

</body>

</html>

hope this helps...

another issue I just thought of is how to avoid multiple emails from the one ip address during his visit as he returns to the page...for another look...

great guys...managed to get it to work using both your posts as inspiration.

thanks...

just one small question?

the index page uses [ as an example ]

the url: index.php?page=home

How can I get the email sent to show the page name rather than just the "basename" [ I think that's what you call it...

would it be something like:

PATHINFO_BASENAME ? =

Thanks PF,

what I actually wanted only was to simply get an email when someone goes to the site, not what he does once there. Simple little outcome instead of using an site enter submit link/button.

what I have actually inserted in the global index page is as follows:

$page = pathinfo($_SERVER['PHP_SELF'], PATHINFO_BASENAME);

$ip = gethostbyname($REMOTE_ADDR);

$useragent = $_SERVER['HTTP_USER_AGENT'];

 

$headers  = 'MIME-Version: 1.0' . "\r\n";

$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";

$headers .= 'To: Admin <[email protected]>' . "\r\n";

$headers .= 'From: Site admin <[email protected]>' . "\r\n";

 

$subject = 'Someone visited Centreplaceonline.com: ' . $page;

 

$message .= 'Someone visited Centreplaceonline.com: ' . $page . "\r\n";

 

$message .= 'Remote computer IP: ' . $ip;

 

mail('[email protected]', $subject, $message, $headers);

Of course what happens is that every time the index page is downloaded I will get an email that says the same thing.

If the script can only send once in a given session would be great...

on second thoughts possibly if the script only sent due to domain visit rather than page visit, then whilst still with in the domain ionly one email will be sent...or something like that...

unfortunately due to the sites cms structure your suggestion floods me with emails that show page info as "array"

 

 

 

 

 

Use a session, or even a cookie for determining if it's the first time he/she visits the page site:

 

<?php
session_start();
if(!isset($_SESSION['my_first_time'])){
     //send the email
     $_SESSION['my_first_time'] = true;
}
//continue with the normal page html and stuff
?>

 

The same applies to a cookie, which you can use instead of the session.

ahh so much to learn.... :)

so how would you include the cookie in the the script

$page = pathinfo($_SERVER['PHP_SELF'], PATHINFO_BASENAME);

$ip = gethostbyname($REMOTE_ADDR);

$useragent = $_SERVER['HTTP_USER_AGENT'];

 

$headers  = 'MIME-Version: 1.0' . "\r\n";

$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";

$headers .= 'To: Admin <[email protected]>' . "\r\n";

$headers .= 'From: Site admin <[email protected]>' . "\r\n";

 

$subject = 'Someone visited Centreplaceonline.com: ' . $page;

 

$message .= 'Someone visited Centreplaceonline.com: ' . $page . "\r\n";

 

$message .= 'Remote computer IP: ' . $ip;

 

mail('[email protected]', $subject, $message, $headers);

 

As you can gather I know a little but no-where near enough about php. Stucture and process...

I understand basic programing principles reaonably well such as the use of variables and logic strings etc in general progamming but nonspecific to php...

 

 

 

<?php
if(!isset($_COOKIE['firsttime'])){
    /* insert the code you have here */
    setcookie('firsttime', 'true', time()+60*60*24*10); //set the cookie for 10 days 
}
?>

 

for the session way:

<?php
session_start();
if(!isset($_SESSION['firsttime'])){
    /* insert the code you have here */
    $_SESSION['firsttime'] = true;
}
?>

 

A cookie is a small file stored locally on the user's computer and it's valid until the expire time is reached. A session is stored on the server and is destroyed when the user closes the browser or the session expire time is reached.

ok this is what is inserted to the global index page.

{session_start();

if(!isset($_SESSION['firsttime']))

$page = pathinfo($_SERVER['PHP_SELF'], PATHINFO_BASENAME);

$ip = gethostbyname($REMOTE_ADDR);

$useragent = $_SERVER['HTTP_USER_AGENT'];

 

$headers  = 'MIME-Version: 1.0' . "\r\n";

$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";

$headers .= 'To: Admin <[email protected]>' . "\r\n";

$headers .= 'From: Site admin <[email protected]>' . "\r\n";

 

$subject = 'Someone visited Centreplaceonline.com: ' . $page;

 

$message .= 'Someone visited Centreplaceonline.com: ' . $page . "\r\n";

 

$message .= 'Remote computer IP: ' . $ip;

 

mail('[email protected]', $subject, $message, $headers);

          $_SESSION['firsttime'] = true;

}

I am getting an email for every page downloaded including refreshes...[ including all the page url info]hmmm...but this will do for now..

 

Thanks for your help....

Obviously I need to get a little more info on structure etc....and will come back to this

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.