Welcome Guest, Not a member yet? Register   Sign In
COOKIE AND SESSIONS dont work both in code igniter and native php
#1

[eluser]andykhatter1[/eluser]
Hi All,

Its been almost a week now and I am pulling my hair out now but no success in making them work.
I have tried gazillions of solutions but no help...
This is what I am doing

$cookie = array(
'name' => 'test',
'value' => 'The Value',
'expire' => time()+9999999,
'domain' => '.domainName.com',
'path' => '/',

'secure' => TRUE
);

setcookie("test", "testing", time()+999999, '/', '.domainName.com', FALSE, TRUE);
set_cookie($cookie);


on the other page:

var_dump(cookie('test'));

var_dump($_COOKIE);

It returns me nothing.

If I echo the setcookie itself it returns false and set_cookie returns me NULL.

Am I missing on any settings??? Though I have checked all of them but still of no help.

Any help/suggestions would be much appreciated.

Thanks
Andy
#2

[eluser]andykhatter1[/eluser]
Also to give you a background on problem....

I wanted to use sessions...I can set the sessions and use the data on the other page but everytime I reload a page it creates a new session.

So while debugging that I realised sessions hold the data in cookies and I have been trying to make my cookies work ,

If there is any other way around doing this let me know.

Also I have enabled my code igniter to use the session table and I can see the session id being created on every hit.

When I looked at the Session.php class in core igniter it always look for a cookie even if its using the table. So my root problem is I am not being able to set a cookie.

When I monitor the cookies through firebug I dont even see the name of the cookie that I set.

Please help I am really frustrated now!! Sad
#3

[eluser]CroNiX[/eluser]
post your config settings for sessions, and also cookies
#4

[eluser]andykhatter1[/eluser]
$config['sess_cookie_name'] = 'ci_session';
$config['sess_expiration'] = 99999999;//have tried 0 too
$config['sess_expire_on_close'] = FALSE;
$config['sess_encrypt_cookie'] = TRUE;
$config['sess_use_database'] = TRUE;
$config['sess_table_name'] = 'ci_sessions';
$config['sess_match_ip'] = TRUE;
$config['sess_match_useragent'] = TRUE;
$config['sess_time_to_update'] = 300;

/*
|--------------------------------------------------------------------------
| Cookie Related Variables
|--------------------------------------------------------------------------
|
| 'cookie_prefix' = Set a prefix if you need to avoid collisions
| 'cookie_domain' = Set to .your-domain.com for site-wide cookies
| 'cookie_path' = Typically will be a forward slash
| 'cookie_secure' = Cookies will only be set if a secure HTTPS connection exists.
|
*/

if(isset($_SERVER['HTTP_HOST']))
{
$config['base_url'] = isset($_SERVER['HTTPS']) && strtolower($_SERVER['HTTPS']) == 'on' ? 'https' : 'http';
$config['base_url'] .= '://'. $_SERVER['HTTP_HOST'];
$config['base_url'] .= isset($_SERVER['SERVER_PORT']) && $_SERVER['SERVER_PORT'] != '80' ? ( ':'.$_SERVER['SERVER_PORT'] ) : '';
$config['base_url'] .= str_replace(basename($_SERVER['SCRIPT_NAME']), '', $_SERVER['SCRIPT_NAME']);
}
else
{
$config['base_url'] = 'http://localhost/';
}

// determine the domain and the path from the base_url
$base_url_parts = parse_url($config['base_url']);
//$config['cookie_domain'] = $base_url_parts['host'];
//$config['cookie_path'] = $base_url_parts['path'];

unset($base_url_parts);
$config['cookie_prefix'] = "";
$config['cookie_domain'] = ".domainName.com";
$config['cookie_path'] = "/";
$config['cookie_secure'] = FALSE;

//var_dump($config['cookie_domain']);die();
#5

[eluser]andykhatter1[/eluser]
Hi

I just tried creating another simple project to test sessions and cookies on my server and it just worked fine.
And if I put session_start() right in the beginning on the index.php file of my codeigniter project it gives me a new session id everytime the page is hit.



So that problem has to be within the codeigniter settings itself.

Edit:
SO now putting the session_start right at the beginning of the index.php file creates a session. So I think the problem was only with right placement...But again only my php sessions work and not codeigniter...If someone could tell where to put my session_start so that atleast I can use the php sessions if not much....

Thanks




Theme © iAndrew 2016 - Forum software by © MyBB