开发者

Smarty - Getting Posted / Session Variables

I'm working on an "In My Basket" Feature on a shopping site. I'm pairing it on productid. I've done a tamper data on the post when you add to basket. The variable that is getting posted is productid.

I've been using This as a guide to output the productid variable. But I'm just not getting a respons开发者_如何学Goe from the page at all.

The code I am using is {$smarty.request.productid}

The TPL file I am using is HERE I am working on the < div class="inbasket"> which is line 69.

It seems to output with the SERVER_NAME example. But I need that equivalent PHP $_POST VAR.

Does anyone have any idea on what I need to do to pull through the productid and show it on screen, Then I can do an IF statement based on that.

Also worth noting I am using Version 2.6.20 of Smarty

Hoping someone can help me out with this. It appears that smarty is just not showing the session variables at all...


Using {$smarty.request.productid} will only get values that were are in the $_POST array or the $_GET array. For session vars you would simply use "session" as in {$smarty.session.productid}. With smarty the same applies to

  • $_POST -- {$smarty.post.productid}
  • $_GET -- {$smarty.get.productid}
  • $_REQUEST -- {$smarty.request.productid} (request will get vars from both $_POST and $_GET)
  • $_SESSION -- {$smarty.session.productid}

Put this at the top of your tpl file and it will popup with all assigned smarty vars

{debug}

Want to see what is in the session? Put this at the top of you tpl file

{php}
print_r($_SESSION);
{/php}


If you fail to debug, You've another alternative to do.

In PHP file,

$smarty->assign('request_var',$_REQUEST['var1']);

In Smarty TPL,

Use {$request_var}


BTW: When printing user input, always use the "escape" modifier. Otherwise your application is vulnerable (XSS etc).

{$smarty.post.productid|escape}

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜