i having a strange issue in sessions.. this is working in WAMP server in my local machine.. my problem is wen hosted to a server in US it's not working..
im doing like this:
session_start();
$_SESSION['test'] = 'testing login..';
in another page i'm doing:
session_start();
echo('my session value is : '.$_SESSION['test']);
but i'm getting only
my session value is :
my session value is not setting..
i checked the session.save_path in cPanel of the server it says /tmp.
pls help..
thanks in advance.
Maybe your script dies because session_start fails with "headers already sent" ? This could happen, for example, if your test machine and production server don't encode new lines the same way...
The errors are probably not displayed on your production server, try something like that :
ini_set('display_errors', 1);
session_start();
and see if you get something useful.
The php opening tag must be written at first line of a php file. This method help me to solve this problem.
Check the permissions on your session.save_path. This location will need to be writable by the Apache/httpd user.
Also check to see if you session.save_path contains any sess_ prefixed files.
thanks for all the help.
my issue was security permission in /tmp folder. once it rectified it's working.
mean time dont use only numeric for SESSION ids, (Eg. $_SESSION['12345']) because in linux hosting its not taking the numeric only index and skipping that. (so use $_SESSION['ACS12345'])..
Take a look at the way you created the file.
If you used auto language detection features, or something similar to create your file, then try creating a new PHP file. Copy your code and try again.
if you're using siteground as your hosting you will need to enable the auto session. follow this steps
Navigate to Dev
click on php manager
click on php variables
Load more until you find session.auto_start
Turn it to yes and you're good to go
Related
Fatal error: Can't use function return value in write on line 3
I've looked extensively for an answer to my specific situation with no progress. Please review what I've already tried and I've included my VPS global php.ini file. No php.ini files exist within the website root.
<?php
session_start();
?>
<!DOCTYPE html>
<html>
I have no idea how that's possible. Please check out what I've already done to try to solve the problem.
Problem originated when I was unable to pass variables to another page using
$_SESSION['$example'] variables with no luck. But I'll worry about that next.
VPS System Specs Currently (Servers/Networks Are Not My Strong Area)
Apache 3 on CentOS 6.8
Default PHP Version | 5
PHP 5 Handler | suPHP
Apache suEXEC | off
Apache Ruid2 | off
Default PHP Version (.php files) | 5
PHP 5 Handler | suPHP
Attempted Solutions
Disabled .htaccess
.htaccess contains
***suPHP_ConfigPath /***
Header append Vary User-Agent
Prior to disabling:
Removed All 301 Rewrite Rules as I've read they interfere with
sessions
Disabled Error Documents
Ensure No Whitespaces Following session_start();
Caching
Turned off all caching through WHM (that I'm aware of)
Tested both Firefox and Chrome before and after clearing history/cookies/cache/etc
Deleted CloudFlare service for this domain
Additional Information
I Don't have a php.ini file since I use a VPS (in case anyone was wondering)
I use php on almost every other page.
Here is an example of the first few lines of another page.
<?php
session_start();
$ip = $_SERVER['REMOTE_ADDR'];
//Version 1.75
The above code is just the first few lines but the page executes fine without issue. It should be noted that this is a redirect page following a PayPal payment to my website. This issue is recent and previously it has worked fine.
It should also be noted that I use session_write_close(): session_unset(); and session_destroy(); on appropriate pages to unset all $_SESSION variables and terminate sessions.
Below is a link to the php.ini file as text if that helps. The domain contained in the link is not the domain with the issue. I'm not attempting to be "shifty" about the domain with the issue, I just don't want people using the service when it's not working properly.
Global PHP INI File As Text Document
Anyone who solves this, I owe you!
-Andrew
Solved Accidentally
I solved the issues, but still don't know what was causing the Fatal Error
Fatal error: Can't use function return value in write on line 3
$_SESSION variables didn't pass between pages.
I solved both the Fatal Error issue and the $_SESSION variables problem by doing one thing. For some, this may be standard procedure, but I am self-taught and this did not occur to me. I was making changes to the PHP advanced configuration in WHM and never did not see any changes as a result.
I was banging my head against the wall for two days trying every solution I read in the forums.
Apache Server Restart
I never restarted my Apache Server during this time, both issues were resolved.
While this solution may seem rudimentary or common practice for some, it's easy to overlook. I read at least 30 different forum posts on Stack Overflow and other sites. Not one suggested an Apache Restart as a method to check.
PHP Configuration
I changed my PHP configuration as listed below and my sessions variables were passing.
session.use_cookies = 1
session.use_only_cookies = 1
session.use_trans_sid = 0
Thank you for everyone who took the time to look at this.
Sincerely, Andrew
I'm making use of storing random token values into session as well as flash message which prints out messages for one time only upon registration of updating profile,, this is working so far like it should on the localhost - wampserver. However, after deploying the website to the live server the process works correctly as long as the user is not logged in, after I log in I just can't update the profile at all, also after a successful registration the message "you have been registered successfully" is shown every time I go to the the homepage while it should only appear once and only once.. and again on the local server it is working like charm.
So after checking some online resources the answer was it mostly the configuration of php.ini on the server is what causing the problem, so I checked the php.ini on the server and after comparing it to the local one i found these two line missing concerning the Session field:
session.save_path = "c:/wamp/tmp"
session.use_only_cookies = 1
Then I added them to the online version of php.ini and it still doesn't work, of course I've changed the save_path to some random value but the whole storing in session doesn't work at all until i comment the session.save_path line, the other line didn't change anything so I don't know where the problem is.
Thanks in advance.
you're trying to write to a directory php doesn't have write access to. when you comment out the line, it stores it in the default php save path, which it does have write permissions.
I just found this PHP Based session variable not retaining value. Works on localhost, but not on server and it is exactly the cause of the problem, these people using register_globals ON .. that's it.
I have a DMZ set up with a web server and an application server, both running Ubuntu under gnome (v11.04 on the web server and v11.10 on the application server). session_start() has started hanging on the application server. The code is located on the application server and it does not hang when I access my web site and access the page with the session_start() call on it. It seems that every session_start() has started hanging on the application server although I have no problems with the associated pages when I access them from other computers or across the web. Also I have only just started having this problem on the application server without having made any changes to my php code. Could it be that some buffer has filled up and needs to be cleared?
I tried editing /etc/php5/apache2/php.ini and setting
session.save_path = "/tmp"
/tmp exists.
But I still have the problem. I can stop it hanging by preceding session_start() with session_end() but then it does not execute the remaining PHP or html code in the file.
/var/log/apache2/error.log included the following message:
PHP Notice: A session had already been started - ignoring session_start() in
/var/www/DraculaPgm.php on line 101, referer:
http://MyWebSite.com/ApplicationServer/Dracula.php
Any assistance with this would be greatly appreciated,
Peter.
Update 29-Dec-2012
Thank you to everyone who replied to this question. Unfortunately, I tried all of the suggestions and 'session_start()' still hangs. However, if I leave it for a few minutes, it breaks with the following error message.
Proxy Error
The proxy server received an invalid response from an upstream server.
The proxy server could not handle the request GET /ApplicationServer/Dracula.php.
Reason: Error reading from remote server
Apache/2.2.17 (Ubuntu) Server at MyWebSite.com Port 80
I have squid installed on the web server. Could this be a problem?
Thanks,
Peter
This sounds like a configuration issue. Make sure that PHP is reporting all errors, i.e., error_reporting(E_ALL) and either display or log all errors. (You might even want to enable display_startup_errors in your php.ini) - reporting all errors may shed light on what's going on. (if you need help you can post any errors that you get from this as an edit) You may want to look at the following as well for troubleshooting the issues with sessions:
When using /dev/random as session entropy file
When page is calling itself with the same session
Alternatively if none of those show anything you may want to read over the bug report at https://bugs.php.net/bug.php?id=28856&edit=1 depending on what version of PHP you are running.
I changed 'session_start()' to the following block.
if(!isset($_SESSION))
{
session_destroy();
session_start();
}
I now do not have the problem. I am hesitant to say that it fixed the problem since it did not seem to fix it right away.
Thank you to everyone for your help,
Peter.
Try changing the permission of the /tmp folder by doing chmod 777 /tmp and check if its working.If its working then change the permission mode to make it more secure
Try checking out this Question I call session_start() the script hangs and nothing happens
And this http://www.projectpier.org/node/1934
"It seems that the session file is opened exclusively. On some
occasions (Windows) I have found that the file lock is not released
properly for whatever reason, therefore causing session_start() to
hang infinitely on any future script executions. My way round this
problem was to use session_set_save_handler() and make sure the write
function used fopen($file, 'w') instead of fopen($file, 'x')"
You can find many others having the same problem and their workarounds if you go through http://php.net/manual/en/function.session-start.php
if(!isset($_SESSION))
{
session_start();
}
Use this at the top of your PHP file!
And for your info: session_destroy() is used to end session.
Before anything else - try another browser!
I just encountered this session_start problem. I checked my tmp folder and everything and I was about to call my hosting-provider until I thought I should try another browser first because it might have to do with session cookies.
I work with chrome, so I tested in IE and found that it was indeed the case: It worked in another browser!
I closed IE ;) - went back to chrome, looked for the cookie (PHP_SESS_ID), deleted it and everything works again!
Well, the good part is - Just like you guys I got to brush up my knowledge of -jay- sessions! ;)
I want to redirect to www.yahoo.com from my codeIgniter application. I write code like this :
redirect("http://www.yahoo.com");
It is working fine in my local computer (Windows vista / WAMP) but when I upload to linux server it just show blank screen and not redirect.
Try using the refresh method:
redirect('http://www.yahoo.com', 'refresh');
Blank screen normally means a fatal error somewhere. Check your logs!
And check your headers too. Curl it or use a HTTP Client to see what is being returned.
Debugging helps with these things. We are just random people on the internet without access to your computer, so without more information (hell you didnt even mention which version of CI you are using) we are all just taking guesses.
you probably want header: header('location: http://www.yahoo.com');
Try enabling error_reporting(E_ALL) to see if there are any errors that indicate output is being sent before those headers (specified by redirect()).
A common issue that I find is that the means of uploading (e.g. deploying over FileZilla) will sometimes insert lines depending on the transfer mode I guess. I've seen those same files I uploaded via FileZilla double spaced entirely. More than likely, you have an empty line at the top of your controller. Best way to find out is to edit that controller on the server (e.g. File Editor or re-download and view it) and see if this is the case.
I copied an existing and successfully running site to a new development server.
The login on the new server is now broken, and I tracked it down to the fact that although the session cookie is renamed ...
ini_set('session.name', 'DOMAIN1');
... the browser keeps storing the sesssion cookie as PHPSESSID.
When I remove the above line from the application on the new server, the login works again. But this is not a good solution, because another application also uses PHPSESSID under this name.
And I would prefer to find the reason for the strange behaviour instead of using a workaround. If I don't fix it it could bite me somewhere else.
Maybe this is already enough information for someone to give me a hint. If not, what information would be useful?
This machine was a very naked and basic ubuntu 8.04 server, and I installed apache2, mysql and php5 with aptitude. I also updated lokales and the timezone.
Solution:
I replaced the line above with this code from from the accepted answer ...
if(ini_set('session.name', 'DOMAIN1') === false || !session_name('DOMAIN1'))
{
die('Unable to set sesssion scope');
}
... and the login now works on the new server.
Sometimes ini_set plays up and is unable to set the ini values correctly, might be down to permissions.
the below does not fully resolve the issue with ini_set, and if anyone knows the reason(s) why ini_set does not work on some type's of host, then please share!
Try the following:
<?
if(ini_set('session.name', 'DOMAIN1') === false || !session_name('DOMAIN1'))
{
die('Unable to set sesssion scope');
}
phpinfo();
?>
alternatively you can just use session_name() to set it, and ill always advise you not to just run functions and hope the always check the in an if statement and prepare for the worst case scenario, thats when your application becomes reliable and less error_prone.