Jump to content

Weird PHP Error


jonoc33

Recommended Posts

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?

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.