Help please - A PHP Error was encountered -

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
5mita
Forum Newbie
Posts: 3
Joined: Mon Feb 11, 2008 5:28 pm

Help please - A PHP Error was encountered -

Post by 5mita »

hope this is the right place to post this... juts shows my desperation...

****************
A PHP Error was encountered
Severity: Warning

Message: Cannot modify header information - headers already sent by (output started at /home/*****/public_html/****/application/config/config.php:1)

Filename: controllers/login.php

Line Number: 50
*********
here is the php code. :banghead:

Code: Select all

<?php
class Login extends Controller 
{
 
    function Intro()
        {
            parent::Controller();   
        }//end method
    
    function index()
        {
            $data       = array();//initialize array
            $this->load->model('common');
            $now        = date('Y-m-d h:i:s');//crrent date stamp
            $datas  = $this->common->basicvars();
            $data   = $datas;
            if(isset($_POST['login_submit']))//check login form submitted
                {
                    //$lang = $this->config->item('language');
                    //echo "hi";
                    $email      = trim($_POST['email']);
                    $password   = md5(trim($_POST['pass']));
                    
                    //validation is done here
                    if($email == '')
                        $error  = "Login Failed : Please give the email !";
                    elseif($password == '')
                        $error  = "Login Failed : Please give the password !";
                    else//if simple validation is over
                        {
                            $condition = "email = '$email' AND password='$password' AND user_status='active'";//creat condition for record exit query
                            $fieldName = "user_id";//filed name to be given while processing record exit function
                            //check the email and password exist
                            if(IsRecordExist4Add('users',$fieldName,$condition))
                                {
                                    $fieldList          = ' user_id ';
                                    $user_rs            = getRow('users', $fieldList, $condition);
                                    
                                    //update lat active field in users table
                                    updateRecords('users',"last_login='$now'","user_id='$user_rs[user_id]'");
                                    
                                    $_SESSION['user_id']= $user_rs['user_id'];
                                    
                                    if(isset($_SESSION['loginUrl']))
                                        {
                                            $loginUrl   = $_SESSION['loginUrl'];
                                            header("Location: ".$loginUrl);
                                        }
                                    else
                                       header("Location: home");                               }
                            elseif(getTotRec("user_id","users","email = '$email' AND password='$password' AND user_status='pending'"))
                                $error  = "Login Failed : Please activate your account!";
                            else
                                $error  = "Login Failed : Invalid email/password !";
                        }
                }//end login
            //echo site_url();
            if($error!='')
                {
            
                    $data['error']= '<table width="90%" border="0" align="center" cellpadding="0" cellspacing="0" class="splborder">
                                        <tr>
                                            <td height="41" bordercolor="#ec8a00" bgcolor="#feffcf"><span class="blktitle">'.$error.'</span><br />
                                             </td>
                                        </tr>
                                    </table>';
                }
            $data['siteUrl']        = site_url();
            $data['center_login']   = true;
            $this->smartyextended->view('login',$data);
        }//end method
}
?>
Last edited by 5mita on Tue Feb 12, 2008 3:02 am, edited 2 times in total.
dayyanb
Forum Commoner
Posts: 46
Joined: Wed Jan 23, 2008 12:34 am

Re: Help please - A PHP Error was encountered -

Post by dayyanb »

You can not set headers once you have printed output. You have done so in "config.php"
GuitarheadCA
Forum Newbie
Posts: 20
Joined: Fri Jul 13, 2007 12:59 am

Re: Help please - A PHP Error was encountered -

Post by GuitarheadCA »

You can buffer the output (which usually also solves this problem) with the ob functions. Place ob_start() at the very top of your code, and place ob_end_flush() after any header modifications have been made.
5mita
Forum Newbie
Posts: 3
Joined: Mon Feb 11, 2008 5:28 pm

Re: Help please - A PHP Error was encountered -

Post by 5mita »

after adding the ob_start() at the top as line 1 and adding ob_end_flush() the new line 51 (this was line 50 in the code i sent earlier, i am now getting the following error:

Parse error: syntax error, unexpected '}' in /home/******/public_html/********/application/controllers/login.php on line 52

so i went to that line and deleted the '}' and got the following error

Parse error: syntax error, unexpected T_ELSEIF in /home/*******/public_html/********/application/controllers/login.php on line 52

where am i going wrong? :crazy:

PS i am still learning php so please help me with the write code :oops:
GuitarheadCA
Forum Newbie
Posts: 20
Joined: Fri Jul 13, 2007 12:59 am

Re: Help please - A PHP Error was encountered -

Post by GuitarheadCA »

I bet you forgot a semicolin (;) after the function call.
5mita
Forum Newbie
Posts: 3
Joined: Mon Feb 11, 2008 5:28 pm

Re: Help please - A PHP Error was encountered -

Post by 5mita »

:oops: at the end of line 52? or wot? :banghead:

well i did just that but still the error remains
Post Reply