[advanced search]
Results from the most recent live auction are here.
19 members in the live chat room. Join Chat!
Register Rules & FAQ NP$ Store Active Threads Mark Forums Read
Go Back   NamePros.Com > Design and Development > Programming > CODE
User Name
Password

Old 10-31-2005, 08:41 AM   · #1
SecondVersion
while ($awake){ code(); }
 
SecondVersion's Avatar
 


Name: Eric
Location: Kentucky
Trader Rating: (137)
Join Date: Mar 2005
Posts: 4,134
NP$: 1123.00 (Donate)
SecondVersion has a reputation beyond reputeSecondVersion has a reputation beyond reputeSecondVersion has a reputation beyond reputeSecondVersion has a reputation beyond reputeSecondVersion has a reputation beyond reputeSecondVersion has a reputation beyond reputeSecondVersion has a reputation beyond reputeSecondVersion has a reputation beyond reputeSecondVersion has a reputation beyond reputeSecondVersion has a reputation beyond reputeSecondVersion has a reputation beyond repute
Member of the Month
MOTM September 2005 Save a Life Child Abuse 9/11/01 :: Never Forget Baby Health Marrow Donor Program AIDS/HIV Breast Cancer Cystic Fibrosis Ethan Allen Fund Animal Cruelty Ethan Allen Fund Ethan Allen Fund Cancer Alzheimer's Protect Our Planet
Simple PHP Tell-A-Friend

Had some time on my hands, so, wrote this little script. Rather simple, and should be relatively straightforward... All you need to do is save as tellafriend.php, functions.php and upload. Then link to it, like so:
PHP Code:
<a href="./tellafriend.php?ref=<?php echo $_SERVER['SCRIPT_NAME']; ?>">Tell a friend</a>


EDIT: Updated to v1.0.1 on June 7, 2006
For some reason, using HTTP_REFERER wouldn't work :s No idea atm, but the above ^^ is a little work-around

tellafriend.php
PHP Code:
<?php

/**************************************************  **************************
*
*   Author   : Eric Sizemore ( www.secondversion.com )
*   Package  : SV's Tell-a-friend
*   Version  : 1.0.1
*   Copyright: (C) 2005-2006 Eric Sizemore
*   Site     : www.secondversion.com
*   Email    : esizemore05@gmail.com
*   File     : tellafriend.php
*
*   This program is free software; you can redistribute it and/or modify
*   it under the terms of the GNU General Public License as published by
*   the Free Software Foundation; either version 2 of the License, or
*   (at your option) any later version.
*
*   This program is distributed in the hope that it will be useful,
*   but WITHOUT ANY WARRANTY; without even the implied warranty of
*   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
*   GNU General Public License for more details.
*
**************************************************  **************************/

// ####################### Define Important Constants #######################
// You'll need to change SITE_NAME, SUBJECT and optionally MSG_WORD_WRAP
define('IN_TAF', true);
define('SITE_NAME', 'YourSite.com');
define('SUBJECT', 'Hello friend! Thought you might be interested in ' . SITE_NAME);
define('MSG_WORD_WRAP', 75);

// ############################### Functions ################################
require_once('functions.php');

$ref = (!empty($_GET['ref'])) ? clean(sanitize($_GET['ref'], 'default')) : '';

// ################################## HTML ##################################
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
    "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Tell-A-Friend</title>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
</head>

<body>

<p align="center"><b>Please tell your friends about us.</b></p>
<table cellpadding="2" cellspacing="0" style="border-collapse: collapse; border: 1px solid #111111;">
<form method="post" action="tellafriend.php?ref=<?php echo $ref; ?>" style="display: inline;">
<tr>
  <td>Your Name:</td>
  <td><input type="text" name="name" size="20"></td>
</tr>
<tr>
  <td>Your Email address:</td>
  <td><input type ="text" name="email" size="20"></td>
</tr>
<tr>
  <td>Friend Email address:</td>
  <td><input type ="text" name="femail" size="20"></td>
</tr>
<tr>
  <td valign="top">Message:</td>
  <td><textarea name="message" rows="5" cols="20"></textarea></td>
</tr>
<tr>
  <td></td>
  <td><input type="submit" name="submit" value="Submit"></td>
</tr>
</form>
</table>
<?php

// ############################ Main Script Start ###########################
if (isset($_POST['submit']) AND $_POST['submit'] != '')
{
    
$name    = clean(sanitize($_POST['name'], 'default'));
    
$email   = clean(sanitize($_POST['email'], 'default'));
    
$femail  = clean(sanitize($_POST['femail'], 'default'));
    
$message = clean(wordwrap(sanitize($_POST['message'], 'light'), MSG_WORD_WRAP));
    
$message = str_replace("\n", '<br>', $message);

    if (!
is_valid_email($email) OR is_email_injection($email) OR !is_valid_email($femail) OR is_email_injection($femail))
    {
        echo
'<br />Your email (or your friends) is either invalid or left blank. Please try again.';
    }
    else
    {
        
$e = $email;

        if (empty(
$name) OR empty($message) OR is_email_injection($name))
        {
            echo
'<br />One or more required fields left blank. Please try again.';
        }
        else
        {
            
$headers = 'MIME-Version: 1.0' . "\r\n";
            
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
            
$headers .= 'Content-Transfer-Encoding: 8bit' . "\r\n";
            
$headers .= 'From: ' . $name . ' <' . $e . '>' . "\r\n";
            
$headers .= 'X-Priority: 1' . "\r\n";
            
$headers .= 'X-Mailer: SVs Tell-a-friend v1.0.1' . "\r\n";

            
$send = mail($femail, SUBJECT, "
            <html>
            <head>
            <title>Email from $name</title>
            </head>

            <body>

            <p>Hello! $name is sending you this message because they think you'll enjoy our website: "
. SITE_NAME . ". <br>Their message is included below.</p>
            
            <p>$message"
. ((!empty($ref)) ? '<br><br><a href="http://' . $_SERVER['HTTP_HOST'] . $ref . '">' . SITE_NAME . '</a>' : '') . "</p>

            </body>
            </html>"
, $headers);

            if (
$send)
            {
                echo
'<br />Thank you, ' . $name . ', for telling your friend about us.';
            }
            else
            {
                echo
'<br />Seems to have been a problem sending the email. Please try again.';
            }
        }
    }
}

// That's all folks!
?>
<p>Powered by <a href="http://www.secondversion.com">SVs Tell-a-friend v1.0.1</a></p>

</body>
</html>

functions.php
PHP Code:
<?php

/**************************************************  **************************
*
*   Author   : Eric Sizemore ( www.secondversion.com )
*   Package  : SV's Tell-a-friend
*   Version  : 1.0.1
*   Copyright: (C) 2005-2006 Eric Sizemore
*   Site     : www.secondversion.com
*   Email    : esizemore05@gmail.com
*   File     : functions.php
*
*   This program is free software; you can redistribute it and/or modify
*   it under the terms of the GNU General Public License as published by
*   the Free Software Foundation; either version 2 of the License, or
*   (at your option) any later version.
*
*   This program is distributed in the hope that it will be useful,
*   but WITHOUT ANY WARRANTY; without even the implied warranty of
*   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
*   GNU General Public License for more details.
*
**************************************************  **************************/

if (!defined('IN_TAF'))
{
    die();
}

/*
Strip any unsafe tags/chars/attributes from input data

@param  string  Data to be cleaned
@param  string  Level or 'strength' of cleaning - default or light
                pretty much the same, but one will remove new lines, and CRLF
@return string
*/
function sanitize($data, $strength)
{
    switch (
$strength)
    {
        case
'':
        case
'default':
             
$search = array('@<script[^>]*?>.*?</script>@si',
                 
'@<applet[^>]*?>.*?</applet>@si',
                 
'@<object[^>]*?>.*?</object>@si',
                 
'@<iframe[^>]*?>.*?</iframe>@si',
                 
'@<style[^>]*?>.*?</style>@si',
                 
'@<form[^>]*?>.*?</form>@si',
                 
'@<[\/\!]*?[^<>]*?>@si',
                 
'@([\r\n])[\s]+@',
                 
'@&(lt|#60);@i',
                 
'@&(gt|#62);@i'
             
);
             break;
        case
'light':
             
$search = array('@<script[^>]*?>.*?</script>@si',
                 
'@<applet[^>]*?>.*?</applet>@si',
                 
'@<object[^>]*?>.*?</object>@si',
                 
'@<iframe[^>]*?>.*?</iframe>@si',
                 
'@<style[^>]*?>.*?</style>@si',
                 
'@<form[^>]*?>.*?</form>@si',
                 
'@<[\/\!]*?[^<>]*?>@si',
                 
'@&(amp|#38);@i',
                 
'@&(lt|#60);@i',
                 
'@&(gt|#62);@i'
             
);
             break;
    }

    return
preg_replace($search, '', strip_tags($data));
}

/*
Trim and strip slashes from data

@param  string  Data to be cleaned
@return string
*/
function clean($data)
{
    return
trim(stripslashes($data));
}

/*
Tests for a valid email address

@param  string  Email address
@return boolean
*/
function is_valid_email($email)
{
    
$pattern = '/^[a-z0-9&\.\-_\+]+@[a-z0-9\-]+\.([a-z0-9\-]+\.)*?[a-z]{2,6}+$/is';
    
    return (
preg_match($pattern, $email)) ? true : false;
}

/*
Tests input data from the contact form for email injection - very basic

@param  string  Data to check
@return boolean
*/
function is_email_injection($data)
{
    return (
eregi("(To:|Bcc:|Cc:|Content-type:|\\r\\n)", urldecode($data))) ? true : false;
}

?>


-Eric


Please register or log-in into NamePros to hide ads
__________________
6k.org @ Sedo auction
SecondVersion.com - The Personal Blog of SecondVersion
Domain Name Portfolio - Get your free copy. - Version 1.0.1 now available!!
MetaCreator.com - Free Meta Tag Creator

Last edited by SecondVersion : 06-07-2006 at 03:23 AM.
SecondVersion is offline   Reply With Quote
Old 11-01-2005, 08:06 AM   · #2
Muneeb2Good
Senior Member
 
Muneeb2Good's Avatar
 
Name: Muneeb Ahmed
Location: Poly-Web.com
Trader Rating: (30)
Join Date: Jun 2005
Posts: 1,312
NP$: 975.25 (Donate)
Muneeb2Good is a name known to allMuneeb2Good is a name known to allMuneeb2Good is a name known to allMuneeb2Good is a name known to allMuneeb2Good is a name known to allMuneeb2Good is a name known to all
Wowwww its really Superb i have done it and its working ...Thanks

well i have a Question that is it working for all the browsers or only for IE 5.5 or higher ....Well thanks again !
Muneeb2Good is offline   Reply With Quote
Old 11-01-2005, 03:58 PM   · #3
SecondVersion
while ($awake){ code(); }
 
SecondVersion's Avatar
 


Name: Eric
Location: Kentucky
Trader Rating: (137)
Join Date: Mar 2005
Posts: 4,134
NP$: 1123.00 (Donate)
SecondVersion has a reputation beyond reputeSecondVersion has a reputation beyond reputeSecondVersion has a reputation beyond reputeSecondVersion has a reputation beyond reputeSecondVersion has a reputation beyond reputeSecondVersion has a reputation beyond reputeSecondVersion has a reputation beyond reputeSecondVersion has a reputation beyond reputeSecondVersion has a reputation beyond reputeSecondVersion has a reputation beyond reputeSecondVersion has a reputation beyond repute
Member of the Month
MOTM September 2005 Save a Life Child Abuse 9/11/01 :: Never Forget Baby Health Marrow Donor Program AIDS/HIV Breast Cancer Cystic Fibrosis Ethan Allen Fund Animal Cruelty Ethan Allen Fund Ethan Allen Fund Cancer Alzheimer's Protect Our Planet
Thanks Yes It will work in all browsers
__________________
6k.org @ Sedo auction
SecondVersion.com - The Personal Blog of SecondVersion
Domain Name Portfolio - Get your free copy. - Version 1.0.1 now available!!
MetaCreator.com - Free Meta Tag Creator
SecondVersion is offline   Reply With Quote
Old 05-02-2006, 08:36 AM   · #4
wvccboy
Account Closed
 
Name: Jay
Trader Rating: (16)
Join Date: Jan 2006
Posts: 460
NP$: 71.00 (Donate)
wvccboy is a jewel in the roughwvccboy is a jewel in the roughwvccboy is a jewel in the rough
Looks nice!
wvccboy is offline   Reply With Quote
Old 05-02-2006, 08:26 PM   · #5
ninedogger
DNOA Member
 
ninedogger's Avatar
 
Location: Iowa
Trader Rating: (38)
Join Date: Jun 2004
Posts: 655
NP$: 12.10 (Donate)
ninedogger is a glorious beacon of lightninedogger is a glorious beacon of lightninedogger is a glorious beacon of lightninedogger is a glorious beacon of lightninedogger is a glorious beacon of lightninedogger is a glorious beacon of light
Save The Children
Originally Posted by wvccboy
Looks nice!



yes it does, i use it on my sites
__________________
Want to prove yourself?

CHECK OUT MY DOMAINS!
ninedogger is offline  
  Reply With Quote
Old 05-02-2006, 08:59 PM   · #6
YaSHaRz
NamePros Member
 
Trader Rating: (0)
Join Date: Apr 2006
Posts: 102
NP$: 0.00 (Donate)
YaSHaRz is an unknown quantity at this point
Thanks for the script, hopefuly I can get it working fine.
By the way, the demo link is down.
YaSHaRz is offline   Reply With Quote
Old 06-07-2006, 03:26 AM   · #7
SecondVersion
while ($awake){ code(); }
 
SecondVersion's Avatar
 


Name: Eric
Location: Kentucky
Trader Rating: (137)
Join Date: Mar 2005
Posts: 4,134
NP$: 1123.00 (Donate)
SecondVersion has a reputation beyond reputeSecondVersion has a reputation beyond reputeSecondVersion has a reputation beyond reputeSecondVersion has a reputation beyond reputeSecondVersion has a reputation beyond reputeSecondVersion has a reputation beyond reputeSecondVersion has a reputation beyond reputeSecondVersion has a reputation beyond reputeSecondVersion has a reputation beyond reputeSecondVersion has a reputation beyond reputeSecondVersion has a reputation beyond repute
Member of the Month
MOTM September 2005 Save a Life Child Abuse 9/11/01 :: Never Forget Baby Health Marrow Donor Program AIDS/HIV Breast Cancer Cystic Fibrosis Ethan Allen Fund Animal Cruelty Ethan Allen Fund Ethan Allen Fund Cancer Alzheimer's Protect Our Planet
Updated to 1.0.1, see first post.

-Eric
__________________
6k.org @ Sedo auction
SecondVersion.com - The Personal Blog of SecondVersion
Domain Name Portfolio - Get your free copy. - Version 1.0.1 now available!!
MetaCreator.com - Free Meta Tag Creator
SecondVersion is offline   Reply With Quote
Closed Thread

NamePros is a revenue sharing forum.

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Randomingly choosing a quote from Database, PHP SquireQuack Programming 9 10-31-2005 05:50 AM
Simple PHP Form Issue buddybuddha Programming 3 10-30-2005 02:53 PM
Simple gz compression GeorgeB CODE 3 07-01-2005 10:56 AM

Site Sponsors
Hunting Moon http://www.internetinvestments.com/ Arcade Script
Advertise your business at NamePros
All times are GMT -7. The time now is 01:28 AM.


Powered by: vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 2.4.0