View Full Version : Adding PHP to client area
steve182
02-25-10, 10:02 PM
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 :)
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}
steve182
02-26-10, 02:54 PM
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.
TonsOfStores
02-26-10, 03:23 PM
try:
{literal}
{php}
echo $smarty.session.uid;
{/php}
{/literal}
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
Pete_RH
02-26-10, 04:16 PM
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.
steve182
02-26-10, 04:33 PM
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.
Powered by vBulletin® Version 4.2.0 Copyright © 2013 vBulletin Solutions, Inc. All rights reserved.