Click to See Complete Forum and Search --> : php referral program


mikeyzc
08-12-2003, 07:58 AM
Ok...I have a resellers website that has a link to our website on it. I want to make it so when a user clicks on the link from our reseller site they come to our site and a session is started which holds the name of the reseller that they came to our site from. I then want to pull the reseller information from this session when they are filling out a form. at the end of the form I want to insert the reseller information into the form that is emailed to us, so we know which reseller site they were referred to us by.

I'm fairly new to php, but if I was pointed into the right direction I think I could handle it.


Thanks in advance.

brendandonhue
08-12-2003, 10:06 AM
You could just pass the information via the query string.
The reseller would just plug their information on to the end of the URL. ex:
http://yoursite.com?referrer=oursite.com
and you can retrieve the info using
$_GET['referrer']

pyro
08-12-2003, 10:08 AM
And then read up on sessions (http://us4.php.net/manual/en/ref.session.php) to see how to pass the referrer from page to page so you can pull it out on the form page, where you need it.

mikeyzc
08-12-2003, 10:19 AM
so I would have to write the referrer=oursite.com to a session

pyro
08-12-2003, 10:27 AM
Yes, I would do something like this: (it will set the value of referrer to the session [oursite.com])

<?php
session_start();
#use $HTTP_SESSION_VARS with PHP 4.0.6 or less
$_SESSION['referrer'] = $_GET["referrer"];
?>

mikeyzc
08-12-2003, 10:37 AM
thanks for the help! you made it pretty easy to understand for a newbie like myself :)

pyro
08-12-2003, 10:39 AM
Happy to help, as always. :)

mikeyzc
08-13-2003, 08:45 AM
ive got the session written,b ut when i navigate to the form page and complete the form and submit it is not inserting the referrer code and it is giving me a parse error on the line where im trying to insert it.


function send_mail ( $Data )
{
/* Collect the email data here */
$To = "webrequest@antekhealthware.com";
$Subject = "***DAQbilling Evaluation Request***";
$Msg = stripcslashes ( "Contact Name: " . $Data["txt_name"] . "\n" .
"Facility Name: " . $Data["txt_facname"] . "\n" .
"Address #1: " . $Data["txt_address"] . "\n" .
"Address #2: " . $Data["txt_address2"] . "\n" .
"City: " . $Data["txt_city"] . "\n" .
"State: " . $Data["txt_state"] . "\n" .
"Zipcode: " . $Data["txt_zip"] . "\n" .
"Phone Number: " . $Data["txt_phone"] . "\n" .
"Hours of Operation: " . $Data["txt_hours"] . "\n" .
"Best time to contact: " . $Data["txt_contact"] . "\n" .
"Billing currently completed by (In-house staff or billing service)? " . $Data["txt_staff"] . "\n" .
"Does any of your billing staff work from home? " . $Data["txt_home"] . "\n" .
"FullTime Providers: " . $Data["txt_fulltime"] . "\n" .
"PartTime Providers: " . $Data["txt_parttime"] . "\n" .
"Number of locations: " . $Data["txt_locations"]. "\n" .
"Average patients per day per provider? " . $Data["txt_average"] . "\n" .
"Percentage of Medicare Patients in your practice? " . $Data["txt_percentage"]. "\n" .
"Email Address: " . $Data["txt_mail"] . "\n" .
"Questions or Comments: " . $Data["txt_comments"] . "\n" );
"Referral Site: " . $Data["referrer"] . "\n" );
$From = "From: " . stripcslashes ( $Data["txt_mail"] );
$Headers = trim ( $From . "\n" );

/* Send the email using the SMTP mail() */
mail ( $To, $Subject, $Msg, $Headers );
}
%>

pyro
08-13-2003, 08:56 AM
When using sessions, you always need to use sessions_start() before you try to read/write to them. Also, the correct way to read the session would be $_SESSION["referrer"] (or, if you are using a version of PHP eariler than PHP 4.1.0, $HTTP_SESSION_VARS["referrer"])

mikeyzc
08-13-2003, 09:26 AM
Originally posted by pyro
When using sessions, you always need to use sessions_start() before you try to read/write to them. Also, the correct way to read the session would be $_SESSION["referrer"] (or, if you are using a version of PHP eariler than PHP 4.1.0, $HTTP_SESSION_VARS["referrer"])

ok...i think im confusing myself...

the link to my page from the referring site is:

http://mycompany.com/sub/index.php?referrer=123

the index.php page that loads when they click the link has:

<?php
session_start();
$_SESSION['referrer'] = $_GET["referrer"];

?>

from there they click a link to a form. the form php contains:


session_start();
$_SESSION['referrer'] = $_GET["referrer"];

function send_mail ( $Data )
{
/* Collect the email data here */
$To = "webrequest@antekhealthware.com";
$Subject = "***DAQbilling Evaluation Request***";
$Msg = stripcslashes ( "Contact Name: " . $Data["txt_name"] . "\n" .
"Facility Name: " . $Data["txt_facname"] . "\n" .
"Address #1: " . $Data["txt_address"] . "\n" .
"Address #2: " . $Data["txt_address2"] . "\n" .
"City: " . $Data["txt_city"] . "\n" .
"State: " . $Data["txt_state"] . "\n" .
"Zipcode: " . $Data["txt_zip"] . "\n" .
"Phone Number: " . $Data["txt_phone"] . "\n" .
"Hours of Operation: " . $Data["txt_hours"] . "\n" .
"Best time to contact: " . $Data["txt_contact"] . "\n" .
"Billing currently completed by (In-house staff or billing service)? " . $Data["txt_staff"] . "\n" .
"Does any of your billing staff work from home? " . $Data["txt_home"] . "\n" .
"FullTime Providers: " . $Data["txt_fulltime"] . "\n" .
"PartTime Providers: " . $Data["txt_parttime"] . "\n" .
"Number of locations: " . $Data["txt_locations"]. "\n" .
"Average patients per day per provider? " . $Data["txt_average"] . "\n" .
"Percentage of Medicare Patients in your practice? " . $Data["txt_percentage"]. "\n" .
"Email Address: " . $Data["txt_mail"] . "\n" .
"Questions or Comments: " . $Data["txt_comments"] . "\n" );
"Referral Code: " . $_SESSION["referrer"] . "\n" );
$From = "From: " . stripcslashes ( $Data["txt_mail"] );
$Headers = trim ( $From . "\n" );

/* Send the email using the SMTP mail() */
mail ( $To, $Subject, $Msg, $Headers );
}
%>



now if the user has multiple pages to navigate through before they get to the form would i need...
<?php
session_start();
$_SESSION['referrer'] = $_GET["referrer"];

?>

on every page?

pyro
08-13-2003, 09:42 AM
By default, sessions use cookies, so you don't need to pass the sessions variable from page to page.

Also, this code is incorrect:

$_SESSION['referrer'] = $_GET["referrer"];

The $_SESSION["referrer"] is already the sessions variable. You don't need to assign anything to it, though you can asign it to a variable, if you wish:

$mysession = $_SESSION["referrer"]; # will equal the value of the session variable.

mikeyzc
08-13-2003, 10:22 AM
okay. sorry for it seeming like your talking to a brick wall, but when inserting the session information into the email what syntax should be used. i finally got passed my parse errors, but it's just inserting a blank into the email for the referrer.


function send_mail ( $Data )
{
/* Collect the email data here */
$To = "webrequest@antekhealthware.com";
$Subject = "***DAQbilling Evaluation Request***";
$Msg = stripcslashes ( "Contact Name: " . $Data["txt_name"] . "\n" .
"Facility Name: " . $Data["txt_facname"] . "\n" .
"Address #1: " . $Data["txt_address"] . "\n" .
"Address #2: " . $Data["txt_address2"] . "\n" .
"City: " . $Data["txt_city"] . "\n" .
"State: " . $Data["txt_state"] . "\n" .
"Zipcode: " . $Data["txt_zip"] . "\n" .
"Phone Number: " . $Data["txt_phone"] . "\n" .
"Hours of Operation: " . $Data["txt_hours"] . "\n" .
"Best time to contact: " . $Data["txt_contact"] . "\n" .
"Billing currently completed by (In-house staff or billing service)? " . $Data["txt_staff"] . "\n" .
"Does any of your billing staff work from home? " . $Data["txt_home"] . "\n" .
"FullTime Providers: " . $Data["txt_fulltime"] . "\n" .
"PartTime Providers: " . $Data["txt_parttime"] . "\n" .
"Number of locations: " . $Data["txt_locations"]. "\n" .
"Average patients per day per provider? " . $Data["txt_average"] . "\n" .
"Percentage of Medicare Patients in your practice? " . $Data["txt_percentage"]. "\n" .
"Email Address: " . $Data["txt_mail"] . "\n" .
"Questions or Comments: " . $Data["txt_comments"] . "\n" .
"Referral Code: " . $_SESSION["referrer"] );
$From = "From: " . stripcslashes ( $Data["txt_mail"] );
$Headers = trim ( $From . "\n" );

/* Send the email using the SMTP mail() */
mail ( $To, $Subject, $Msg, $Headers );
}
%>

pyro
08-13-2003, 10:48 AM
You need to insert session_start() before you can read the sessions variable. Try this:

function send_mail ( $Data )
{
session_start(); #start the session
/* Collect the email data here */
$To = "webrequest@antekhealthware.com";
$Subject = "***DAQbilling Evaluation Request***";
$Msg = stripcslashes ( "Contact Name: " . $Data["txt_name"] . "\n" .
"Facility Name: " . $Data["txt_facname"] . "\n" .
"Address #1: " . $Data["txt_address"] . "\n" .
"Address #2: " . $Data["txt_address2"] . "\n" .
"City: " . $Data["txt_city"] . "\n" .
"State: " . $Data["txt_state"] . "\n" .
"Zipcode: " . $Data["txt_zip"] . "\n" .
"Phone Number: " . $Data["txt_phone"] . "\n" .
"Hours of Operation: " . $Data["txt_hours"] . "\n" .
"Best time to contact: " . $Data["txt_contact"] . "\n" .
"Billing currently completed by (In-house staff or billing service)? " . $Data["txt_staff"] . "\n" .
"Does any of your billing staff work from home? " . $Data["txt_home"] . "\n" .
"FullTime Providers: " . $Data["txt_fulltime"] . "\n" .
"PartTime Providers: " . $Data["txt_parttime"] . "\n" .
"Number of locations: " . $Data["txt_locations"]. "\n" .
"Average patients per day per provider? " . $Data["txt_average"] . "\n" .
"Percentage of Medicare Patients in your practice? " . $Data["txt_percentage"]. "\n" .
"Email Address: " . $Data["txt_mail"] . "\n" .
"Questions or Comments: " . $Data["txt_comments"] . "\n" .
"Referral Code: " . $_SESSION["referrer"] );
$From = "From: " . stripcslashes ( $Data["txt_mail"] );
$Headers = trim ( $From . "\n" );

/* Send the email using the SMTP mail() */
mail ( $To, $Subject, $Msg, $Headers );
}

pyro
08-13-2003, 10:48 AM
You need to insert session_start() before you can read the sessions variable. Try this:

function send_mail ( $Data )
{
session_start(); #start the session
/* Collect the email data here */
$To = "webrequest@antekhealthware.com";
$Subject = "***DAQbilling Evaluation Request***";
$Msg = stripcslashes ( "Contact Name: " . $Data["txt_name"] . "\n" .
"Facility Name: " . $Data["txt_facname"] . "\n" .
"Address #1: " . $Data["txt_address"] . "\n" .
"Address #2: " . $Data["txt_address2"] . "\n" .
"City: " . $Data["txt_city"] . "\n" .
"State: " . $Data["txt_state"] . "\n" .
"Zipcode: " . $Data["txt_zip"] . "\n" .
"Phone Number: " . $Data["txt_phone"] . "\n" .
"Hours of Operation: " . $Data["txt_hours"] . "\n" .
"Best time to contact: " . $Data["txt_contact"] . "\n" .
"Billing currently completed by (In-house staff or billing service)? " . $Data["txt_staff"] . "\n" .
"Does any of your billing staff work from home? " . $Data["txt_home"] . "\n" .
"FullTime Providers: " . $Data["txt_fulltime"] . "\n" .
"PartTime Providers: " . $Data["txt_parttime"] . "\n" .
"Number of locations: " . $Data["txt_locations"]. "\n" .
"Average patients per day per provider? " . $Data["txt_average"] . "\n" .
"Percentage of Medicare Patients in your practice? " . $Data["txt_percentage"]. "\n" .
"Email Address: " . $Data["txt_mail"] . "\n" .
"Questions or Comments: " . $Data["txt_comments"] . "\n" .
"Referral Code: " . $_SESSION["referrer"] );
$From = "From: " . stripcslashes ( $Data["txt_mail"] );
$Headers = trim ( $From . "\n" );

/* Send the email using the SMTP mail() */
mail ( $To, $Subject, $Msg, $Headers );
}

mikeyzc
08-13-2003, 10:55 AM
Originally posted by pyro
[B]You need to insert session_start() before you can read the sessions variable.

i did, except i started the session before the send_mail function. I tried your way and it did not work either. No errors, but it's just not inserting the referral code.

pyro
08-13-2003, 10:58 AM
It is working fine in my test pages... Can you post you code for both pages, so I can try to find the problem, please?

mikeyzc
08-13-2003, 11:10 AM
index.php


<?php
session_start();
#use $HTTP_SESSION_VARS with PHP 4.0.6 or less
$_SESSION['referrer'] = $_GET["referrer"];
?>

<html>
<head>
<title>DAQbilling</title>
<a href="http://www.mydomian.com/sub/referform.php">form</a>
</body>
</html>

form.php


function send_mail ( $Data )
{
session_start(); #start the session
/* Collect the email data here */
$To = "mcalcagno@antekhealthware.com";
$Subject = "***DAQbilling Evaluation Request***";
$Msg = stripcslashes ( "Contact Name: " . $Data["txt_name"] . "\n" .
"Facility Name: " . $Data["txt_facname"] . "\n" .
"Address #1: " . $Data["txt_address"] . "\n" .
"Address #2: " . $Data["txt_address2"] . "\n" .
"City: " . $Data["txt_city"] . "\n" .
"State: " . $Data["txt_state"] . "\n" .
"Zipcode: " . $Data["txt_zip"] . "\n" .
"Phone Number: " . $Data["txt_phone"] . "\n" .
"Hours of Operation: " . $Data["txt_hours"] . "\n" .
"Best time to contact: " . $Data["txt_contact"] . "\n" .
"Billing currently completed by (In-house staff or billing service)? " . $Data["txt_staff"] . "\n" .
"Does any of your billing staff work from home? " . $Data["txt_home"] . "\n" .
"FullTime Providers: " . $Data["txt_fulltime"] . "\n" .
"PartTime Providers: " . $Data["txt_parttime"] . "\n" .
"Number of locations: " . $Data["txt_locations"]. "\n" .
"Average patients per day per provider? " . $Data["txt_average"] . "\n" .
"Percentage of Medicare Patients in your practice? " . $Data["txt_percentage"]. "\n" .
"Email Address: " . $Data["txt_mail"] . "\n" .
"Questions or Comments: " . $Data["txt_comments"] . "\n" .
"Referral Code: " . $Data["referrer"] );
$From = "From: " . stripcslashes ( $Data["txt_mail"] );
$Headers = trim ( $From . "\n" );

/* Send the email using the SMTP mail() */
mail ( $To, $Subject, $Msg, $Headers );
}
%>

pyro
08-13-2003, 11:15 AM
You referenced the session wrong in form.php. Try this one:

function send_mail ( $Data )
{
session_start(); #start the session
/* Collect the email data here */
$To = "mcalcagno@antekhealthware.com";
$Subject = "***DAQbilling Evaluation Request***";
$Msg = stripcslashes ( "Contact Name: " . $Data["txt_name"] . "\n" .
"Facility Name: " . $Data["txt_facname"] . "\n" .
"Address #1: " . $Data["txt_address"] . "\n" .
"Address #2: " . $Data["txt_address2"] . "\n" .
"City: " . $Data["txt_city"] . "\n" .
"State: " . $Data["txt_state"] . "\n" .
"Zipcode: " . $Data["txt_zip"] . "\n" .
"Phone Number: " . $Data["txt_phone"] . "\n" .
"Hours of Operation: " . $Data["txt_hours"] . "\n" .
"Best time to contact: " . $Data["txt_contact"] . "\n" .
"Billing currently completed by (In-house staff or billing service)? " . $Data["txt_staff"] . "\n" .
"Does any of your billing staff work from home? " . $Data["txt_home"] . "\n" .
"FullTime Providers: " . $Data["txt_fulltime"] . "\n" .
"PartTime Providers: " . $Data["txt_parttime"] . "\n" .
"Number of locations: " . $Data["txt_locations"]. "\n" .
"Average patients per day per provider? " . $Data["txt_average"] . "\n" .
"Percentage of Medicare Patients in your practice? " . $Data["txt_percentage"]. "\n" .
"Email Address: " . $Data["txt_mail"] . "\n" .
"Questions or Comments: " . $Data["txt_comments"] . "\n" .
"Referral Code: " . $_SESSION["referrer"] );
$From = "From: " . stripcslashes ( $Data["txt_mail"] );
$Headers = trim ( $From . "\n" );

/* Send the email using the SMTP mail() */
mail ( $To, $Subject, $Msg, $Headers );
}
%>

mikeyzc
08-13-2003, 11:31 AM
Originally posted by pyro
You referenced the session wrong in form.php. Try this one:

function send_mail ( $Data )
{
session_start(); #start the session
/* Collect the email data here */
$To = "mcalcagno@antekhealthware.com";
$Subject = "***DAQbilling Evaluation Request***";
$Msg = stripcslashes ( "Contact Name: " . $Data["txt_name"] . "\n" .
"Facility Name: " . $Data["txt_facname"] . "\n" .
"Address #1: " . $Data["txt_address"] . "\n" .
"Address #2: " . $Data["txt_address2"] . "\n" .
"City: " . $Data["txt_city"] . "\n" .
"State: " . $Data["txt_state"] . "\n" .
"Zipcode: " . $Data["txt_zip"] . "\n" .
"Phone Number: " . $Data["txt_phone"] . "\n" .
"Hours of Operation: " . $Data["txt_hours"] . "\n" .
"Best time to contact: " . $Data["txt_contact"] . "\n" .
"Billing currently completed by (In-house staff or billing service)? " . $Data["txt_staff"] . "\n" .
"Does any of your billing staff work from home? " . $Data["txt_home"] . "\n" .
"FullTime Providers: " . $Data["txt_fulltime"] . "\n" .
"PartTime Providers: " . $Data["txt_parttime"] . "\n" .
"Number of locations: " . $Data["txt_locations"]. "\n" .
"Average patients per day per provider? " . $Data["txt_average"] . "\n" .
"Percentage of Medicare Patients in your practice? " . $Data["txt_percentage"]. "\n" .
"Email Address: " . $Data["txt_mail"] . "\n" .
"Questions or Comments: " . $Data["txt_comments"] . "\n" .
"Referral Code: " . $_SESSION["referrer"] );
$From = "From: " . stripcslashes ( $Data["txt_mail"] );
$Headers = trim ( $From . "\n" );

/* Send the email using the SMTP mail() */
mail ( $To, $Subject, $Msg, $Headers );
}
%>

I already tried that. I figured I'd try $Data since the other did not work.

pyro
08-13-2003, 11:35 AM
Try a simple test page:

<?PHP
session_start();
echo $_SESSION["referrer"];
?>See if that will return the value. If not, we know it isn't setting the session.

mikeyzc
08-13-2003, 11:40 AM
Originally posted by pyro
Try a simple test page:

<?PHP
session_start();
echo $_SESSION["referrer"];
?>See if that will return the value. If not, we know it isn't setting the session.

that worked fine

pyro
08-13-2003, 11:48 AM
Hmm... it should be working... Try assigning the sessions variable to a new variable and writing that in:

function send_mail ( $Data )
{
session_start(); #start the session
$referrer = $_SESSION["referrer"];

/* Collect the email data here */
$To = "mcalcagno@antekhealthware.com";
$Subject = "***DAQbilling Evaluation Request***";
$Msg = stripcslashes ( "Contact Name: " . $Data["txt_name"] . "\n" .
"Facility Name: " . $Data["txt_facname"] . "\n" .
"Address #1: " . $Data["txt_address"] . "\n" .
"Address #2: " . $Data["txt_address2"] . "\n" .
"City: " . $Data["txt_city"] . "\n" .
"State: " . $Data["txt_state"] . "\n" .
"Zipcode: " . $Data["txt_zip"] . "\n" .
"Phone Number: " . $Data["txt_phone"] . "\n" .
"Hours of Operation: " . $Data["txt_hours"] . "\n" .
"Best time to contact: " . $Data["txt_contact"] . "\n" .
"Billing currently completed by (In-house staff or billing service)? " . $Data["txt_staff"] . "\n" .
"Does any of your billing staff work from home? " . $Data["txt_home"] . "\n" .
"FullTime Providers: " . $Data["txt_fulltime"] . "\n" .
"PartTime Providers: " . $Data["txt_parttime"] . "\n" .
"Number of locations: " . $Data["txt_locations"]. "\n" .
"Average patients per day per provider? " . $Data["txt_average"] . "\n" .
"Percentage of Medicare Patients in your practice? " . $Data["txt_percentage"]. "\n" .
"Email Address: " . $Data["txt_mail"] . "\n" .
"Questions or Comments: " . $Data["txt_comments"] . "\n" .
"Referral Code: " . $referrer );
$From = "From: " . stripcslashes ( $Data["txt_mail"] );
$Headers = trim ( $From . "\n" );

/* Send the email using the SMTP mail() */
mail ( $To, $Subject, $Msg, $Headers );
}Also, you aren't printing any HTML to the screen before the session_start() is called, correct?

mikeyzc
08-13-2003, 12:11 PM
correct. After the mail is sent i print html to the screen.

mikeyzc
08-13-2003, 12:13 PM
the new variable did not work either.

mikeyzc
08-13-2003, 02:00 PM
I think i found the problem. The script that gathers the information and sends the email is running from a different web server than the rest of the webpages. I think the session is being dropped when it gets to the send_mail section. Thank you for all of the help:)

:o