jonoc33 Posted November 30, 2007 Share Posted November 30, 2007 Hey guys. I upgraded from PHP 4 to PHP 5 recently, and this code was working on PHP 4 but it isnt anymore. It came up with this error: Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at /home/jonoc33/public_html/clansolutions/members/inc/top.php:5) in /home/jonoc33/public_html/clansolutions/members/menu.php on line 3 Warning: Cannot modify header information - headers already sent by (output started at /home/jonoc33/public_html/clansolutions/members/inc/top.php:5) in /home/jonoc33/public_html/clansolutions/members/menu.php on line 6 The code that contains line 3 and 6 is this: <? include("inc/top.php"); session_start(); // line 3 if(!session_is_registered("client_id")) { header("Location: index.htm"); // line 6 exit; } ?> Should I ask to downgrade to PHP 4? Quote Link to comment Share on other sites More sharing options...
MasterACE14 Posted November 30, 2007 Share Posted November 30, 2007 this error is caused by having something appear on your page before session_start(); remove absolutely everything before session_start(); , except for <?php of course. so the new top of your file should be like this: <?php session_start(); Regards ACE Quote Link to comment Share on other sites More sharing options...
nuxy Posted November 30, 2007 Share Posted November 30, 2007 No. I don't know much about headers in php4 so correct me if i'm wrong anyone. You cannot print/echo any output before all the headers is not sent, this also applies with cookies and sessions. Quote Link to comment Share on other sites More sharing options...
jonoc33 Posted November 30, 2007 Author Share Posted November 30, 2007 Ok, that worked. Now I have a login script: <? include("inc/config.php"); $connection = mysql_connect($hostname, $user, $pass) or die ("Unable to connect!"); $query = "SELECT * FROM clients WHERE name = '$name' AND password = PASSWORD('$password')"; $result = mysql_db_query($database, $query, $connection); if (mysql_num_rows($result) == 1) { session_start(); session_register("client_id"); session_register("client_name"); session_register("client_email"); session_register("client_ref"); session_register("client_title"); list($clientid, $name, $pass, $email, $ref, $title) = mysql_fetch_row($result); $client_id = $clientid; $client_name = $name; $client_email = $email; $client_ref = $ref; $client_title = $title; header("Location: menu.php"); mysql_free_result ($result); mysql_close($connection); } else { mysql_free_result ($result); mysql_close($connection); header("Location: index.htm"); exit; } ?> Notice up the top the session starts in an IF statement, with things before it. The login does not work anymore. What would I do to resolve this? Quote Link to comment Share on other sites More sharing options...
Aureole Posted November 30, 2007 Share Posted November 30, 2007 Just put it at the top, it shouldn't make a difference as far as I know. Quote Link to comment Share on other sites More sharing options...
MasterACE14 Posted November 30, 2007 Share Posted November 30, 2007 just put session_start(); at the very top of each page, and the session_register(); will work if the IF test expression returns true. Regards ACE Quote Link to comment Share on other sites More sharing options...
jonoc33 Posted November 30, 2007 Author Share Posted November 30, 2007 This is weird.. It's still not redirecting me to menu.php because the redirection code is wrong.. Menu.php does work now though if I go there manually Quote Link to comment Share on other sites More sharing options...
Aureole Posted November 30, 2007 Share Posted November 30, 2007 Looks fine to me... one thing you may want to take into consideration is... <?php header("Location: menu.php"); mysql_free_result ($result); mysql_close($connection); ?> After the header()... as far as I know the other two won't be executed so you may as well put them before. I'm not entirely sure but I think I'm right. Quote Link to comment Share on other sites More sharing options...
PFMaBiSmAd Posted November 30, 2007 Share Posted November 30, 2007 Check your web server log for errors and/or turn on full php error reporting in php.ini or a .htaccess file to get php to help you out. I suspect a problem with register_globals. session_register() and session_is_registered() functions are depreciated (a long time ago) and only work when register_globals are on. Quote Link to comment Share on other sites More sharing options...
Aureole Posted November 30, 2007 Share Posted November 30, 2007 If register globals is off then you can do something like... $_SESSION['something'] = 'something'; That's how I do it and I have register globals off. Quote Link to comment Share on other sites More sharing options...
jonoc33 Posted November 30, 2007 Author Share Posted November 30, 2007 To much of a hassle. I'm asking to downgrade to PHP 4. I think PHP 4 is better in my opinion and i'm used to it's functionality. Quote Link to comment Share on other sites More sharing options...
Aureole Posted November 30, 2007 Share Posted November 30, 2007 PHP 5 can do everything PHP 4 can do and more, plus it no doubt has bug fixes and what not... but if you want to downgrade then you downgrade. :-\ Quote Link to comment Share on other sites More sharing options...
PFMaBiSmAd Posted November 30, 2007 Share Posted November 30, 2007 The end of life for PHP4 is the end of this year, in a little more than 30 days. Your web host probably won't continue offering PHP4 for very long after that. Your problem is not PHP4 vs PHP5 but configuration differences in php.ini and since register_globals have been eliminated completely in PHP6, you're going to need to remove any dependencies on register_globals if you want your code to keep working when PHP6 is released. Quote Link to comment 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.