Welcome Guest, Not a member yet? Register   Sign In
Unable to set sessions in www.example.com domain name.
#1

[eluser]srikantmatihali[/eluser]
Hi all,

I am using sessions for my expressionengine project. I am unable to set sessions for www.example.com domain. I have set sessions for http://example.com.

I have used

Code:
if (session_id() == ''){
   session_start();
} and

if(!isset($_SESSION)){
   session_start();
}

and

if(empty($_SESSION['userid'])){
                         session_start();
}

at the top of the page. I have written custom ee plugin where I do session check.

I tried reaching http://webchat.freenode.net/ and got suggestions from there also. It dint help.

I have follwed steps from this thread.
http://ellislab.com/forums/viewthread/231468/

Can someone please suggest me on this.
#2

[eluser]rana[/eluser]
Why don't do it in codeigniter way? check here:
http://ellislab.com/codeigniter/user-gui...sions.html

Also, as session is needed a lot, you can load it via autoload, so no external call will be required at all.
#3

[eluser]Otemu[/eluser]
Change your code to something like this
//start the session
session_start();
//check if session exists
if(isset($_SESSION['username']))
{
echo "welcome ".$_SESSION['username'];
}
//if it doesn't exist do something else
else
{
echo "your not welcome here";
}
#4

[eluser]srikantmatihali[/eluser]
@Otemu: I have used the same concept, but could not get any solution.
@rana: I was in a confusion of using sessions in three different variations.
1. native php way
2. the expression engine way http://ellislab.com/expressionengine/use...ssion.html
3. your idea to use it via code igniter way.

Most of my code is already written. It is difficult to change it all of a sudden. But i will give a try in a demo project . In the meantime I observed something interesting.

If i set sessions on www.example.com by harcode method, it wont set on http://example.com.

So I need a solution such that if a user sets sessions either with http://example.com or www.example.com, both should yield same session results.
#5

[eluser]Otemu[/eluser]
Paste the full code for your controller and view of at least two pages so we can try see where the issue is.

To tackle losing sessions on http://example.com
either force www. or no www. in .htaccess file using redirects
or try this

Add this line before your session_start();:
ini_set('session.cookie_domain', '.mysite.com' );

Your problem is probably your PHP_SESS_ID cookie domain not beginning with a "."
session_set_cookie_params ( 3600 , '/', '.example.com');

Taken from http://stackoverflow.com/questions/14000...to-another
#6

[eluser]srikantmatihali[/eluser]
After your feedback and some googling, I have found out that inorder to let sessions stay availabe on multiple domains on the same server we got change settings either through php.ini file or through ini_set function

I have used this on index file of expressionengine

Code:
ini_set('session.cookie_domain','.example.com');

It is working fine for me.

Below posts helped me to understand the issue more broadely.

http://stackoverflow.com/questions/14339...sionengine

http://stackoverflow.com/questions/10642...ub-domains


http://stackoverflow.com/questions/49483...-directory




Theme © iAndrew 2016 - Forum software by © MyBB