steve182 Posted February 25, 2010 Share Posted February 25, 2010 I am working to add a PHP call into the client area to pull info out of the database. I can write the PHP code, but here is where I am having trouble: 1. Obtaining the User Session ID - I am currently using echo "$_SESSION['uid']"; 2. Using this variable to pull a value from the Database When I insert PHP in the header.tpl file it just displays my php code. thanks for any help in advance, I have been racking my brain over this one 0 Quote Link to comment Share on other sites More sharing options...
sparky Posted February 26, 2010 Share Posted February 26, 2010 When using php in a smarty template you need to enclose the php code in these tags {php} ... {/php} In smarty to get the variable you are after use {$smarty.session.uid} 0 Quote Link to comment Share on other sites More sharing options...
steve182 Posted February 26, 2010 Author Share Posted February 26, 2010 When using php in a smarty template you need to enclose the php code in these tags {php} ... {/php} In smarty to get the variable you are after use {$smarty.session.uid} Thanks so much for the response, it is greatly appreciated. I added the code {literal} {php} echo "{$smarty.session.uid}"; {/php} {/literal} To my header.tpl page and the output is {php} echo "{$smarty.session.uid}"; {/php} showing up on my page. I tried it without the literal tag, but that wrecked the page. If this helps: what I am trying to do is pull a value from the database and display it on the page. This value is unique to the client logged in. I can easily do this in normal PHP using SQL, but am having a hard time here. Thanks a lot for the help, and if there is a better way to do this, I am all ears. 0 Quote Link to comment Share on other sites More sharing options...
GORF Posted February 26, 2010 Share Posted February 26, 2010 try: {literal} {php} echo $smarty.session.uid; {/php} {/literal} 0 Quote Link to comment Share on other sites More sharing options...
WHMCS CEO Matt Posted February 26, 2010 WHMCS CEO Share Posted February 26, 2010 You need to lose the literal tags around the PHP code block (you just use those to enclose javascript and CSS) and only use regular PHP variables inside the PHP code block, not smarty syntax. So for example: {php} echo "Your Client ID is: ".$_SESSION['uid']; {/php} Matt 0 Quote Link to comment Share on other sites More sharing options...
Pete_RH Posted February 26, 2010 Share Posted February 26, 2010 (edited) You don't put {literal}{/literal} around PHP. I find I only need it for javascript and css. Also, within {php}{/php} tags, you lose the smart object so just use normal PHP functions to retrieve the session id. Placing this code... {php}echo "Session ID: [".$_SESSION["uid"]."]"; {/php} ...in a .tpl page will work. Edited February 26, 2010 by Pete_RH 0 Quote Link to comment Share on other sites More sharing options...
steve182 Posted February 26, 2010 Author Share Posted February 26, 2010 You don't put {literal}{/literal} around PHP. I find I only need it for javascript and css. Also, within {php}{/php} tags, you lose the smart object so just use normal PHP functions to retrieve the session id. Placing this code... ...in a .tpl page will work. Thanks Matt and Pete, this worked perfectly and I really appreciate your help. 0 Quote Link to comment 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.