awakedesignstudios Posted August 27, 2009 Share Posted August 27, 2009 hi world, im new to php so bare with me. a site im developing requires the ability to pass a variable to a link when its clicked. what i mean by this is when a link is clicked, php grabs a variable and sticks it in the link, for tracking which user logged into my site clicked the link. Quote Link to comment https://forums.phpfreaks.com/topic/172159-passing-variable-to-outgoing-link/ Share on other sites More sharing options...
ignace Posted August 27, 2009 Share Posted August 27, 2009 print '<a href="http://domain/page.php?user=' . $_SESSION['username'] . '">click</a>'; Quote Link to comment https://forums.phpfreaks.com/topic/172159-passing-variable-to-outgoing-link/#findComment-907723 Share on other sites More sharing options...
awakedesignstudios Posted August 27, 2009 Author Share Posted August 27, 2009 so $_SESSION would be the variable thats storing the username? or username storing the variable, and $_SESSION is inputting it into the link? im new to this php world....somehow i need to store a variable based on the user that is logged in, and pass the user variable into the link when its clicked...so if print '<a href="http://domain/page.php?user=' . $_SESSION['username'] . '">click</a>'; puts the username into the link, how would i store the user variable in the first place? Quote Link to comment https://forums.phpfreaks.com/topic/172159-passing-variable-to-outgoing-link/#findComment-907733 Share on other sites More sharing options...
awakedesignstudios Posted August 27, 2009 Author Share Posted August 27, 2009 what im asking is how should i store the usernames variable in the first place? Quote Link to comment https://forums.phpfreaks.com/topic/172159-passing-variable-to-outgoing-link/#findComment-907740 Share on other sites More sharing options...
ignace Posted August 27, 2009 Share Posted August 27, 2009 $_SESSION['username'] = $_POST['username'] for example Quote Link to comment https://forums.phpfreaks.com/topic/172159-passing-variable-to-outgoing-link/#findComment-907751 Share on other sites More sharing options...
awakedesignstudios Posted August 27, 2009 Author Share Posted August 27, 2009 so use a form? doesnt that mean the very next page has to be the link one? if im going to use the username var on different pages, will POST remember? someone on another forum suggested i use cookies to store the username. im using this in joomla, so i think i have the edit the built in login module to track the username coookie somehow, not sure how yet though. do u know anything about customizing joomla and its extensions? Quote Link to comment https://forums.phpfreaks.com/topic/172159-passing-variable-to-outgoing-link/#findComment-907957 Share on other sites More sharing options...
gamesmstr Posted August 28, 2009 Share Posted August 28, 2009 Session variables stay active in the current session until the session is closed. No need to recall them on every page. Quote Link to comment https://forums.phpfreaks.com/topic/172159-passing-variable-to-outgoing-link/#findComment-907993 Share on other sites More sharing options...
waynew Posted August 28, 2009 Share Posted August 28, 2009 Also, do make sure to sanitize the output of $_SESSION['username'] using htmlentities! Quote Link to comment https://forums.phpfreaks.com/topic/172159-passing-variable-to-outgoing-link/#findComment-908001 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.