Hey guys,
I'm slowly trying to learn some php, I can mostly just follow along tutorials, as I haven't been able to memorize a lot of the rules and things yet.
I'd like to have a way for people to refer other people to fill out this form on my site.
Basically how I plan for it to work, is a user enters their info into the form, submits it, info is appended to csv file. I open csv file and assign a unique id # based on the position in the csv file. Then I'd like them to be able to refer other users based on that id #. And if someone fills out the form using that other person's referral id #, it records that on the csv file.
So I have some questions with going about this...
Lets say someone's referral id # is 123. Can I give them a link that says mysite.com/apply.php?refid=123 and then insert the code below into /apply.php, or is there another step?
Code:
<?php session_start();
// See if a refid is being given in the URL
if (strlen($_GET['refid']) > 0) {
$refid = $_GET['refid'];
}
// If there is no refid in the URL, check the session
elseif (strlen($_SESSION['refid']) > 0) {
$refid = $_SESSION['refid'];
}
// Write the current refid to the session.
// Now, if the user strays away, the session will be checked for the most recent refid
$_SESSION['refid'] = $refid;
// Echo an <input> tag for the refid, for the registration form
echo '<input type="hidden" name="refid" value="' . htmlspecialchars($refid) . '" />';
}
?>
So what the code above should accomplish is:
If there is a ref id # in the URL, record it in an invisible field on the form and add the ref id # to a session cookie.
If there is no ref id # in the URL, check if there is a session cookie with a ref id #
If there is no ref id # in the URL or session, don't add any input.
If there is a ref id # in the session, record it in an invisible field on the form.
Does the code accomplish those things? And are there any problems with the way the codes written?
If there is a ref id # in the session, record it in an invisible field on the form.
Looks like that isn't done, but why do you need it?????
You are concentrating on the referrer, why? he is not on your site nor is he doing anything on your site at present. It's the current user you need to track. Especially if you have things she can or should do on the site.
When the new user fills out the form he enters or does not enter a referrer's number. You should write all form info to the file immediately, including the referrer number. That's all you need.
P.S. This is just for your information:
Learn how PHP talks to MySQL (a database) or one of your choosing. It's simple and you can get info from it much easier then a cvs file.
I'm starting an online advertising network.
I want to be able to reward people for referring others to my network.
So lets say user1 signs up, gets their refid #, then posts it on their website.
user2 follows that link, and check out my site. closes it out, leaves the computer, and comes back later in the day and signs up.
I don't want user2 to have to fill in user1's refid #.
I'd like user1's refid # to be sent to the csv file with the rest of the form automatically.
I'm not sure why the code above isn't accomplishing that
Could you help me out? Or tell me if I'm confused with something.
I think integrating mysql is a little beyond my level right now. But in the future as I learn more I may try it out.
And its throwing up this error: Warning: Cannot modify header information - headers already sent by (output started at /home/vvm/public_html/publishers/apply/index.php:18) in /home/vvm/public_html/publishers/apply/index.php on line 84
If user2 goes to your site because of a link on user1's web site and leaves you have no information on him. How are you going to know when he comes back? Do you have a login page? Is there anyway you can store his info if he(user2) does not fill out the form.
If you log everyone that comes to your site from user1 that file will get large and how do you know when to delete them?
Say user2 comes in from user1 and leaves; comes back 5 times over a three month period and then fills out the form. See what I mean?
I think you can reward user1 when a person follows his link to your page and you can give out bigger rewards if user2 fills in the form at that time, but keeping records on people that enter via a link and tying them to that link will get out of hand.
FYI
Session variables are destroyed when a session ends or times out.
Before starting an online advertising network learn how to use a database!!
@Sunfighter I want it to save the session info (refid) for a limited amount of time. I was under the impression that the session ID would expire when the person closes their browser or clears their history?
All I want is if user2 follows user1's link, and user2 fills out the form, then user1's refid is appended to the entry into the csv file.
And if user2 views a different page on my site right after following user1's link, it should store user1's refid for a short time so if user2 goes back to the form and fills it out, it still adds user1's refid.
I tried editing my code some, but I'm getting this error still:
PHP Warning: Cannot modify header information - headers already sent by (output started at /home/vvm/public_html/publishers/apply/index.php:21) in /home/vvm/public_html/publishers/apply/index.php on line 88
Also, can anyone help me in deleting the commas, enters, =, -, and other special characters that users can enter that ruin csv files?
First let me ask you a question, does the site your putting this on give you access to mysql?
If user2 comes into your site with address that ends in ?refid=123 or some other number this code checks it and sets a cookie OR it see if as cookie exists and if yes reads it and puts into a session variable.
}else if(isset($_COOKIE["njfailREWARDsystem"])){ $value = $_COOKIE["njfailREWARDsystem"]; $_SESSION["rewards"] = $value; echo $_SESSION["rewards"]; // ONLY here for show } ?>
You should be having trouble with the code you published
, are you?
Last edited by sunfighter; 01-31-2013 at 09:52 PM..
Yes, I do have access to mysql, though I'm not too familiar with mysql.
I figured the csv file would be simpler, and at least be functional until I can develop a better solution.
Yes, I am having trouble with the code I published
Could you help me with integrating your cookie script into my code so its functional?
Your input checking just looks to see if the user entered something and not what he entered. You should spend some time on the internet looking up evaluating forms. Lots out there. It's also where you eliminate the commas, enters, =, -, and other special characters that your having problems with. Some of this uses Regex which is hard to master, but easy to copy/paste.
if(empty($_POST['publishername']))
{
$errorMessage .= "<li>Please enter your name in the field below.</li>";
}
if(empty($_POST['publisheremail']))
{
$errorMessage .= "<li>Please enter your email in the field below.</li>";
}
if(empty($_POST['websitename']))
{
$errorMessage .= "<li>Please enter a name for your website.</li>";
}
if(empty($_POST['websiteurl']))
{
$errorMessage .= "<li>Please enter your website's URL.</li>";
}
if(empty($_POST['uniqueviews']))
{
$errorMessage .= "<li>Please enter an estimate of your website's monthly unique views.</li>";
}
if(empty($_POST['rawviews']))
{
$errorMessage .= "<li>Please enter an estimate of your website's monthly raw impressions.</li>";
}
if(empty($_POST['websitedescription']))
{
$errorMessage .= "<li>Please enter a description for your website.</li>";
}
//define the receiver of the email
$to = $_POST['publisheremail'];
//define the subject of the email
$subject = 'ValueViewMedia Application Confirmation';
//define the message to be sent. Each line should be separated with \n
$message = $_POST['publishername']. ",\n\nThank you for applying to become a ValueViewMedia publisher!\nWe will review your application, and contact you with the results within 48 hours.\n\nThank you,\nValueViewMedia";
//define the headers we want passed. Note that they are separated with \r\n
$headers = "From: publishers@valueviewmedia.com\r\nReply-To: publishers@valueviewmedia.com";
//send the email
$mail_sent = @mail( $to, $subject, $message, $headers );
<body>
<div id="headerWrapper">
<div id="header">
<div id="networkname">
<h1><a href="/"><img alt="ValueViewMedia" src="/valueviewmedia.png"></a></h1>
</div>
<nav class="topbar" id="usernav">
<ul>
<li class="menu"><a class="menu" name="Settings" title="Log in to your ValueViewMedia Publisher or Advertiser account." href="http://manage.valueviewmedia.com/">Log in</a></li>
<li><a title="Talk with a support representative." href="/contactus/">Contact Us</a></li>
</ul>
</nav>
</div>
</div>
<div class="navtabsWrapper">
<nav id="navtabs">
<ul>
<li id="tab-dashboard"><a title="Home Page." href="/">Home</a></li>
<li id="tab-campaigns" class="selected"><a title="Information on becoming a ValueViewMedia Publisher." href="/publishers/">Publishers</a></li>
<li id="tab-sites"><a title="Learn about advertising on the ValueViewMedia network." href="/advertisers/">Advertisers</a></li>
</ul>
</nav>
</div>
<div class="imageNavContainer">
</div>
<div id="maincontent">
<div class="contentHeader">
<h2>Publisher Application</h2>
</div>
<div class="applicationcontainer">
<?php
if(!empty($errorMessage))
{
echo("<div class='errormessages'>\n");
echo("<p>There was an error with your application:</p>\n");
echo("<ul>" . $errorMessage . "</ul>\n");
echo("</div>\n");
}
?>
<form id="form" name="form" method="post" action="#">
<input type="hidden" name="msoft" value="junk">
<h1>Please fill out the form below.</h1>
<p>After you submit this form, a ValueViewMedia representative will review your website(s), and email you within 48 hours to discuss the results and help you get started with our network.</p>
<label>Full Name<br>
<span class="small">First Name Last Name</span>
</label>
<input type="text" name="publishername" id="publishername" /><br><br>
<label>Email Address<br>
<span class="small">This is how we will contact you</span>
</label>
<input type="text" name="publisheremail" id="publisheremail" /><br><br>
<label>Company Name<br>
<span class="small">Leave blank if you are not representing a company</span>
</label>
<input type="text" name="publishercompanyname" id="publishercompanyname" /><br><br>
<label>Website Name<br>
<span class="small">Title of your website</span>
</label>
<input type="text" name="websitename" id="websitename" /><br><br>
<div class="helpicon">
<div class="help">
<img src="/help.png">
<div>
This information will not be used to market your site, so please do not load it with keywords.<br>
If you have multiple sites, you can separate the titles using a backslash /.
</div>
</div>
</div>
<div class="helpicon">
<div class="help">
<img src="/help.png">
<div>
If you have multiple websites, you can separate them using a backslash /.
Example: http://example.com / http://other.com
</div>
</div>
</div>
<label>Unique Visitors Per Month<br>
<span class="small">Your average unique views</span>
</label>
<input type="text" name="uniqueviews" id="uniqueviews"><br><br>
<div class="helpicon">
<div class="help">
<img src="/help.png">
<div>
If you have multiple websites, please list your site's URL and then the views for that site. Then list your next website's URL and list the views for that site. Example: example.com 22000 other.com 15000
</div>
</div>
</div><br>
<label>Raw Impressions Per Month<br>
<span class="small">Your average overall impressions per month</span>
</label>
<input type="text" name="rawviews" id="rawviews"><br><br>
<label>Website Description<br>
<span class="small">Describe your website to us</span>
</label><br>
<textarea rows="5" cols="50" name="websitedescription" id="websitedescription"></textarea>
If you call the form page like this http://www.formpage.php?refid=235
Then you have an id of 235 and that should be written to the file. If you click on the page or call it with http://www.formpage.php then you did not come from a referencer page and there is no ID.
If you go to the page from example.com/apply/index.php?refid=123
And you fill out the form, it will not record refid 123.
However, if you go to example.com/apply/index.php?refid=123
And then leave the page, and then go back to example.com/apply
Then it will record refid 123 in the csv when you submit the form.
I'm not sure why its working like that, is there something I missed?
I tried adding this code below to the form, and adding $refid to the list of fwrite
but it did not change anything.
if(empty($_POST['publishername'])) { $errorMessage .= "<li>Please enter your name in the field below.</li>"; } if(empty($_POST['publisheremail'])) { $errorMessage .= "<li>Please enter your email in the field below.</li>"; } if(empty($_POST['websitename'])) { $errorMessage .= "<li>Please enter a name for your website.</li>"; } if(empty($_POST['websiteurl'])) { $errorMessage .= "<li>Please enter your website's URL.</li>"; } if(empty($_POST['uniqueviews'])) { $errorMessage .= "<li>Please enter an estimate of your website's monthly unique views.</li>"; } if(empty($_POST['rawviews'])) { $errorMessage .= "<li>Please enter an estimate of your website's monthly raw impressions.</li>"; } if(empty($_POST['websitedescription'])) { $errorMessage .= "<li>Please enter a description for your website.</li>"; }
//define the receiver of the email $to = $_POST['publisheremail']; //define the subject of the email $subject = 'ValueViewMedia Application Confirmation'; //define the message to be sent. Each line should be separated with \n $message = $_POST['publishername']. ",\n\nThank you for applying to become a ValueViewMedia publisher!\nWe will review your application, and contact you with the results within 48 hours.\n\nThank you,\nValueViewMedia"; //define the headers we want passed. Note that they are separated with \r\n $headers = "From: publishers@valueviewmedia.com\r\nReply-To: publishers@valueviewmedia.com"; //send the email $mail_sent = @mail( $to, $subject, $message, $headers );
Also I looked up Regex like you suggested
Do you think this code would remove everything except letters numbers _ and -
I think those are all the important characters.
Could you tell me where in my code I should place this?
njfail there is no need to continue this on the forms. I sent you email through the site it's in your "USERCP" The tag to get there is located at the top of the page. Mail sent this PM.