ThemeForest

Passing PHP Variable to Outgoing Link

408 posts
  • Has been a member for 4-5 years
  • Exclusive Author
  • Sold between 1 000 and 5 000 dollars
  • Bought between 100 and 499 items
  • United States
  • Referred between 10 and 49 users
arctic_ark says

hello world, a site im developing requires the ability to put a stored variable into an outgoing link when its clicked. this is for tracking the users that click the links. im new to php so have little idea how this is done, but i do know i will probably need to store a variable for the user who is logged into my site, and then send that variable to the link when its clicked.

so if my link is http://somesite.com/somelink$ref=#USERNAME#

and johndoe is logged into my account and clicks that link, the link turns into

ttp://somesite.com/somelink$ref=johndoe

3 years ago
220 posts
  • Has been a member for 3-4 years
  • Exclusive Author
  • Sold between 1 000 and 5 000 dollars
  • Bought between 10 and 49 items
  • Netherlands
  • Referred between 1 and 9 users
ronn0 says
<?php
$url = “http://somesite.com/somelink?ref=”.$var;
?>
3 years ago
408 posts
  • Has been a member for 4-5 years
  • Exclusive Author
  • Sold between 1 000 and 5 000 dollars
  • Bought between 100 and 499 items
  • United States
  • Referred between 10 and 49 users
arctic_ark says

thanks ron,

so if the $var would be the users name who is logged in, how would I store the username variable in the first place when they first log in?

3 years ago
420 posts
  • Has been a member for 3-4 years
  • Beta Tester
  • Exclusive Author
  • Sold between 1 000 and 5 000 dollars
  • Bought between 10 and 49 items
  • United States
  • Referred between 10 and 49 users
vasilios says

This is what I do for users/logging in:

1. If the username and password match the records in the database, set a cookie that is in the format: username_RANDOM_STRING_OF_CRAZYNESS. 2. Use the username anywhere I want on the site with the following code:

<?php // Assumes that logged_in checks for the user to be logged in.
if (logged_in()) {
     $explode = explode('_', strip_tags(htmlspecialchars($_COOKIE['loggedin'])));
     $username = $explode['0'];
}
?>

Hope that makes sense. :)

3 years ago
408 posts
  • Has been a member for 4-5 years
  • Exclusive Author
  • Sold between 1 000 and 5 000 dollars
  • Bought between 100 and 499 items
  • United States
  • Referred between 10 and 49 users
arctic_ark says

sorta, so i guess i should use cookies to store the username variable. i found a good article on that at http://www.w3schools.com/PHP/php_cookies.asp. my problem is im going to be using this inside a joomla site, so how would i store the cookie on login from a joomla site, im not sure, i will find out though somehow!

i can have the links just go to something like somesite.com/mylink.php that will go to the correct address and put the username var inside of it, but im not sure how to store the variable from within joomla. maybe i need to edit the login code, and make it go to my own link like somesite.com/usercookie.php, and then have usercookie.php store the cookie, then redirect to the user logged in menu. just an idea, im a php infant, just started learning. ill figure it out though. i posted in joomla forums on how to store the cookie but nothing yet.

3 years ago
by
by
by
by
by