PHP - Moved: I'm Looking For A Php Referral System For My Site
This topic has been moved to Miscellaneous.
http://www.phpfreaks.com/forums/index.php?topic=346529.0 Similar Tutorialsdb table username------>id->username->cash->points->referrer
db table referral_levels------>id->level->earnings->signupBonusCash->signupBonusPoints->status
username referrer -------- -------- admin kelly88 admin // UPDATE USERNAME ADMIN WITH referral level 1 POINTS/CASH // jacob kelly88 // UPDATE USERNAME ADMIN WITH referral level 2 POINTS/CASH AND USERNAME kelly88 WITH referral level 1 POINTS/CASH // david16 jacob // UPDATE USERNAME ADMIN WITH referral level 3 POINTS/CASH AND USERNAME kelly88 WITH referral level 2 POINTS/CASH AND USERNAME jacob WITH referral level 1 POINTS/CASH //Is this possible. If yes - HOW? Current test registration code with referral level 1 <?php if(!empty($_GET['ref'])){ $referrerUsername = filter_input(INPUT_GET, 'ref', FILTER_SANITIZE_STRING); if(usernameExist($referrerUsername, $db) === TRUE){ $_SESSION['ref'] = $referrerUsername; } } // define variables with the value for each field // the value from POST,GET if this exist, or an empty value $errors = array(); $username = isset($_POST['username']) ? filter_input(INPUT_POST, 'username', FILTER_SANITIZE_STRING) : ''; $referrer = !empty($_SESSION['ref']) ? $_SESSION['ref'] : (isset($_POST['referrer']) ? filter_input(INPUT_POST, 'referrer', FILTER_SANITIZE_STRING) : ''); if(!empty($_POST['submit'])){ if(empty($username)){ $errors[] = $lang['error']['a_019']; } else if(validUsernameLenght($username) === FALSE){ $errors[] = $lang['error']['a_020']; } else if(validUsernameChars($username) === FALSE){ $errors[] = $lang['error']['a_021']; } else if(usernameExist($username, $db) === TRUE){ $errors[] = $lang['error']['a_022']; } if(!empty($referrer)){ if(usernameExist($referrer, $db) === FALSE){ $errors[] = $lang['error']['a_037']; } else if($username == $referrer){ $errors[] = $lang['error']['a_038']; } } } if(!empty($_POST['submit']) and empty($errors)){ /* $queryOne = 'INSERT INTO users(username, referrer) VALUES (:username, :referrer)'; $insertOne = $db->prepare($queryOne); $insertOne->bindParam(':username', $username, PDO::PARAM_STR); $insertOne->bindParam(':referrer', $referrer, PDO::PARAM_STR); $successOne = $insertOne->execute(); */ if($referrer){ $query = 'SELECT signupBonusCash AS sbc, signupBonusPoints AS sbp FROM referral_levels WHERE level = 1 AND status = "enabled"'; $select = $db->query($query); $row = $select->fetch(PDO::FETCH_ASSOC); $queryTwo = 'UPDATE users SET points = points + :points, cash = cash + :cash WHERE username = :referrer'; $selectTwo = $db->prepare($queryTwo); $selectTwo->bindParam(':cash', $row['sbc'], PDO::PARAM_STR); $selectTwo->bindParam(':points', $row['sbp'], PDO::PARAM_STR); $selectTwo->bindParam(':referrer', $referrer, PDO::PARAM_STR); $selectTwo->execute(); } } if(!empty($errors)){ foreach($errors as $error){ print $error.'<br>'; } } print ' <form method="POST"> <table style="width:100%"> <tr> <td style="width:30%;font-weight:bold">Username</td> <td style="width:70%"><input type="text" name="username" maxlength="255" style="width:200px" value="'.cleanOutput($username).'"></td> </tr>'; if(!empty($_SESSION['ref'])){ print ' <tr> <td style="font-weight:bold">'.$lang['global']['a_047'].'</td> <td><input type="text" name="referrer" readonly="readonly" maxlength="255" style="width:200px" value="'.cleanOutput($referrer).'"></td> </tr>'; }else{ print ' <tr> <td style="font-weight:bold">'.$lang['global']['a_047'].'</td> <td><input type="text" name="referrer" maxlength="255" style="width:200px" value="'.cleanOutput($referrer).'"></td> </tr>'; } print ' <tr> <td colspan="2" style="text-align:center"><input type="submit" name="submit" value="Submit"></td> </tr> </table> </form>'; ?> Hi, I have a fully pledged membership system and want to integrate my own user referral system but want some tips, advice really on the logic of it. Basically already registered users on my site will have the option to refer people, only registered users. I will try to explain my logic and what i have done so far. My current registered users table is something like Quote users (table) - id (user id) - email (user email) - password (hash of users password) - reg_date (date user registered) I have some other fields but not relevant to what I want to do and to keep things as simple as possible I left them out. I am thinking of creating a new table called referrals and for example when a registered user on my site from the users table goes to a member only page called referral.php it will display a form so they can enter an email address of someone they want to refer and it also displays the people they referred. My referral table is like this so far and not sure if it's best way to go about the database logics and php logic. my table so far looks like this: Quote referrals (table) - id (auto incremented every time a new referral (row) is added to referrals table) - referrer_uid (id of referrer, this would be the unique id of a registered user from the users table) - referred_email (email address of person who has been referred) - status (when someone is first referred default will be `referred`, if they signup to site via referral link this will update to `completed`) - created_on (date the referral was made, unix timestamp) - updated_on (date the referred person actually clicks the referral link and completes signup) Currently i added the database table above to my site on local. added some sample data for testing and created a referral.php page where there's a form so a registered member can enter a persons email and refer them to my site to signup. On referral.php there is also the total people they referred and a table showing all the people they referred as follows: Referred Email | Referred Date | Status | Completed On Now so far everything is seems fine. I have my sample (pretend referrals i made) data showing in my test account. The part i am now not sure about is this: Obviously to stop abuse i do my usual validation checks like: check to ensure the email being entered on referrals page does not exist in users table (registered member), check to ensure the email has not already been referred previously (for spam reasons) only allowed to refer an email address once and not allowed to refer someone who has previously been referred by someone else to (again for spam reasons) Now onto the tracking the referral and link building. I was first thinking this: on sign up form have a hidden field. The sign up form would do a simple check to see if isset $_GET['ref'] like signup.php?ref=something_here if it is prefill the hidden field, when user then signs up if the ref=something_here matches what's in the database then update referral to complete so the referrer knows that their friend for example signed up via their referral, unix timestamp of when referred person completed signup. Now i was going to use the email address of referred person or username of person who made the referral signup.php?ref=username or signup.php?ref=referred_email . Now what i am thinking is what would be better and i guess stop random abuse is create another column and call it referred_id; this would be a random md5 hash that is unique to that referral and it will be appended to the url like signup.php?ref=md5_hash_here. So my questions a 1) Is there anything you think i should change, improve on, alter etc ? 2) Do you think i am going about it the rite way or making a mess of it ? 3) Have i left anything out that i may have not thought of that could cause the system to be abused ? Any suggestions, feedback, help on the whole logic would be great. I coded allot of it last night and won't take me long to do the rest but need some help in terms of ensuring i am doing it the best way possible etc, the logic behind it all. Thanks for any suggestions, help, advice, tips! PHPFAN I created a specific Linux user responsible to host a given site, created a postgresql user and database with the same name, and created a pool, and all is good... Almost. How can I make the user a system user (i.e. useradd -r my_user) without a home? Without a home, where should ssh keys go? Anything need to be changed when creating the postgresql user? Thanks Hi friends, I need assistance with making russian fonts displayable in the system emails that are being sent to my auction website users. Any reason the russian fonts I have entered below are displayed the way they are. Please also note I am brand new in PHP and simple llingo would be appreciated. Regards, <? ## Email File -> email an auction to a friend ## called only from the $item->auction_friend() function! ## File Version -> v6.10 if ( !defined('INCLUDED') ) { die("Access Denied"); } //$sender_details = $this->get_sql_row("SELECT u.name, u.email FROM " . DB_PREFIX . "users u WHERE u.user_id='" . $user_id . "'"); $send = true; // always sent; ## text message - editable $text_message = 'Dear %1$s, Your friend, %2$s, has forwarded an auction, posted on %3$s for you to look at. To view the details of the auction, please click on the URL below: %4$s Additional comments: %5%s Best regards, The %6$s staff'; ## html message - editable $html_message = 'Дорогой (ая) %1$s, <br> <br> Ваш друг, %2$s, отправил на Ваше рассмотрение Аукцион, выставленный на %3$s. <br> <br> [ <a href="%4$s">Нажмите здесь</a> ] чтобы просмотреть этот Аукцион. <br> <br> Дополнительные комментарии: %5$s <br> <br> С Уважением, <br> %6$s <br> <br> <br> Dorogoy (aya) %1$s, <br> <br> Vash drug, %2$s, otpravil na Vashe rassmotreniye Auktsion, vistavlenniy na %3$s. <br> <br> [ <a href="%4$s">Najmite zdes</a> ] chtobi prosmotret etot Auktsion. <br> <br> Dopolnitelniye kommentarii: %5$s <br> <br> S Uvajeniyem, <br> %6$s'; $auction_link = process_link('auction_details', array('name' => $item_details['name'], 'auction_id' => $item_details['auction_id'])); $text_message = sprintf($text_message, $friend_name, $sender_name, $this->setts['sitename'], $auction_link, $comments, $this->setts['sitename']); $html_message = sprintf($html_message, $friend_name, $sender_name, $this->setts['sitename'], $auction_link, $comments, $this->setts['sitename']); send_mail($friend_email, 'Проверьте этот Аукцион', $text_message, $this->setts['admin_email'], $html_message, $sender_name, $send); ?> This topic has done the Monster Mash to MySQL Help. http://www.phpfreaks.com/forums/index.php?topic=343718.0 This topic has been moved to Third Party PHP Scripts. http://www.phpfreaks.com/forums/index.php?topic=314868.0 This topic has been moved to Miscellaneous. http://www.phpfreaks.com/forums/index.php?topic=345826.0 This topic has been moved to Miscellaneous. http://www.phpfreaks.com/forums/index.php?topic=314181.0 This topic has been moved to Miscellaneous. http://www.phpfreaks.com/forums/index.php?topic=319007.0 This topic has been moved to Miscellaneous. http://www.phpfreaks.com/forums/index.php?topic=348317.0 This topic has been moved to Third Party PHP Scripts. http://www.phpfreaks.com/forums/index.php?topic=358615.0 This topic has been moved to Ajax Help. http://www.phpfreaks.com/forums/index.php?topic=352279.0 This topic has been moved to Miscellaneous. http://www.phpfreaks.com/forums/index.php?topic=348500.0 This topic has been moved to Third Party PHP Scripts. http://www.phpfreaks.com/forums/index.php?topic=359002.0 This topic has been moved to Application Design. http://www.phpfreaks.com/forums/index.php?topic=313919.0 This topic has been moved to Miscellaneous. http://www.phpfreaks.com/forums/index.php?topic=317096.0 This topic has been moved to Miscellaneous. http://www.phpfreaks.com/forums/index.php?topic=349747.0 Hello friends! I just need the last help to have everything working ok. I'm having an issue because the input won't show the referral ID. Here is the .htaccess code: /*This changes the URL mysite.com/reg.php/referral.html to mysite.com/reg.php?referral*/ Code: [Select] Options +FollowSymlinks RewriteEngine on RewriteRule ^reg.php/(.*)\.html$ http://www.mysite/reg.php?$1 Then the code in the reg.php page: Code: [Select] if($_COOKIE['referido']) { $ref = $_COOKIE['referido']; } else { $ref = $do->get_r_file_url(); $ref = str_replace(array(".html", "/"), "", $ref); if(eregi('.php', $ref)) { $ref=false; } setcookie("referido", $ref, time()+60*60*24*30); } And then the input: <input size='3' style='width:170px;' id='referral' type='hidden' name='6' value='{$ref}' > So how do I do to make the input show the referral ID? Thanks! Hello friends. I'm needing a bit of help with some code. I have this code to show my users their referral link: (this code goes in the reg.php file) Code: [Select] if($_COOKIE['referido']) { $ref = $_COOKIE['referido']; } else { $ref = $do->get_r_file_url(); $ref = str_replace(array(".html", "/"), "", $ref); if(eregi('.php', $ref)) { $ref=false; } setcookie("referido", $ref, time()+60*60*24*30); } And then this one on the user's profile to show their referral URL: Code: [Select] $dp = $do->get_loc()."reg.php/{$signin_username}.html"; So the result is "mysite.com/reg.php/referral.html" and I want it to be "mysite.com/reg.php?referral" I just need to get rid of the "/" I've seen sites like "thesite.com/?r=referral" How can i do something like that? Thanks! In the database, I have a table called 'users' inside that I have email, nick (aka username), and balance. The individual aspects are set up, and work. My site is also successfully connecting to and reading / writing info in the database. So my question is: How would I go about having a box on the register page called 'refer' where the person would enter their referrers email (or nickname, one or the other) then it finds that person, and puts a value of 10 in 'balance'. Anyone with more experience than me have any ideas? All help is greatly appreciated. |