Solved: 5 Years ago [How To?] Carrying referral from non-mybb pages to mybb parts.
#1
Solved: 5 Years ago
I've tried to play around with the member referral link:

http://example.com/member.php?action=reg...referrer=1

The non-mybb pages are just simple html. What I'm attempting to do is send someone to:

http://example.com/?referrer=1

They browse to any page they like within site non-mybb and mybb pages and "referrer=1" is remembered across site. If and when the go through registration process during session referrer will show as "admin" or whomever referrer was.

I tried this on example.com homepage:

<?php
// Start the session
session_start();
?>

<?php
// Set session variables
if (empty($_GET)) {
    $_SESSION['mode'] = "referrer";
}else{
    $_SESSION['mode'] = $_GET['mode'];
}
?>


Tried to insert 2nd portion (without php brackets) within mybb index.php, global.php, header, etc. to no avail during registration process.

Am I on right track with above or just wildly off and if so what should I be doing? I chose php because that is the guts of mybb, but would this be better suited for a javascript snippet? That seems like it would open up a whole other host of problems for a novice. It seems like a simple idea to carry over a cookie or variable in browser between different portions of site.

Any help greatly appreciated.
Reply
#2
Solved: 5 Years ago
Try setting a mybb[referrer] cookie (with configured cookie prefix, if any) with the value set to the user ID.
This is set by MyBB from the GET parameters (https://github.com/mybb/mybb/blob/mybb_1....php#L1148), and used at https://github.com/mybb/mybb/blob/mybb_1...r.php#L890.
devilshakerz.com/pgp (DF3A 34D9 A627 42E5 BC6A 6750 1F2F B8AA 28FF E1BC) ▪ keybase.io/devilshakerz
Reply
#3
Solved: 5 Years ago
(2020-01-28, 05:24 PM)Devilshakerz Wrote: Try setting a mybb[referrer] cookie (with configured cookie prefix, if any) with the value set to the user ID.
This is set by MyBB from the GET parameters (https://github.com/mybb/mybb/blob/mybb_1....php#L1148), and used at https://github.com/mybb/mybb/blob/mybb_1...r.php#L890.
Let's see if understood correctly.  I would paste into top of all non-mybb html pages:

<?php
// Start the session
session_start();
?>

...and then underneath 1st link lines 1149-1167,

...next underneath that 2nd link lines 890-929?
Reply
#4
Solved: 5 Years ago
(2020-01-28, 05:36 PM)maqueen Wrote:
(2020-01-28, 05:24 PM)Devilshakerz Wrote: Try setting a mybb[referrer] cookie (with configured cookie prefix, if any) with the value set to the user ID.
This is set by MyBB from the GET parameters (https://github.com/mybb/mybb/blob/mybb_1....php#L1148), and used at https://github.com/mybb/mybb/blob/mybb_1...r.php#L890.
Let's see if understood correctly.  I would paste into top of all non-mybb html pages:

<?php
// Start the session
session_start();
?>

...and then underneath 1st link lines 1149-1167,

...next underneath that 2nd link lines 890-929?

Something like this on non-MyBB pages:
<?php

if (isset($_GET['referrer'])) {
    setcookie('mybb[referrer]', (int)$_GET['referrer']);
}

?>

This cookie should be then recognized on the MyBB registration page (the links may help understand how that happens, if you're more familiar with PHP).
devilshakerz.com/pgp (DF3A 34D9 A627 42E5 BC6A 6750 1F2F B8AA 28FF E1BC) ▪ keybase.io/devilshakerz
Reply
#5
Solved: 5 Years ago
I tried what you wrote above in various combinations with a session starter, without, your code above head, in body, etc. Cookie isn't being set at beginning according to Chrome and FF.
Reply
#6
Solved: 5 Years ago
So the browser doesn't list the cookie on the external page, when ?referrer=X is appended to its URL? Can you share the actual URLs for the file and forum?

session_ functions shouldn't be needed, and it's best to have the PHP code at the beginning of the file and the HTML content after ?>. Make sure they have a .php extension, rather than .html (if you can see PHP code in page source using a web browser, it means it's not being run on the server).
devilshakerz.com/pgp (DF3A 34D9 A627 42E5 BC6A 6750 1F2F B8AA 28FF E1BC) ▪ keybase.io/devilshakerz
Reply
#7
Solved: 5 Years ago
After hours I was literally about to give up.

"Make sure they have a .php extension, rather than .html (if you can see PHP code in page source using a web browser, it means it's not being run on the server). "

This:

<?php

if (isset($_GET['referrer'])) {
setcookie('mybb[referrer]', (int)$_GET['referrer']);
}

?>

AND THIS (is/was key)

Changing original site index.html to index.php...

Works like a charm across all pages now!

Thank you.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)