Jump to content

Session Register problem


bri4n

Recommended Posts

Hi ya!

 

I was wondering if someone can help me resolcve this simple problem. I get the following errors when trying to proces a page on my website:

 

Warning: session_register() [function.session-register]: Cannot send session cookie - headers already sent by (output started at /var/www/vhosts/sendadollar.co.nz/httpdocs/admin/adminprocess.php:15) in /var/www/vhosts/sendadollar.co.nz/httpdocs/admin/adminprocess.php on line 33

 

Warning: session_register() [function.session-register]: Cannot send session cache limiter - headers already sent (output started at /var/www/vhosts/sendadollar.co.nz/httpdocs/admin/adminprocess.php:15) in /var/www/vhosts/sendadollar.co.nz/httpdocs/admin/adminprocess.php on line 33

 

Here is the code for the pages involved:

 

<?php

/*Connect to database*/

include("../include/assorted.inc.php");

 

$connection=mysql_connect($host,$user,$password)

or die("Could not connect to the server");

$db=mysql_select_db($database,$connection)

or die("Could not connect to the database");

 

$login_name=$_POST['login'];

$password=$_POST['password'];

 

/*See if login from form exists, if so then allow user to perform tasks, else ask for login*/

$query="SELECT password FROM admin WHERE password ='$password'";

$result=mysql_query($query) or die ("Could not execute query");

$count=mysql_num_rows($result);

 

if ($count==1){

session_register("login");

session_register("password");

header("location:login_success.php");

} else {

header("location:adminlogin.php");

echo "Wrong Login name or Password";

}

 

?>

 

and here is the code for the adminprocess page:

 

<html>

<head>

<link rel="stylesheet" type="text/css" href="../css/base.css"/>

<title>Send-a-Dollar!</title>

</head>

 

<body>

<center>

<image src="../images/logo.gif" width="380" height="90">

</center>

<hr>

<p>

 

<div id="contents">

<?php

/*Connect to database*/

include("../include/assorted.inc.php");

$connection=mysql_connect($host,$user,$password)

or die("Could not connect to the server");

$db=mysql_select_db($database,$connection)

or die("Could not connect to the database");

 

$login_name=$_POST['login'];

$password=$_POST['password'];

 

/*See if login from form exists, if so then allow user to perform tasks, else ask for login*/

$query="SELECT password FROM admin WHERE password ='$password'";

$result=mysql_query($query) or die ("Could not execute query");

$count=mysql_num_rows($result);

 

 

if ($count==1){

session_register("login");

session_register("password");

header("location:login_success.php");

} else {

echo "Wrong Login name or Password";

}

?>

</div>

</body>

</html>

 

I was wondering if someone could tell me what I have done wrong. I know that somehow it is recognising the output of the header information, thus screwing up the session!  ;D

 

Thanks for any help

 

TIA

Brian  :)

 

 

 

Link to comment
https://forums.phpfreaks.com/topic/80240-session-register-problem/
Share on other sites

You have to send the register session command at the VERY START of your file:

 

<?php

session_start();

?>

 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head>

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

<title> ...

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.