The following warnings occurred: | ||||||||||||
Warning [2] Undefined variable $unreadreports - Line: 26 - File: global.php(961) : eval()'d code PHP 8.2.25 (Linux)
|
User refer url - Printable Version +- UserSpice (https://userspice.com/forums) +-- Forum: Miscellaneous (https://userspice.com/forums/forumdisplay.php?fid=28) +--- Forum: Off-topic Discussions (https://userspice.com/forums/forumdisplay.php?fid=10) +--- Thread: User refer url (/showthread.php?tid=730) |
User refer url - kingnath - 09-08-2017 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... User refer url - mudmin - 09-09-2017 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 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 Code: <?php $ref = Input::get('refid'); Code: $check = $db->query("SELECT id FROM users WHERE id = ?",array($ref))->count(); 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. User refer url - kingnath - 09-10-2017 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... User refer url - mudmin - 09-10-2017 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(); Code: <input type="text" class="form-control" name="refid" id="ghome" value="<?=$name->username>"> User refer url - kingnath - 09-10-2017 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'); and on _join.php <pre> Code: <label for="refer">Refer by* (If no referee enter "Semilore")</label> i don't understand this line Code: <?=$name-/>username>”></p> </div><!-- .bbp-reply-content --></div><!-- .reply --> </li><!-- .bbp-body --> <li class= User refer url - mudmin - 09-10-2017 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(); Code: <input type="text" class="form-control" name="refid" id="ghome" value="<?=$name->username?>"> User refer url - kingnath - 09-10-2017 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? User refer url - mudmin - 09-10-2017 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(); //make the query by itself Code: $nameQ = $db->query('SELECT username FROM users WHERE id = ?",array($ref)); 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. User refer url - kingnath - 09-10-2017 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. |