/    Sign up×
Community /Pin to ProfileBookmark

php referral program

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.

to post a comment
PHP

24 Comments(s)

Copy linkTweet thisAlerts:
@brendandonhueAug 12.2003 — 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']
Copy linkTweet thisAlerts:
@pyroAug 12.2003 — And then read up on [URL=http://us4.php.net/manual/en/ref.session.php]sessions[/URL] 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.
Copy linkTweet thisAlerts:
@mikeyzcauthorAug 12.2003 — so I would have to write the referrer=oursite.com to a session
Copy linkTweet thisAlerts:
@pyroAug 12.2003 — Yes, I would do something like this: (it will set the value of referrer to the session [oursite.com])

[code=php]<?php
session_start();
#use $HTTP_SESSION_VARS with PHP 4.0.6 or less
$_SESSION['referrer'] = $_GET["referrer"];
?>[/code]
Copy linkTweet thisAlerts:
@mikeyzcauthorAug 12.2003 — thanks for the help! you made it pretty easy to understand for a newbie like myself ?
Copy linkTweet thisAlerts:
@pyroAug 12.2003 — Happy to help, as always. ?
Copy linkTweet thisAlerts:
@mikeyzcauthorAug 13.2003 — 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.


[size=1][code=php]function send_mail ( $Data )
{
/* Collect the email data here */
$To = "[email protected]";
$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 );
}
%>[/code]
[/size]
Copy linkTweet thisAlerts:
@pyroAug 13.2003 — 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"])
Copy linkTweet thisAlerts:
@mikeyzcauthorAug 13.2003 — [i]Originally posted by pyro [/i]

[B]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"]) [/B][/QUOTE]


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

[b]the link to my page from the referring site is:[/b]

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

[b]the index.php page that loads when they click the link has:[/b]
[code=php]
<?php
session_start();
$_SESSION['referrer'] = $_GET["referrer"];

?>[/code]


[b]from there they click a link to a form. the form php contains:[/b]

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

function send_mail ( $Data )
{
/* Collect the email data here */
$To = "[email protected]";
$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 );
}
%>
[/code]



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

?>[/code]
[/b]

on every page?
Copy linkTweet thisAlerts:
@pyroAug 13.2003 — By default, sessions use cookies, so you don't need to pass the sessions variable from page to page.

Also, this code is incorrect:

[code=php]$_SESSION['referrer'] = $_GET["referrer"];[/code]

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.
Copy linkTweet thisAlerts:
@mikeyzcauthorAug 13.2003 — 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.

[size=1][code=php]
function send_mail ( $Data )
{
/* Collect the email data here */
$To = "[email protected]";
$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 );
}
%>[/code]
[/size]
Copy linkTweet thisAlerts:
@pyroAug 13.2003 — You need to insert session_start() before you can read the sessions variable. Try this:

[code=php]function send_mail ( $Data )
{
session_start(); #start the session
/* Collect the email data here */
$To = "[email protected]";
$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 );
}[/code]
Copy linkTweet thisAlerts:
@pyroAug 13.2003 — You need to insert session_start() before you can read the sessions variable. Try this:

[code=php]function send_mail ( $Data )
{
session_start(); #start the session
/* Collect the email data here */
$To = "[email protected]";
$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 );
}[/code]
Copy linkTweet thisAlerts:
@mikeyzcauthorAug 13.2003 — [i]Originally posted by pyro [/i]

[B]You need to insert session_start() before you can read the sessions variable.[/QUOTE]




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.
Copy linkTweet thisAlerts:
@pyroAug 13.2003 — 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?
Copy linkTweet thisAlerts:
@mikeyzcauthorAug 13.2003 — [b]index.php[/b]

[code=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>[/code]


[b]form.php[/b]

[code=php]
function send_mail ( $Data )
{
session_start(); #start the session
/* Collect the email data here */
$To = "[email protected]";
$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 );
}
%>[/code]
Copy linkTweet thisAlerts:
@pyroAug 13.2003 — You referenced the session wrong in form.php. Try this one:

[code=php]function send_mail ( $Data )
{
session_start(); #start the session
/* Collect the email data here */
$To = "[email protected]";
$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 );
}
%>[/code]
Copy linkTweet thisAlerts:
@mikeyzcauthorAug 13.2003 — [i]Originally posted by pyro [/i]

[B]You referenced the session wrong in form.php. Try this one:



[code=php]function send_mail ( $Data )
{
session_start(); #start the session
/* Collect the email data here */
$To = "[email protected]";
$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 );
}
%>[/code]
[/B][/QUOTE]


I already tried that. I figured I'd try $Data since the other did not work.
Copy linkTweet thisAlerts:
@pyroAug 13.2003 — Try a simple test page:

[code=php]<?PHP
session_start();
echo $_SESSION["referrer"];
?>[/code]
See if that will return the value. If not, we know it isn't setting the session.
Copy linkTweet thisAlerts:
@mikeyzcauthorAug 13.2003 — [i]Originally posted by pyro [/i]

[B]Try a simple test page:



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


that worked fine
Copy linkTweet thisAlerts:
@pyroAug 13.2003 — Hmm... it should be working... Try assigning the sessions variable to a new variable and writing that in:

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

/* Collect the email data here */
$To = "[email protected]";
$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 );
}[/code]
Also, you aren't printing any HTML to the screen before the session_start() is called, correct?
Copy linkTweet thisAlerts:
@mikeyzcauthorAug 13.2003 — correct. After the mail is sent i print html to the screen.
Copy linkTweet thisAlerts:
@mikeyzcauthorAug 13.2003 — the new variable did not work either.
Copy linkTweet thisAlerts:
@mikeyzcauthorAug 13.2003 — 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
×

Success!

Help @mikeyzc spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.4,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...