Register Advertise with usHelp Desk Today's Posts Search

Closed Thread
Thread Tools Search this Thread
Unread 30th Dec 2013, 12:43 PM   #1
Warrior Member
 
Join Date: 2013
Posts: 25
Thanks: 53
Thanked 4 Times in 4 Posts
Default
Simple PHP question that will likely help many
Share on: 
fb share twitter share gplus share more share

I think an answer to this question will likely help many folks on the forum
BTW: I have tried to search the forum and Google long before posting this

My scenario is this:
  • I have built a site Live Smarter Online to promote Auto Recruiting Platform
  • I built it in such a way to help my team members build their own downline
  • I want people from other teams to be able to use it as well
  • I need them to be able to pass their affiliate code to get credit
  • I would like to be able to have aff ids rotate if possible if no one specifically sends their own code
  • I am using WordPress (but I don't think that will make much of a difference)

If you are still with me, thank you. This is difficult to explain in a concise manner.

I am planning to use <? echo $_GET['id'] ?> to insert the promoter's username into all of the links but if someone comes to the site directly, I want to have the link automatically rotate through my downline's usernames, thus helping everyone get more traffic.

I am sure I am not the only person to have thought of this, I just haven't been able to track it down, specifically the rotator aspect.

Does anyone care to take a crack at it?

Thanks in advance!
Mark
LiveSmarterNotHarder is offline  
Unread 30th Dec 2013, 02:11 PM   #2
Warrior Member
 
Join Date: 2013
Posts: 25
Thanks: 53
Thanked 4 Times in 4 Posts
Default
Re: Simple PHP question that will likely help many
Share on: 
fb share twitter share gplus share more share

Maybe this will make the rotator part easier to understand, manage and implement:
  • IF: If someone sends people to the site with their affiliate id, it will ECHO their id in all of the site links
  • For example: http://livesmarteronline.com/?id=<? $_GET['id'] ?>
  • IF NOT: If someone comes to the site via Google or traffic I send to it, the links will all contain a URL from an external rotator program I use
  • For example: http://rotatorurl.tld/r/?rotatorid=1

Something like:

<?php $TEAMMATE = "<? $_GET['id'] ?>"; ?>

which would then allow

<a href="insert domain name here/<?php echo $TEAMMATE; ?>" rel="nofollow" target="_blank">


In other words:

If someone goes to the site via: domain/?id=TEAMMATE all of the links going to the company will give TEAMMATE credit

If someone goes to the site directly (without an affiliate link), the links will all be served up with URL rotator link that will rotate through my team's usernames and helping everyone on my team more traffic than they would have had otherwise = everyone wins!
LiveSmarterNotHarder is offline  
Unread 30th Dec 2013, 02:55 PM   #3
PHP ninja
War Room Member
 
kevbo22's Avatar
 
Join Date: 2011
Location: Denver
Posts: 124
Thanks: 13
Thanked 27 Times in 25 Posts
Default
Re: Simple PHP question that will likely help many
Share on: 
fb share twitter share gplus share more share

<?
if($_GET['id'] > 0) {
$TEAMMATE = $_GET['id'];
}else{
//include your url rotator here
}
?>

The best path to prosperity is free market capitalism!
kevbo22 is offline  
The Following User Says Thank You to kevbo22 For This Useful Post:
Unread 30th Dec 2013, 03:55 PM   #4
Warrior Member
 
Join Date: 2013
Posts: 25
Thanks: 53
Thanked 4 Times in 4 Posts
Default
Re: Simple PHP question that will likely help many
Share on: 
fb share twitter share gplus share more share

Thanks for the quick reply, kevbo22.

I am pretty new to working with PHP so thank you for your patience:

Can you give me an example of how to implement this?

ie:
Is your code to be placed in the HEAD tags?

<?
if($_GET['id'] > 0) {
$TEAMMATE = $_GET['id'];
}else{
//include your url rotator here
URL-ROTATOR dot COM
}
?>

and being as originally my links have been:
"domain dot com/<?php echo $TEAMMATE; ?>"

to allow their ID to convert the links and give them credit, would there be a way to have the links go to:

URL/TEAMMATE link (IF they provided a "?id=TEAMMATE")
OR
ROTATOR URL (IF the reader came to the site directly)

I hope this makes sense.
I truly appreciate your help.
I'm designing this as an effort to "pay it forward" as much as I can.

Thanks,
Mark
LiveSmarterNotHarder is offline  
Unread 30th Dec 2013, 04:26 PM   #5
Advanced Warrior
War Room Member
 
Brandon Tanner's Avatar
 
Join Date: 2006
Location: USA
Posts: 1,907
Thanks: 236
Thanked 1,377 Times in 676 Posts
Default
Re: Simple PHP question that will likely help many
Share on: 
fb share twitter share gplus share more share

I would use isset instead of > 0

<?php
if(isset($_GET['id'])) {
$TEAMMATE = $_GET['id'];
}else{
// rotator code here
}
?>


Also, you should sanitize your $TEAMMATE value before you do anything with it, otherwise you're opening yourself up to all kinds of potentially nasty stuff (XSS attacks, etc). Using htmlspecialchars is a good start, and will protect you from most types of basic attacks.

$TEAMMATE = htmlspecialchars($TEAMMATE, ENT_QUOTES);


As per the rotator part, the easiest way (by far) to do it would be to assign each of your teammate's an ID number, and then rotate through them randomly (which should work out to be fairly even over the long run). For example, if you have 3 teammate's, and their referral ID's are Member1, Member2, Member3, etc., then you can do something like this...

$number = (rand(1,3);
$TEAMMATE = "Member" . $number;
echo $TEAMMATE;


If you'd rather not go the random route, then you would have to keep track of each of your teammate's referral count in either a database or a flat file, then loop through each teammate in the database whenever someone visits the site without an aff link. That would involve a lot more code than the 'random' option though, and I'd definitely recommend hiring someone to code that part if you're new to PHP / MySQL.


Brandon Tanner is offline  
The Following 2 Users Say Thank You to Brandon Tanner For This Useful Post:
Unread 30th Dec 2013, 05:15 PM   #6
Warrior Member
 
Join Date: 2013
Posts: 25
Thanks: 53
Thanked 4 Times in 4 Posts
Default
Re: Simple PHP question that will likely help many
Share on: 
fb share twitter share gplus share more share

Brandon, that sounds great.

To clarify:

<head>
<?php
if(isset($_GET['id'])) {
$TEAMMATE = $_GET['id'];
}else{
//rotator dot com
}
?>
</head>



And the link would be:

<body>

company dot com/<? echo $_GET['id'] ?>

</body>


Not sure yet how to implement the:
$TEAMMATE = htmlspecialchars($TEAMMATE, ENT_QUOTES);
...but I really appreciate you bringing that up
LiveSmarterNotHarder is offline  
Unread 30th Dec 2013, 06:49 PM   #7
Advanced Warrior
War Room Member
 
Brandon Tanner's Avatar
 
Join Date: 2006
Location: USA
Posts: 1,907
Thanks: 236
Thanked 1,377 Times in 676 Posts
Default
Re: Simple PHP question that will likely help many
Share on: 
fb share twitter share gplus share more share

I would put the initial PHP code block very first thing in the document (before the <html> tag). Then you can put the echo code anywhere you need it in the body.

As per how to implement htmlspecialchars, just insert the htmlspecialchars line right after you grab the $TEAMMATE value from $_GET...

<?php
if(isset($_GET['id'])) {
$TEAMMATE = $_GET['id'];

$TEAMMATE = htmlspecialchars($TEAMMATE, ENT_QUOTES);
} else {
// rotator code here
}
?>


Basically, all the htmlspecialchars line does is sanitize (encode) any quotes found in the $TEAMMATE value (because a malicious user would normally need to use quotes to facilitate a XSS attack, yet a legitimate affiliate ID will not normally contain quotes). In the odd case you DO want to be able to use quotes as part of the affiliate ID, then you would simply decode that value whenever you need it (see this).


Brandon Tanner is offline  
The Following User Says Thank You to Brandon Tanner For This Useful Post:
Closed Thread


Bookmarks

Tags
php, question, simple


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off




All times are GMT -6. The time now is 12:27 PM.