R0bb0b Posted October 8, 2008 Share Posted October 8, 2008 Please look into this, session_save_path("/some/path/to/dir/"); This ("/some/path/to/dir/"), should i leave it this way, or i must specify some path to a directory and if yes, what directory? I hope you understand You need to change the path to somewhere, I would say outside of the document root if you can. Quote Link to comment https://forums.phpfreaks.com/topic/127438-solved-wierd-session-warning/page/2/#findComment-659707 Share on other sites More sharing options...
nitation Posted October 8, 2008 Author Share Posted October 8, 2008 This is 1-3 lines of session.php <?php session_start(); $afso_name=session_name(); $afso_sid=session_id(); ?> The below is 1-8 lines of login.php <?php session_start(); if (!isset ($_SESSION["admin_id"])) { header ("Location:main.php?login=missing"); } include("connect.php"); if($log){ $sqllog=mysql_query(" SELECT * FROM enter_code WHERE aname='$loginname' "); ?> I put this code in the main file, ini_set ("display_errors", "1"); error_reporting(E_ALL); This is what it outputted; Warning: session_start() [function.session-start]: open(/tmp/sess_d90f4557eceb9cdf247d9e5e5301e58f, O_RDWR) failed: Read-only file system (30) in /home/prudccou/public_html/session.php on line 2 Warning: session_start() [function.session-start]: Cannot send session cookie - headers already sent by (output started at /home/prudccou/public_html/session.php:2) in /home/prudccou/public_html/session.php on line 2 Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at /home/prudccou/public_html/session.php:2) in /home/prudccou/public_html/session.php on line 2 Notice: Undefined index: afso_userid in /home/prudccou/public_html/session.php on line 5 Notice: A session had already been started - ignoring session_start() in /home/prudccou/public_html/login.php on line 3 Warning: Cannot modify header information - headers already sent by (output started at /home/prudccou/public_html/session.php:2) in /home/prudccou/public_html/login.php on line 8 Notice: Undefined variable: log in /home/prudccou/public_html/login.php on line 13 Quote Link to comment https://forums.phpfreaks.com/topic/127438-solved-wierd-session-warning/page/2/#findComment-659708 Share on other sites More sharing options...
R0bb0b Posted October 8, 2008 Share Posted October 8, 2008 this is funny: Notice: A session had already been started - ignoring session_start() in /home/prudccou/public_html/login.php on line 3 BTW: you don't need to call session_start() for every included file, just the first one. Quote Link to comment https://forums.phpfreaks.com/topic/127438-solved-wierd-session-warning/page/2/#findComment-659709 Share on other sites More sharing options...
nitation Posted October 8, 2008 Author Share Posted October 8, 2008 @ R0bb0b I placed session.php in my includes folder in /www directory I believe my code should look like this; ini_set("session.save_path","/public_html/includes/"); Also, what is funny about session had already started Quote Link to comment https://forums.phpfreaks.com/topic/127438-solved-wierd-session-warning/page/2/#findComment-659710 Share on other sites More sharing options...
R0bb0b Posted October 8, 2008 Share Posted October 8, 2008 @ R0bb0b I placed session.php in my includes folder in /www directory I believe my code should look like this; ini_set("session.save_path","/public_html/includes/"); Also, what is funny about session had already started I'm not exactly sure what the permissions on session files are, but I would assume that you would want to keep them outside of the document root, is that possible? Its funny that the session is already started because if this is the case, it sounds like the issue happens randomly because if failed the first time and apparently succeeded later on. Are you calling session_save_path() on the very first line of code that runs after your first "<?php" tag? If not, that's what you want to do. Quote Link to comment https://forums.phpfreaks.com/topic/127438-solved-wierd-session-warning/page/2/#findComment-659713 Share on other sites More sharing options...
PFMaBiSmAd Posted October 8, 2008 Share Posted October 8, 2008 A) Where in your code are you putting the line to set session.save_path? B) login.php and session.php are obviously being included by some main file. Post that code as well. C) After the header() redirect in login.php, add a exit(); statement. I suspect this is partly responsible for the original error as that page will continue executing and the browser will request main.php, which I am going to guess contains or includes a file the contains a session_start(); @R0bb0b, his error reporting was set to prevent notice messages from being reported and the "Notice: A session had already been started" was occurring all along. This code is a mess. There should only be one session_start() statement at the beginning of the page and the code that R0bb0b has given to set session.save_path must go before that single session_start(). I am going to guess that if the header() redirect is not causing the original error that this tangle of include statements/session_starts is what is causing the original error. Quote Link to comment https://forums.phpfreaks.com/topic/127438-solved-wierd-session-warning/page/2/#findComment-659715 Share on other sites More sharing options...
aeonsky Posted October 8, 2008 Share Posted October 8, 2008 tmp is outside root, so I'd guess yeah. You should be able to save them outside public root. By the way, are you using cPanel? I saw that you can actually change permissions on your tmp folder. You should try that! Quote Link to comment https://forums.phpfreaks.com/topic/127438-solved-wierd-session-warning/page/2/#findComment-659716 Share on other sites More sharing options...
PFMaBiSmAd Posted October 8, 2008 Share Posted October 8, 2008 Setting the session.save_path is an attempt to work around a tmp folder that might have a problem. However, based on what the code is doing, it is likely the code is causing this and setting the session.save_path to a different folder won't have any effect on the original error. Quote Link to comment https://forums.phpfreaks.com/topic/127438-solved-wierd-session-warning/page/2/#findComment-659718 Share on other sites More sharing options...
nitation Posted October 8, 2008 Author Share Posted October 8, 2008 A) Where in your code are you putting the line to set session.save_path? B) login.php and session.php are obviously being included by some main file. Post that code as well. C) After the header() redirect in login.php, add a exit(); statement. I suspect this is partly responsible for the original error as that page will continue executing and the browser will request main.php, which I am going to guess contains or includes a file the contains a session_start(); @R0bb0b, his error reporting was set to prevent notice messages from being reported and the "Notice: A session had already been started" was occurring all along. This code is a mess. There should only be one session_start() statement at the beginning of the page and the code that R0bb0b has given to set session.save_path must go before that single session_start(). I am going to guess that if the header() redirect is not causing the original error that this tangle of include statements/session_starts is what is causing the original error. A) I am putting session.save_path in session.php B) this is the main file. main.php <? include("session.php"); include("connect.php"); include("admin/includes/en.php"); $return="Access Code"; if($login=="wrong"){ $return="Access code wrong"; } else if($login=="missing"){ $return="Access code missing"; } require("index_login.php"); ?> C) I have added exit after redirecting. Take a look at the full code for login.php <?php session_start(); if (!isset ($_SESSION["admin_id"])) { header ("Location:main.php?login=missing"); } include("connect.php"); if($log){ $sqllog=mysql_query(" SELECT * FROM enter_code WHERE aname='$loginname' "); if($sqllog){ $row=mysql_fetch_array($sqllog); $rowid=$row["id"]; } $num=mysql_num_rows($sqllog); if($num > 0){ $_SESSION["admin_id"]=$row["adminid"]; header ("Location: index.php"); } else { header ("Location: main.php?login=wrong"); } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/127438-solved-wierd-session-warning/page/2/#findComment-659721 Share on other sites More sharing options...
nitation Posted October 8, 2008 Author Share Posted October 8, 2008 Am i still missing something??? @ PFMaBiSmAD Quote Link to comment https://forums.phpfreaks.com/topic/127438-solved-wierd-session-warning/page/2/#findComment-659731 Share on other sites More sharing options...
PFMaBiSmAd Posted October 8, 2008 Share Posted October 8, 2008 C) I have added exit after redirecting.Except, I don't see any exit; statements in the code you posted for login.php. Every header ("Location:some_url"); must have an exit; statement after it to prevent the remainder of the code from being executed. Your login code could be sending up to two header() redirects, both of which will be requested by the browser. Quote Link to comment https://forums.phpfreaks.com/topic/127438-solved-wierd-session-warning/page/2/#findComment-659739 Share on other sites More sharing options...
nitation Posted October 8, 2008 Author Share Posted October 8, 2008 I posted the old long.php. I have added the exit(); and this is the error am getting. Warning: session_start() [function.session-start]: open(/tmp/sess_86fe007aecc23577c9629d5a4e231cde, O_RDWR) failed: Read-only file system (30) in /home/prudccou/public_html/session.php on line 2 Warning: session_start() [function.session-start]: Cannot send session cookie - headers already sent by (output started at /home/prudccou/public_html/session.php:2) in /home/prudccou/public_html/session.php on line 2 Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at /home/prudccou/public_html/session.php:2) in /home/prudccou/public_html/session.php on line 2 Notice: Undefined index: afso_userid in /home/prudccou/public_html/session.php on line 5 Parse error: syntax error, unexpected ':' in /home/prudccou/public_html/login.php on line 32 Warning: Unknown(): open(/tmp/sess_86fe007aecc23577c9629d5a4e231cde, O_RDWR) failed: Read-only file system (30) in Unknown on line 0 Warning: Unknown(): Failed to write session data (files). Please verify that the current setting of session.save_path is correct (/tmp) in Unknown on line 0 Quote Link to comment https://forums.phpfreaks.com/topic/127438-solved-wierd-session-warning/page/2/#findComment-659740 Share on other sites More sharing options...
sKunKbad Posted October 9, 2008 Share Posted October 9, 2008 Maybe I'm wrong, but I think you need to call session_name() and session_id() before session_start(). Quote Link to comment https://forums.phpfreaks.com/topic/127438-solved-wierd-session-warning/page/2/#findComment-660636 Share on other sites More sharing options...
nitation Posted October 9, 2008 Author Share Posted October 9, 2008 session_name(), session_id() before session_start(). Am hearing that for the first time :X Quote Link to comment https://forums.phpfreaks.com/topic/127438-solved-wierd-session-warning/page/2/#findComment-660845 Share on other sites More sharing options...
R0bb0b Posted October 9, 2008 Share Posted October 9, 2008 session_name(), session_id() before session_start(). Am hearing that for the first time :X These should not be necessary. At this point I would create one test file, start a session and play with the session variables. This will allow you to determine if there is an issue with the server or your code. Quote Link to comment https://forums.phpfreaks.com/topic/127438-solved-wierd-session-warning/page/2/#findComment-660932 Share on other sites More sharing options...
sKunKbad Posted October 9, 2008 Share Posted October 9, 2008 session_name(), session_id() before session_start(). Am hearing that for the first time :X According to the php manual: Description string session_name ([ string $name ] ) session_name() returns the name of the current session. The session name is reset to the default value stored in session.name at request startup time. Thus, you need to call session_name() for every request (and before session_start() or session_register() are called). Quote Link to comment https://forums.phpfreaks.com/topic/127438-solved-wierd-session-warning/page/2/#findComment-661125 Share on other sites More sharing options...
DeanWhitehouse Posted October 9, 2008 Share Posted October 9, 2008 Lol, no you don't need to call session_name or session_id, you just need session start. But if he can post his full code with the errors he may get a faster/better answer. Quote Link to comment https://forums.phpfreaks.com/topic/127438-solved-wierd-session-warning/page/2/#findComment-661155 Share on other sites More sharing options...
sKunKbad Posted October 9, 2008 Share Posted October 9, 2008 Lol, no you don't need to call session_name or session_id, you just need session start. But if he can post his full code with the errors he may get a faster/better answer. I know you don't need to call session_name or session_id, but he is in his code. I am very interested to see what the fix is in the end. Quote Link to comment https://forums.phpfreaks.com/topic/127438-solved-wierd-session-warning/page/2/#findComment-661245 Share on other sites More sharing options...
nitation Posted October 10, 2008 Author Share Posted October 10, 2008 I managed to fix the problem. A developer friend of mine said its a random error from the host. That there is nothing to do. Actually, i did nothing and all errors dissappeared. Thanks guys for ur Help. PFMaBiSmAd and Blade280891, Kudos to you guys. Quote Link to comment https://forums.phpfreaks.com/topic/127438-solved-wierd-session-warning/page/2/#findComment-661771 Share on other sites More sharing options...
R0bb0b Posted October 10, 2008 Share Posted October 10, 2008 mind if I ask you what versions of apache and php you're running? Quote Link to comment https://forums.phpfreaks.com/topic/127438-solved-wierd-session-warning/page/2/#findComment-661819 Share on other sites More sharing options...
nitation Posted October 10, 2008 Author Share Posted October 10, 2008 Php 5.2.5 Apache/1.3.41 (Unix) Quote Link to comment https://forums.phpfreaks.com/topic/127438-solved-wierd-session-warning/page/2/#findComment-661833 Share on other sites More sharing options...
DeanWhitehouse Posted October 10, 2008 Share Posted October 10, 2008 When i had a problem similar to this, where setting a session timed out the script, i found out the host was upgrading the php version. If you know that the code can't be causing the error, contact the host. Quote Link to comment https://forums.phpfreaks.com/topic/127438-solved-wierd-session-warning/page/2/#findComment-662088 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.