Session data working on local but not on ipage server - php

I have been trying to debug this problem for hours but couldn't. I have these two files:
My first file:
session_start();
$_SESSION['user'] = '1';
My second file:
session_start();
print_r($_SESSION);
echo $_SESSION['user'];
But The second file echoes an empty array. This works fine on my localhost but didn't work on online server. I also have 'register_globals' turned off in php.ini

If you are using cPanel goto cPanel > php.ini QuickConfig >
Check for
session.save_handler = files
session.save_path = /tmp
If you have still facing the problem ask your cPanel guys they will help you

i was also facing the same issue with ipage hosting now it is solved with Radhakrishna Chowdary`s help i did following-
login to your ipage hosting account
go to Additional Tools -> CGI and Scripted Language Support
there choose PHP Scripting
there you will see "Edit your php.ini file for PHP 5.3" click on
edit.
change value of session.save_path `s value to "/tmp"
its done working now :)

iPage requires you to specify the session_save_path() within your script. Like so :
session_save_path("your home directory path"/cgi-bin/tmp);
session_start();
Take a look at this iPage Knowledgebase article for further reference.

Try changing the session variables like $_SESSION['user'] to $_SESSION['userr']
as changing the variable names worked for me for php 5.3 on ipage

Changing 'session.save_path' is not working I tried this a lot but nothing fixed, I contact there support to fix the issue for me, but they said session is disabled in ipage, which is something very bad for cPanel site.
But anyway I recommend another hosting service since iPage doesn't support session which is something main in php development for login and save data.
I recently receive this from IPage customer service:
this mean that the "session.save_path" will never change in 'php.ini', you have to do it in your code as mentioned from there customer service.
Remember to add this line before session start
session_save_path('/home/your/home/directory/path/cgi-bin/tmp');

Related

How to enable PHP cookies?

I am facing a problem recently with PHP Sessions, on every browser refresh the sessions are getting lost.
I saw that the PHPSESSID is not being read in the cookies.
Then i tried this piece of code.
echo (isset($_COOKIE['foo']) && $_COOKIE['foo']=='bar') ? 'enabled' : 'disabled';
And it seems that PHP cookies are disabled.
My question is this: How can i enable the PHP cookies? What is causing this problem?
Is it a server configuration?
Thank you in advance. Hope to read an explanation from someone.
There are 2 places to do it, either in your php config, or in an htaccess file.
Config
find and change this setting in your php.ini file:
session.use_cookies=1
heres the docs on this and all the other cookie related switches.
note: if you dont know where youre php.ini file is, from the command line, type $ php --ini and itll show you where its located for the cli, the server version will likely be up one level in an apache2/nginx folder.
htaccess
check you dont have this line in your .htaccess file.
SetEnv session.use_cookies='0';

PHP redirects not working after switching to VPS

Edit: This issue was fixed by turning "output_buffering" to "on" in php.ini on vps server. Thank you.
After moving from shared godaddy server to managed VPS on godaddy, the PHP header redirects stopped working on the website.
if(isset($_SESSION['user_id'])){
#header("Location: dashboard.php");
}
Any of these header redirects do not work any more.
Do you know which modules need to be installed or settings that need to be changed for this to work again? It was working fine on the shared server, and also it was tested on another server and worked fine. Just this VPS did not work. It is using WHM cpanel with easyapache 3.
Thank you.
"Remember that header() must be called before any actual output is sent, either by normal HTML tags, blank lines in a file, or from PHP"
http://php.net/manual/en/function.header.php
Maybe there's a problem with session, not header function.
I'd suggest you to try sending header without any condition, and if it works, make sure that session.save_path is writable.
This issue was fixed by turning "output_buffering" to "on" in php.ini on vps server. Thank you.

PHP Session variables not readable on debian azure server

I have got a problem with my php sessions. I have created a debian server on Azure and installed a php/MySQL/apache on it.
The code I use is functional, because it works on my production server but impossible to read $_SESSION variables on this new server.
I can see files well written in /var/lib/php5/sessions, and this directory is readable for the apache user.
In a same page, the $_SESSION variables are available, but not after a redirection on another page.
Is anybody has an idea ? in apache2.conf ? php.ini? network configuration ?
As the production PHP runtime, the session is disabled by default, you can check the PHP configurations via phpinfo() function for the setting of session.auto_start. Refer to http://php.net/manual/en/session.configuration.php#ini.session.auto-start for more info.
You can set the session.auto_start to 1 in php.ini to enable the session automatically.
Otherwise, you can add the code session_start(); in the begin of your PHP script to enable session manually.

Wordpress changes are visible only to logged in users

So here is an unbelievable issue , i am working on wordpress but the problem is if i changes the content in the template file the changes are visible only if the user is logged in . no condition in the template .
for try i have created a template check.php and put the content only
<? echo "hieeee" ; ?>
assigned this to a page , first time it shows me the correct content for both conditions, but if i change the content like
<? echo "hieeee this is update " ; ?>
for logged in user it will show hieeee this is update and for logged out users hieeee can't understand where is the issue .
PHP Version 5.5.16 | mysql client 5.0.11 | SunOS wp1.superhome.com.au 5.11
its solved There was a plugin Nginx Helper which store the cache on server. Thanx all for your efforts
This is definility a caching issue. First I thought it was a caching plugin, but it seems like you have full control of that. It worked locally but not on production server, so it had to be something on the server.
Taking a closer look at the phpinfo() you've supplied, superhome host is using Zend OPcache v7.0.4-dev
You could try to disable the cache temporarily by doing:
If PHP runs as an Apache module, use .htaccess file: php_flag opcache.enable Off
If PHP runs as CGI/FastCGI, use .user.ini file: opcache.enable=0
If you have access to php.ini, try to disable it that there.
UPDATE
It seemed you find the actual answer that there was a plugin messing it up, but if someone else stumples upon the same issue this answer might help.

Session is not working on my site

I Am using a session on a website and I am unable to take the data on the other page. I have used the code on other host and its working fine on other host so I think that the host problem.
The code I used to save the session is:
session_start();
$_SESSION["std_id"] = 'rst';
echo "<pre>";
print_r($_SESSION);
echo "</pre>";
And I am retrieving it on the other page with this code:
session_start();
echo "<pre>";
print_r($_SESSION);
echo "</pre>";
As I said its working fine on other host as well as on localhost, so that is the server issue, but I need to keep the login info of the user as we use to maintain login record through session.
We have installed Joomla on that site and its working fine its maintaining all the login info and every thing.
Can anyone suggest me the solution other than changing the host :)
Thanks.
Edited:
I can't show the host name as due to some reason.
The domain I am using is a sub-domain for a University department and the main site is of University site, and I am using this code under a new folder at sub domain.
do you get any errors in your error log or in php error reporting (error_reporting)?
like "No session exists - writing to test_value"
you can also test your current session directory if its writeable:
$writeable = is_writable(ini_get("session.save_path"));
one solution is to change your session directory with this:
(create the /tmp directory by hand in your root)
ini_set("session.save_path","/tmp");
or to your .htaccess
php_value session.save_path /tmp
and give 0777 permission in that /tmp directory, which must be in your root.
As I see in your codes, everything looks fine. You do not need to change your host just contact to your host provider. I've had a similiar issue with a host before. If you contact them, they will edit your php.ini file to allow you to start sessions.
Note : Not every host providers allow users to use many features of PHP. You have it ask them to set it on. They turn these features off to save CPU usage.

Categories