dongzhi9906 2011-10-18 16:48
浏览 12
已采纳

如何为每个链接动态构建查询字符串?

I am building a method for impersonating a certain user on my website, similar to how Facebook now does it on the profiles with the "View As" button.

The goal here is to be able to append the user id of the person that I would like to impersonate to the query string like so: viewas=1234. Upon seeing that, the site would allow me (as an admin) to "impersonate" that user.

However, the problem comes with carrying the "impersonation" state between page loads. Each link that I click on will need to be adjusted to carry the viewas=1234.

For example, a link that would typically look like this...

<a href='http://www.example.com/profile?profileid=5678'>My Profile</a>

...would have to dynamically know to turn into...

<a href='http://www.example.com/profile?profileid=5678&viewas=1234'>My Profile</a>

...whenever I would like to impersonate the user with the id 1234. And this would have to happen site wide.

Is the best way to somehow do this with JS after the load, with PHP on the server side, or something else?

  • 写回答

3条回答 默认 最新

  • dongtiao2105 2011-10-18 17:02
    关注

    Not sure whether this is the answer you'd be looking for, however here it goes. I recently had to implement a similar set of functionality. I went with storing the value of "viewas" in the session variable. This way, there is no need to modify HTML, javascript, etc. - only your code (which you already are modifying anyway to handle the query string) - in the code check the session variable instead.

    You can then unset this variable when the admin "logs out" from impersonation.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?