4

My site uses a "guest" account and therefore needs to allow multiple simultaneous logins from different IPs. So I'm using "Session ID Only" for my Website Session Type.

Is there any good documentation about keeping preserving the Session ID string (S=d571da22a6...) when generating internal links in templates? Through trial and error I've found that when looping through entries, the {url_title_path='group/template'} format will output the Session ID string (thus keeping the user logged in when they click one of them), whereas {comment_url_auto_title_path} does not.

But for the life of me though I can't figure out how to link to the home page and output the Session ID string. {site_url} doesn't do it, and {cp_session_id} only applies to users who have access to the control panel.

Am I missing something? Is it the expected behavior that clicking any link without the Session ID string will log the user out (or at least display the page as if the user is logged out)?

1
  • Hi James, did anything below work? Please let us know how you got on (and mark an answer if any helped).
    – Blatant
    May 22, 2015 at 9:10

3 Answers 3

1

Have you tried outputting the session > userdata > fingerprint on the template. I've used this in addons to recreate the session ID in the control panel.

ee()->session->userdata['fingerprint']

I haven't accessed or tried this on a template though, but it might point you a the right direction.

0

Yea without the session id in the URL it would not keep the user logged in, have you tried the standard {path} and {route} tags? these should maintain the Session ID in the url it puts out.

-1

You could always get $_COOKIE['PHPSESSID'] or call session_id() by enabling PHP in your template.

<a href="http://yourdomain/SID=<?php echo $_COOKIE['PHPSESSID'] ?>">
<a href="http://yourdomain/SID=<?php echo session_id() ?>">

I hope this could help.

References: - ExpressionEngine User Guide: PHP In Templates - PHP session_id()

2
  • Thanks, that sure looks like it would work, but unfortunately in my EE install (v2.8.1), neither of those output anything, no matter what my session types are set to in the CP. Jul 22, 2014 at 14:45
  • Well, this method is far from reliable as PHP in templates is parsed via an eval() operation in the template parser. However to fix this ensure you call @session_start(); before referencing $_COOKIE or session_id. This method will only work in cookieless mode. ee()->session->userdata['fingerprint'], {path} or {route} should all work as these will call the session into existance at the application level and pre-populate the session_id.
    – Blatant
    May 22, 2015 at 9:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.