Jump to content

Get URL to automatically paste username into referral box?


Bfghost

Recommended Posts

Basically, I need to build a referral link/URL that puts the referral name in the referral box at the registration page.

What I want is to have a URL that looks like http://.../register.php/?ref=xxxxx  where xxxxx automatically is inserted into the referral box on the registration page. What I don't know is how the URL ending part (e.g. ?ref=xxxx) should be formatted for the xxxx part to be automatically pasted into the referral box, and if any changes have to be made in the code for it to be possible. :)

 

Here's the code for the registration page:

<?php
$ref_title = "Register Free";
if($set['recaptcha_enabled'])
{
require_once('modules/recaptcha/recaptchalib.php');
}

$tok_id = sha1(md5(session_id()));

if($_COOKIE['tref'])
{
$ref = $_COOKIE['tref'];
} else {
$ref = $do->get_r_file_url();
$ref = str_replace(array(".html", "/"), "", $ref);
if(eregi('.php', $ref)) { $ref=false; }

setcookie("tref", $ref, time()+60*300);
}

if($loggedin)
{
$error = "You are already logged in.";
$show_login=0;
} elseif($_POST)
{
$username = $do->filter($_POST[1]);
$password = $do->filter($_POST[2]);
$confirm_password = $do->filter($_POST[3]);
$email = $do->filter($_POST[4]);
$alertpay = $do->filter($_POST[5]);
$referral = $do->filter($_POST[6]);
$country = $do->filter($_POST[7]);

if($referral != "") {
$sql = mysql_query("SELECT * FROM users WHERE username='{$referral}'");
$sql = mysql_fetch_array($sql);
$membership = $sql['upgname'];
$drefs = mysql_query("SELECT * FROM users WHERE upline='{$referral}' AND uplinetype<2");
$drefs = mysql_num_rows($drefs);
$mbrshp = mysql_query("SELECT dreflimit FROM upg_options WHERE uo_name='{$membership}'");
$mbrshp = mysql_fetch_array($mbrshp);
$dreflimit = $mbrshp['dreflimit'];

if($membership == "Standard") {
    $dreflimit = $set['stddreflimit'];
}
}

if($set['recaptcha_enabled'])
{
# the response from reCAPTCHA
$resp = null;
# the error code from reCAPTCHA, if any
$error = null;

# was there a reCAPTCHA response?
if ($_POST["recaptcha_response_field"]) {
        $resp = recaptcha_check_answer ($set['recaptcha_privatekey'],
                                        $_SERVER["REMOTE_ADDR"],
                                        $_POST["recaptcha_challenge_field"],
                                        $_POST["recaptcha_response_field"]);

        if (!$resp->is_valid) {
$error=(!$error) ? "You entered an invalid captcha code." : $error;
$show_login=1;
        }
} else {
$error=(!$error) ? "You entered an invalid captcha code." : $error;
$show_login=1;
}
} 

if($_POST["token"] !=$tok_id)
{
$error = "Your token session has expired, please re-enter this form again to continue.";
$show_page = 1;
}
if(!$username)
{
$error = "You forgot to fill in your username.";
$show_page = 1;
}
if(!$password)
{
$error = (!$error) ? "You forgot to fill in your password." : $error;
$show_page = 1;
}
if(!$confirm_password)
{
$error = (!$error) ? "You forgot to fill in your password again." : $error;
$show_page = 1;
}
if(!$email)
{
$error = (!$error) ? "You forgot to fill in your email." : $error;
$show_page = 1;
}
if(!$alertpay)
{
$error = (!$error) ? "You forgot to fill in your payment email." : $error;
$show_page = 1;
}
if($password != $confirm_password)
{
$error = (!$error) ? "Your passwords don't match, try again." : $error;
$show_page = 1;
}
if(strlen($password) < 6)
{
$error = (!$error) ? "Your password must be at least 6 characters." : $error;
$show_page = 1;
}
if(strlen($username) < 3)
{
$error = (!$error) ? "Your username must be at least 3 characters." : $error;
$show_page = 1;
}
if(strlen($username) > 16)
{
$error = (!$error) ? "Your username cannot exceed 16 characters." : $error;
$show_page = 1;
}
if(!eregi('@', $email) or !eregi('.', $email))
{
$error = (!$error) ? "Your email address is invalid, try again." : $error;
$show_page = 1;
}
if(!eregi('@', $alertpay) or !eregi('.', $alertpay))
{
$error = (!$error) ? "Your payment email address is invalid, try again." : $error;
$show_page = 1;
}
$test = "abcdefghijklmnopqrstuvwxyz123456789";
$text =  str_split($password);
for($i=0;$i<strlen($password);$i++) {    
    if(strpos($test, strtolower($text[$i])) <= 0 && strtolower($text[$i]) != "a") {
        $err = 1;
    }
}
if($err) {
$error = (!$error) ? "Your password must be alphanumeric characters A-Z and/or 0-9." : $error;
$show_page = 1;
}    
if($do->request_exceed($gc))
{
$error = (!$error) ? "Only one request every 30 seconds, next request in ".($do->show_request_left($gc))." seconds." : $error;
$show_page = 1;
} else {
$do->start_request_control($gc);
}
if($referral != "") {
if($drefs >= $dreflimit)
{
    $error = (!$error) ? "I'm sorry, this user has reached his/her direct referral limit. Please either register under a different upline or register under no upline." : $error;
    $show_page = 1;
}
}
if(!$error)
{
$pq = mysql_query("SELECT COUNT(*) AS cnt FROM users WHERE username='$username' OR email='$email' LIMIT 1;");
$pq = mysql_fetch_array($pq);
$pq = $pq['cnt'];

if($pq)
{
$error = (!$error) ? "Your username and/or email is already in use, please pick another." : $error;
$show_page = 1;
}


$pq2 = mysql_query("SELECT COUNT(*) AS cnt FROM users WHERE lastip='{$_SERVER['REMOTE_ADDR']}' LIMIT 1;");
$pq2 = mysql_fetch_array($pq2);
$pq2 = $pq2['cnt'];

if($pq2)
{
$error = (!$error) ? "You're IP is already being used so you're not permitted to signup again." : $error;
$show_page = 1;
}

if(strlen($referral) > 1)
{
$refex = mysql_query("SELECT COUNT(*) AS cnt FROM users WHERE username='$referral' LIMIT 1;");
$refex = mysql_fetch_array($refex);
$refex = $refex['cnt'];

if(!$refex)
{
$error = (!$error) ? "A user with that referral name doesn't currently exist." : $error;
$show_page = 1;
}
}
}
if($set['pcaptcha']) {
if( strtolower($_POST['code'])!= strtolower($_SESSION['texto'])){ 
$error=(!$error) ? "You entered an invalid captcha." : $error;
$show_page = 1;
}
}
if(!$error)
{
$encoded_password = sha1($password);

if($do->new_user($username, $encoded_password, $email, $alertpay, $referral, $country, $c))
{
$contents .= "    <div id='box2'>
        <div id='lb'>
            <div id='rb'>
                <div id='bb'>
                    <div id='blc'>
                        <div id='brc'>
                            <div id='tb'>
                                <div id='tlc'>
                                    <div id='trc'>        
                                        <div id='content'><h3>Congratulations</h3>
<p>Your newly created account has been made and you are free to login into your account at any time.</p>
<p>When logging into your account you can read our Getting Started guide.</p>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>";
mysql_query("INSERT INTO history (username,type,time,custom1,custom2,custom3,custom4,custom5) VALUES ('{$username}','joined',unix_timestamp(),'0','0','0','0','0')") or die(mysql_error());
mysql_query("UPDATE stats SET users = users + '1'");
$show_page=0;
} else {
$error = (!$error) ? "There was a problem creating your account, please contact the administrator to resolve the problem." : $error;
$show_page = 1;
}

}

} else {
$show_page = 1;
}

if($error)
{
$contents .= "<div class='err'>$error</div>";
}
if($show_page)
{
if($set['recaptcha_enabled'])
{
$recaptcha = recaptcha_get_html($set['recaptcha_publickey'], $error);
}
if(!$ref) { $ref=$_POST[6]; }

$ip = $_SERVER['REMOTE_ADDR'];
$ip_number = sprintf("%u", ip2long($ip));

$country_query  = "SELECT cntry,country FROM ip2country WHERE ip_from<=$ip_number AND ip_to>=$ip_number";

$country_exec = mysql_query($country_query);

$ccode_array=mysql_fetch_array($country_exec);

$country_code=$ccode_array['cntry'];

$country_name=$ccode_array['country'];

$contents .= "
    <div id='box9'>
        <div id='lb'>
            <div id='rb'>
                <div id='bb'>
                    <div id='blc'>
                        <div id='brc'>
                            <div id='tb'>
                                <div id='tlc'>
                                    <div id='trc'>        
                                        <div id='content'>
<table>
    <tr>";
    if($ref) {
        $contents .= "<td><img src='../themes/GeN3/images/newdref.png' align='center'></td>";
    }else{
        $contents .= "<td><img src='themes/GeN3/images/newdref.png' align='center'></td>";
    }
    $contents .= "<td><h3><font color='black'>Register</font></h3></td>
    </tr>
</table>
<br /><br />
<form method='post'>
<input type='hidden' name='token' value='{$tok_id}'>
<table>
    <tr>
        <td>Username:</td>
        <td><input type='text' name='1' id='username' value='{$username}' class='input'></label></td>
    </tr>
    <tr>
        <td>Password:</td>
        <td><input id='password' type='password' name='2' value='' class='input'></td>
    </tr>
    <tr>
        <td colspan='2'><small>Your password must be alphanumeric characters A-Z and/or 0-9.</small></td>
    </tr>
    <tr>
        <td>Confirm Password:</td>
        <td><input id='cpassword' type='password' name='3' value='' class='input'></td>
    </tr>
    <tr>
        <td>Email Address:</td>
        <td><input id='email' type='text' name='4' value='{$email}' class='input'></td>
    </tr>
    <tr>
        <td>Alertpay Address:</td>
        <td><input id='alertpay' type='text' name='5' value='{$alertpay}' class='input'></td>
    </tr>
    <tr>
        <td>Referral (optional):</td>
        <td><input id='referral' type='text' name='6' value='{$ref}' class='input'></td>
    </tr>
    <tr>
        <td>Detected Country:</td>
        <td>{$country_name}</td>
    </tr>";
if($set['pcaptcha']) {
$contents .= "
<tr><td> </td></tr>
<tr>
    <td colspan='2' align='center'>
        <table style='border-top: 1px solid #000000; border-bottom: 1px solid #000000;'>
            <tr>
                <td>Type the letters you see below:</td>
            </tr>
            <tr>";
if($ref) {
        $contents .= "<td><img src='../image.php?$res' /></td>";
    }else {
        $contents .= "<td><img src='image.php?$res' /></td>";
    }
}
$contents .="<td><input type='text' size='3' maxlength='3' name='code' autocomplete='off' class='securitycode' value=''></td></tr></table></tr>";
if($set['recaptcha_enabled']) {
$contents .= "
<tr>
    <td colspan='2'>{$recaptcha}</td>
</tr>";
}
$contents .= "
<input type='hidden' name='7' value='{$country_name}'>
<tr>
    <td align='center'><br /><br /><input type='submit' value='Register Account'></td>
</tr>
</form>
</table>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>";

}
?> 

 

This should be the part I'm interested in:

<tr>
        <td>Referral (optional):</td>
        <td><input id='referral' type='text' name='6' value='{$ref}' class='input'></td>
    </tr>  

Link to comment
Share on other sites

If I put it in place I get this error:

Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in /......../register.php  on line 330

 

It looks like this:

<tr>
	<td>Referral (optional):</td>
	<td><input type='text' name='referral' value='<?php echo (isset($_GET['href']) && $_GET['href']!='')?$_GET['ref']:""; ?>'></td>
</tr>

Link to comment
Share on other sites

There is really nothing wrong with the syntax. Though that not my prefered method to use an abbreviated conditional.

Try:

<?php

$href='http://this.com';

echo (isset($href) && $href !='')?$href:""; 

?>

You will see that it works.

 

When you see that it works use it in your <input> as shown in the example given prior. But change $href='http...';

to

$href=$_GET['href'];//put it with the other get/post conversions and use just the conditional statement.

 

As to what it is, it is an abbreviated if/else

if (isset($href) && $href !='')

{echo "$href";}

else

{echo "";}

 

statement?output if true:output if false

 

 

HTH

Teamatomic

Link to comment
Share on other sites

Still doesn't work, getting "Parse error: syntax error, unexpected '>' in /home/content/90/5569190/html/themes/GeN3/register.php  on line 319"

<tr>
	<td>Referral:(optional)</td>
	echo "<td><input id='referral' type='text' name='6' value=\"";
	if(isset($_GET['href']) && $_GET['href']!=''){ echo $_GET['href']; }
		echo "\" class='input'></td>";
</tr>

What's wrong.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.