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?