最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

php - Setting cookie when link clicked - Stack Overflow

programmeradmin0浏览0评论

So there's this plugin for wordpress, Transposh: / its basically a translation engine. I have this site i'm owrking on where when a user visits the site the site checks for Transposh's Language preference cookie like this:

<?php if( isset( $_COOKIE['TR_LNG'] ) ) {} else { ?>

and if the cookie (called TR_LNG) is not found it proceeds to show a language selection dialogue, that has links to both English and French versions of the site. The problem is transposh's own widget sets the default language like this: the suer selects language on widget. Widget loads required language page and displays a link below the widget that says Set this language as default. The link looks like this:

<a id="tr_setdeflang" class="tr_setdeflang" onclick="return false;" href=".php?action=tp_cookie_bck">Set this lang....</a>

what I need to happen is, when a user clicks a language in the language preference dialogue that looks like this:

<a href="/">In English</a>

I need it to also set the language, English in the above example as the default. That's the best I can explain my situation, if you need anymore info just let me know.

So there's this plugin for wordpress, Transposh: http://transposh/ its basically a translation engine. I have this site i'm owrking on where when a user visits the site the site checks for Transposh's Language preference cookie like this:

<?php if( isset( $_COOKIE['TR_LNG'] ) ) {} else { ?>

and if the cookie (called TR_LNG) is not found it proceeds to show a language selection dialogue, that has links to both English and French versions of the site. The problem is transposh's own widget sets the default language like this: the suer selects language on widget. Widget loads required language page and displays a link below the widget that says Set this language as default. The link looks like this:

<a id="tr_setdeflang" class="tr_setdeflang" onclick="return false;" href="http://sarvatma/wp-admin/admin-ajax.php?action=tp_cookie_bck">Set this lang....</a>

what I need to happen is, when a user clicks a language in the language preference dialogue that looks like this:

<a href="http://www.sarvatma/en/">In English</a>

I need it to also set the language, English in the above example as the default. That's the best I can explain my situation, if you need anymore info just let me know.

Share Improve this question edited Aug 21, 2012 at 19:58 Atom Vayalinkal asked Aug 19, 2012 at 22:47 Atom VayalinkalAtom Vayalinkal 2,7028 gold badges30 silver badges37 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 2

If I understand, you just need to bind the setting of a cookie to the clicking of the link?

If so, you need to add an ID to your <a>:

<a href="http://www.sarvatma/en/" id="mylink">In English</a>

Then bind some cookie-setting code to the click event:

(Using jQuery)

$("a#mylink").bind("click", function() {
    $.cookie("TR_LNG", "English");
});
发布评论

评论列表(0)

  1. 暂无评论