PHP Classes

Header problem when i use login system

Recommend this page to a friend!

      DrasticTools  >  All threads  >  Header problem when i use login system  >  (Un) Subscribe thread alerts  
Subject:Header problem when i use login system
Summary:how can i avoid header error in session_start()?
Messages:5
Author:andrew apple
Date:2009-08-13 12:36:59
Update:2009-08-17 18:59:41
 

  1. Header problem when i use login system   Reply   Report abuse  
Picture of andrew apple andrew apple - 2009-08-13 12:36:59
Hi folk!

The datagrid is working nice, but now i want it to implement under a login system.

This is my index page:

<?php
session_start();

echo 'Welcome, ';

if (isset($_SESSION['k_username'])) {
echo '<b>'.$_SESSION['k_username'].'</b>.';
include("myDrasticGrid.php");
echo '<p><a href="logout.php">Logout</a></p>';
}else{
echo '<p><a href="login.php">Login</a></p>
<p><a href="registrar.php">Registrar</a></p>';
}
?>

myDrasticGrid is a copy of ExampleGrid2.php.

But i got :
Warning: Cannot modify header information - headers already sent by (output started at C:\xampp\htdocs\BorealWeb\app\grid\myDrasticGrid.php:2) in C:\xampp\htdocs\BorealWeb\app\grid\drasticSrcMySQL.class.php on line 130

Seems like i cantuse "session_start()" becaue DrasticSrcMySQL is using sessions.

any idea to implemente this under a login system?

Thanks

  2. Re: Header problem when i use login system   Reply   Report abuse  
Picture of dd dd - 2009-08-13 18:59:05 - In reply to message 1 from andrew apple
Hi Andrew,

The php code in the examplegrid2.php:
<?php
define("PATHDRASTICTOOLS", "");
include(PATHDRASTICTOOLS."Examplemysqlconfig.php");
include(PATHDRASTICTOOLS."drasticSrcMySQL.class.php");
$src = new drasticSrcMySQL($server, $user, $pw, $db, $table);
?>
must be executed first, before any other output is generated. In your case you have other code wich generates output and therefore this will imply a header error. So either move the drasticdata php code at the start, or if that is not possible, use the "path" option in the drasticgrid javascript part to define a different path for the drasticTools php class instead of calling the php file from which the javascript is called.

I hope this is understandable and help you to go on, if not, please notify us.

regards,

Drasticdata

  3. Re: Header problem when i use login system   Reply   Report abuse  
Picture of andrew apple andrew apple - 2009-08-13 21:15:44 - In reply to message 2 from dd
Hi,

Im just trying to make a "if" to show or not the grid, like:
<?php
define("PATHDRASTICTOOLS", "");
include(PATHDRASTICTOOLS."../myConfig.php");
include(PATHDRASTICTOOLS."drasticSrcMySQL.class.php");

if (isset($_SESSION['k_username'])) {
// do something or not if the user is loged
}

....

and i get the header error. I dont want to show the grid to not loged users.

  4. Re: Header problem when i use login system   Reply   Report abuse  
Picture of dd dd - 2009-08-14 08:07:33 - In reply to message 3 from andrew apple
Hi Andrew,

If you dont want to show the grid to not logged users, then just include your logic in your php file as you did and make the javascript call to drasticgrid subject to the condition you want (as you did).
And you can remove all the php stuff:
<?php
define("PATHDRASTICTOOLS", "");
include(PATHDRASTICTOOLS."../myConfig.php");
include(PATHDRASTICTOOLS."drasticSrcMySQL.class.php");

code from that php file and put it into another php file (or make a copy).
The name of that other php file should be specified in the 'path' option in the calling javascript.
You can have a look at example Examplegrid7 (two instances of the grid) to see how the 'path' option works.

This way you differentiate between the php file with your logic (which needs sessions) and the php file to be called from the drasticgrid for its data (which does not use sessions). Mixing them up causes the problems you eperience.

hope this helps,

regards, drasticdata

  5. Re: Header problem when i use login system   Reply   Report abuse  
Picture of andrew apple andrew apple - 2009-08-17 18:59:41 - In reply to message 4 from dd
OK!
Thank so much!
Problem solved just using something like "ExampleGrid7.php".

It works great.