Jump to content

Adding PHP to client area


steve182

Recommended Posts

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 :)

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

  • WHMCS CEO

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

Link to comment
Share on other sites

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 by Pete_RH
Link to comment
Share on other sites

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.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use & Guidelines and understand your posts will initially be pre-moderated