Okay, affiliates are able to sign up. Now, we need to let them log in to their accounts. We'll now create two files for that.
The first file is called "login.php":<?php session_start(); $auid = isset($_POST['auid']) ? $_POST['auid'] : $_SESSION['auid']; $pwd = isset($_POST['pwd']) ? $_POST['pwd'] : $_SESSION['pwd'];
if(!isset($auid)) { loginform(); exit; } $results = mysql_query("SELECT * FROM affiliates WHERE username='{$auid}' && password='{$pwd}'"); $row = mysql_fetch_assoc($results); if($row['username'] == $auid && $row['password'] == $pwd){ $_SESSION['userId'] = $row['ID']; $_SESSION['username'] = $row['username']; $_SESSION['email'] = $row['email']; $_SESSION['akey'] = $row['akey']; }else{ session_destroy(); session_start(); loginform(); exit; } ?> <? function loginform(){ global $sitename; ?> <CENTER> <BR> <FONT FACE=verdana color=#FFFFFF size=5><B><?=$sitename?> Login</B></FONT> <BR> <TABLE cellspacing=0> <FORM method=post> <TR><TD>Username: <TD><INPUT type=text name=auid size=16> <TR><TD>Pass: <TD><INPUT type=pass name=pwd size=16> <TR><TD colspan=2><INPUT type=submit value="Log In >>"></TD> </FORM> </TABLE> <BR> <? } ?>
This file is used to let your affiliates log in to the site. Next, we create a file called "account.php":<? include("common.php"); include("login.php"); include("header.php"); $mode = isset($_REQUEST['mode']) ? $_REQUEST['mode'] : ''; ?> <p>Welcome <?=$_SESSION['username']?><br/> <hr/> <a href='account.php'>Your Account</a> | <a href='account.php?mode=affedit'>Edit Your Profile</a> <br/> <hr/></p> <? if($mode == 'affedit'){ include("affedit.php"); }else{ include("affstats.php"); } include("footer.php"); ?>
This is the main file that your affiliates will use for viewing their stats and updating their account. We now will create two more files as part of this section. The first one is "affstats.php." This file displays the affiliate stats. <p>Your Affiliate Link:<br/> <textarea rows=3 cols=50 wrap=SOFT><?=$siteurl?>/click.php?refid=<?=$_SESSION['akey']?></textarea> <hr/> <? $mystats = AffiliateStats($_SESSION['userId']); if($mystats['clicks'] > 0){ $ratio = number_format( (($mystats['orders'] / $mystats['clicks']) * 100), 2 )." %"; }else{ $ratio = "0 %"; } ?> <b>Your Stats</b><br/></p> <table align=center width=350 border=1> <tr> <td>Total Clicks:</td> <td><?=number_format($mystats['clicks'],0)?> </td> </tr> <tr> <td>Total Orders:</td> <td><?=number_format($mystats['orders'],0)?> </td> </tr> <tr> <td>Ratio %:</td> <td><?=$ratio?> </td> </tr> </table> <br> <table align=center width=350 border=1> <tr> <td>Amount Earned:</td> <td>$<?=number_format($mystats['order_total'],2)?></td> </tr> <tr> <td>Payments Pending:</td> <td>$<?=number_format($mystats['pending_total'],2)?></td> </tr> <tr> <td>Amount Paid:</td> <td>$<?=number_format($mystats['paid_total'],2)?></td> </tr> </table> <hr/>
Next, create a file called "affedit.php." This file lets your affiliates edit their accounts.<? $step = isset($_POST['step']) ? $_POST['step'] : 1; switch ($step){ case '2': AffiliateUpdate($_SESSION['userId']); echo "Your account has been updated<br>"; break; default: $affinfo = mysql_fetch_assoc( mysql_query("SELECT * FROM affiliates WHERE ID='{$_SESSION['userId']}'") ); ?> <table> <form method="POST" action="account.php?mode=affedit"> <input type='hidden' name='step' value='2'> <? foreach($affiliateForm as $field=>$info){ echo "<tr>"; if( !empty($info[0]) ){ echo "<td valign=top>{$info[0]}</td>"; } echo "<td valign=top>"; switch($info[1]){ case "hidden": // hidden variables don't get edited. break; case "password": echo "<input type='password' name='{$field}' value='$affinfo[$field]'>"; break; case "text": echo "<input type='text' name='{$field}' value='{$affinfo[$field]}'>"; break; case "textarea": echo "<textarea name='{$field}' rows=5 cols=25>{$affinfo[$field]}</textarea>"; break; case "select": $info[2] = explode("|",$info[2]); echo "<select name='{$field}'>"; foreach($info[2] as $k=>$v){ if($v == $affinfo[$field]){ echo "<option SELECTED>{$v}</option>"; }else{ echo "<option>{$v}</option>"; } } echo "</select>"; break; } echo "</td>"; echo "</tr>"; } ?> <tr> <td colspan=2><input type='submit' value='Save'></td> </tr> </form> </table> <? break; } ?>
Okay, this is it for the part of the script that handles affiliates managing their accounts. Now, we need to a way to manage affiliates.
Please enable JavaScript to view the comments powered by Disqus. blog comments powered by