The following warnings occurred:
Warning [2] Undefined variable $unreadreports - Line: 26 - File: global.php(961) : eval()'d code PHP 8.1.2-1ubuntu2.14 (Linux)
File Line Function
/global.php(961) : eval()'d code 26 errorHandler->error
/global.php 961 eval
/showthread.php 28 require_once





× This forum is read only. As of July 23, 2019, the UserSpice forums have been closed. To receive support, please join our Discord by clicking here. Thank you!

  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
User refer url
#1
I want registration to my site to be based on refer only, how can i assign a refer url to the member id e.g. mysite.com/users/join.php?refid=2 or any other possible means.

Thanks...
  Reply
#2
It depends on how secure you want it. If you're doing this kind of modification, you're going to want to copy your join form over to the usersc folder.

Change line 24 to
Code:
<?php require_once '../users/init.php'; ?>

This will stop your modifications from getting overwritten by updates.

Ok...now I will give you the simplest possible version...we will use the user_id of an existing user. Note that if you're going to do this one, you might want your user id's to be higher than just 1,2,3. Don't ever change user number 1...just don't use that one for referrals.

To bump up your user ids by default, go into phpmyadmin, click on your database, click the sql, and type
Code:
ALTER TABLE users AUTO_INCREMENT=10000
Hit go. That will start user numbers at 10,000. Then just leave user 1 alone. Maybe delete user 2.

Ok, so back to usersc/join.php
You will make your referral links (note the c) mysite.com/usersc/join.php?refid=10000

Change line 29, which is just
Code:
<?php
to
Code:
<?php $ref = Input::get('refid');
Code:
$check = $db->query("SELECT id FROM users WHERE id = ?",array($ref))->count();
//looking for users with the ref code
Code:
if ($check < 1){Redirect::to('mydomain.com/index.php?err=Sorry.+Invalid+referral+code.');
Code:
}

Now you could get more creative where instead of using the user id, you could generate a random number for each user and put it somewhere in their users table, but this will get you started.


  Reply
#3
Thanks for your reply, the mod works well. But the join page is not opening when acessed from the homepage, i think my initial request was not well phrased.

What happened was that i have added a referby field to the join form and i want the field value to be the username of the member if the page was accessed through the user refer url.

Thank you for your time...
  Reply
#4
Oh. Ok. You can do that too.

Then at the top of your join form you still want

Code:
$ref = Input::get('refid');
Code:
$name = $db->query('SELECT username FROM users WHERE id = ?",array($ref))->first();
Then I would do your form input like this

Code:
<input type="text" class="form-control" name="refid" id="ghome" value="<?=$name->username>">
  Reply
#5
I don't get the implementation well, and having issue with the form.

This is what i did;

on join.php

<pre>
Code:
$ref = Input::get('refid');
$name = $db->query("SELECT username FROM users WHERE id = ?",array($ref))->first();
</pre>


and on _join.php

<pre>
Code:
<label for="refer">Refer by* (If no referee enter "Semilore")</label>
        <input  class="form-control" type="text" name="refer" id="refer" placeholder="Enter Referee Username" value="<?php if (!$form_valid && !empty($_POST)){ echo $refer;} ?>" required >
</pre>


i don't understand this line

Code:
<?=$name-/>username>”></p>            </div><!-- .bbp-reply-content --></div><!-- .reply -->                        </li><!-- .bbp-body -->    <li class=
  Reply
#6
Sorry. The website rendered the html instead of showing it to you. I was missing a code tag....

Then at the top of your join form you still want

Code:
$ref = Input::get('refid');
Code:
$name = $db->query('SELECT username FROM users WHERE id = ?",array($ref))->first();
Then I would do your form input like this

Code:
<input type="text" class="form-control" name="refid" id="ghome" value="<?=$name->username?>">
  Reply
#7
Thank you for your time, it all works well now.

The issue am having now was when the page was accessed directly without the refid url (e.g. /users/join.php) the page is showing the following error;

1) Notice: Undefined offset: 0 in C:\xampp\htdocs\semilore\users\classes\DB.php on line 155

DB.php line 155 has `public function first(){
return $this->results()[0];
}`

2) <br /><b>Notice</b>: Trying to get property of non-object in <b>C:\xampp\htdocs\semilore\users\views\_join.php</b> on line <b>50</b><br />

line 50 has
Code:
<input class="form-control" type="text" name="refer" id="refer" placeholder="Enter Referee Username" value="<?=$name->username?>" required >

Please how can i resolve that?
  Reply
#8
Ok. That makes sense. I will show you what to change and why it will help.

//I was assuming the user id was valid. Let's not do that.
Code:
$name = $db->query('SELECT username FROM users WHERE id = ?",array($ref))->first();
to

//make the query by itself
Code:
$nameQ = $db->query('SELECT username FROM users WHERE id = ?",array($ref));
//see if there are any results
Code:
$nameC = $nameQ->count();

if there are, grab the first (only) one
Code:
if($nameC > 0){
Code:
$name = $nameQ->first();
Code:
}

//Now, change the logic in your input class to only put in the value if there was one found when searching
//I'm going to share this as a pastebin link so I can space it out better without it being confusing.
https://pastebin.com/2CqLUa0F

If that isn't right, it's pretty close. I may have concatenated something wrong off the top of my head, but it's pretty close.
  Reply
#9
Thank you so much, its all good now, i really appreciate your effort.

The input field from pastebin.com was given me a syntax error but while i was try possible means i arrived at

<input class="form-control" type="text" name="refer" id="refer" <?php if($nameC < 1){echo "placeholder='Enter Referee Username'";} else{echo "value=$name->username";} ?> required >

and it works well, hope its all correct.
  Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)