0

I am developing an application on codeigniter whenever i try to visit the business controller it redirects to login page. This is the url http://www.atms.com.au/index.php/business. I cant find where the check for session variable is made for login This is the controller

<?php
class Business extends Controller
{
    function Business()
    {
        parent::Controller();
        $this->load->model('members_model');
    }

    function index()
    {
        $this->session->set_userdata( $this->session_name, true) ;
        $this->session->set_userdata( "atms_member_login_id", $this->login_id);
        if($this->input->post('submit_business_info'))
        {           
            $business_name = $data['business_name'] = $this->input->post('business_name');
            $data['business_description'] = $this->input->post('description');
            $data['status'] = '1';

            if($_FILES['business_logo']['name'])
            {
                $prev_image = $this->input->post('prev_image');
                $logo = upload_image('business_logo', $this->config->item('business_logo_root'), array('dest' => $this->config->item('business_logo_root'), 'size' => array('w' => 127, 'h' => 127), 'ratio' => false), $prev_image);

                if($logo)
                    $data['business_logo'] = $logo;
                else
                    $data['business_logo'] = $prev_image;
            }

            $this->general_db_model->update('atms_members_info_tmp', $data, 'member_id = '.member_id());

            $member_detail = $this->general_db_model->getMemberDetail('atms_members_info', member_id());
        //debug_array($member_detail);
            $clinics = $this->input->post('clinic');

            if(!empty($clinics))
            {

                foreach($clinics as $key=>$clinic)
                {

                    if(array_values_exist($clinic))
                    {       

                        if($clinic_id = $clinic['clinic_id'])
                        {

                            unset($clinic['clinic_id']);
                            $this->general_db_model->update('atms_members_clinic_info_tmp', $clinic, 'clinic_id = '.$clinic_id);

                            $data['provider_no'] = 'updated';
                            $this->general_db_model->update('atms_members_info_tmp', $data, 'member_id = '.member_id());

                                        }
                                    else
                                {
                                $clinic['member_id'] = member_id();
                            $this->general_db_model->insert('atms_members_clinic_info_tmp', $clinic);
                            $data['provider_no'] = 'updated';
                            $this->general_db_model->update('atms_members_info_tmp', $data, 'member_id = '.member_id());

                        }
                    }
                }

                    $link = site_url()."/admin/members/update_details/".$member_detail->id;
                    $message = '';
                    $message.= 'Dear '.$business_name.',<br/><br/>';
                    $message.= $business_name.' had update business listing. So please approve it.<br/>';   
                    $message.= " Link: <a href='".$link."' > Update Link</a><br/>";             
                    $message.= 'Thank You.<br/>';                               
                    $subject = "Approve Update business listing.";

                    //$to = $this->settings->item('admin_email');
                    $to = $this->settings->item('admin_email');
                    $from =$member_detail->email;
                    //die($message);
                    $header = config_item('project_title');     

                    $this->my_library->send_email($to , $subject, $message, $header, $from);

            }

            $this->session->set_flashdata('success_message', 'Your business details successfully updated. Note: your updates must be approved by the administrator before displaying on the site.');
            redirect(current_url());
            die();
        }


        $data['info'] = $this->members_model->get_member_details(member_id());
        $data['clinics'] = $this->members_model->get_member_clinics(member_id());       
        $this->load->view('site/member/business_v', $data);
    }
}
?>

and this is the view

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <?php $this->load->view('site/inc/head');?>
</head>
<body>
<div id="wrapper">
  <div id="headerWrapper">
    <div id="header">
      <div class="top">
        <?php $this->load->view('site/inc/header');?>
      </div>
      <div id="menu">
        <?php $this->load->view('site/inc/menu');?>
      </div>
      <div id="bannerIn" class="">
        <h1>Update My Details</h1>
      </div>
    </div>
  </div>
  <!-- end #header -->
  <div id="pageWrapper">
    <div id="page" class="clf">
      <div id="content">
        <div class="wideForm">
        <?php 
            global_message();
        ?>
        <form method="post" enctype="multipart/form-data" id="businessForm" name="businessForm">
        <ul class="clf">
            <li>
              <label>Business Name</label>
              <div class="inpWrapwide">
                <input type="text" class="text" name="business_name" id="business_name" value="<?php echo $info->business_name;?>" />
              </div>
            </li>
            <li>
              <label>Add Logo</label>

                <div class="inpWrap file">
                    <input type="file" name="business_logo" id="addlogo" value="<?php echo $info->business_logo;?>" />
                    <input type="hidden" name="prev_image" value="<?php echo $info->business_logo;?>" />

                </div>
                <div style="padding:5px;"><em><?php echo $info->business_logo;?></em></div>
            </li>
            <li>
              <label>Description</label>
              <div class="txtWrap">
                <textarea name="description" rows="4" cols="60"><?php echo $info->business_description;?></textarea>
              </div>
            </li>
            <?php 
            $count = 1;
            if(count($clinics) > 0) : 
                    foreach($clinics as $key=>$clinic):
            ?>
            <div id="clinic_<?php echo $count;?>">
                <li>
                    <h3 style="float:left;">Clinic <?php echo $key+1;?></h3>
                    <input type="hidden" name="clinic[<?php echo $count;?>][clinic_id]" value="<?php echo $clinic->clinic_id;?>" />
                    <span style="padding-left:10px;"><a href="javascript:;" onclick="removeClinic(<?php echo $count;?>, <?php echo $clinic->clinic_id;?>);" class="remove_clinic"><img src="<?php echo config_item('site_images');?>close.gif" /></a></span>
                </li>
                <li class="split">
                <dl class="clf">            
                <dd>
                    <label>Address 1</label>
                    <div class="inpWrap">
                        <input type="text" class="text" name="clinic[<?php echo $count;?>][clinic_address_1]" value="<?php echo $clinic->clinic_address_1;?>" />                
                    </div>
                </dd>
                <dd class="lastItem">

                    <label>Address 2</label>
                   <div class="inpWrap">
            <input type="text" class="text" name="clinic[<?php echo $count;?>][clinic_address_2]" value="<?php echo $clinic->clinic_address_2;?>" />                                        
                   </div>
                </dd></dl>
                </li>
                <li class="split">
                <dl class="clf">            
                <dd>
                    <label>Suburb</label>
                    <div class="inpWrap">
                        <input type="text" class="text" name="clinic[<?php echo $count;?>][clinic_suburb]" value="<?php echo $clinic->clinic_suburb;?>" />                
                    </div>
                </dd>
                <dd class="lastItem">
                    <label>State</label>

                     <?php echo select_states('clinic['.$count.'][clinic_state_id]', $clinic->clinic_state_id);?>                                       

                </dd></dl>
                </li>

                <li class="split">
                <dl class="clf">            
                <dd>
                    <label>Postcode</label>
                    <div class="inpWrap">
                        <input type="text" class="text" name="clinic[<?php echo $count;?>][clinic_postcode]" value="<?php echo $clinic->clinic_postcode;?>" />                
                    </div>
                </dd>
                <dd class="lastItem">
                    <label>Phone</label>
                    <div class="inpWrap">
                        <input type="text" class="text" name="clinic[<?php echo $count;?>][clinic_telephone]" value="<?php echo $clinic->clinic_telephone;?>" />                
                    </div>
                </dd></dl>
                </li>
                <li class="split">
                <dl class="clf">            
                <dd>
                    <label>Mobile</label>
                    <div class="inpWrap">
                        <input type="text" class="text" name="clinic[<?php echo $count;?>][clinic_mobile]" value="<?php echo $clinic->clinic_mobile;?>" />                
                    </div>
                </dd>
                <dd class="lastItem">
                    <label>Email</label>
                    <div class="inpWrap">
                        <input type="text" class="text" name="clinic[<?php echo $count;?>][clinic_email]" value="<?php echo $clinic->clinic_email;?>" />                
                    </div>
                </dd></dl>
                <dl class="clf">            
                <dd>
                    <label>Website</label>
                    <div class="inpWrap">
                        <input type="text" class="text" name="clinic[<?php echo $count;?>][clinic_website]" value="<?php echo $clinic->clinic_website;?>" />                
                    </div>
                </dd>
                </dl>
                </li>
            </div>
            <?php $count++; endforeach; ?>    
            <?php else: 
            ?>
            <div>
                <li>
                    <h3>Clinic 1</h3>
                </li>
                <li class="split">
                <dl class="clf">            
                <dd>
                    <label>City</label>
                    <div class="inpWrap">
                        <input type="text" class="text" name="clinic[<?php echo $count;?>][clinic_address_1]" value="" />                
                    </div>
                </dd>
                <dd class="lastItem">
                    <label>State</label>
                    <div class="inpWrap">
                        <?php echo select_states('clinic['.$count.'][clinic_state_id]');?>

                    </div>
                </dd></dl>
                </li>
                <li class="split">
                <dl class="clf">            
                <dd>
                    <label>Postcode</label>
                    <div class="inpWrap">
                        <input type="text" class="text" name="clinic[<?php echo $count;?>][clinic_postcode]" value="" />                
                    </div>
                </dd>
                <dd class="lastItem">
                    <label>Phone</label>
                    <input type="text" class="text" name="clinic[<?php echo $count;?>][clinic_telephone]" value="" /> 
                </dd></dl>
                </li>
                <li class="split">
                <dl class="clf">            
                <dd>
                    <label>Mobile</label>
                    <div class="inpWrap">
                        <input type="text" class="text" name="clinic[<?php echo $count;?>][clinic_mobile]" value="" />                
                    </div>
                </dd>
                <dd class="lastItem">
                    <label>Email</label>
                    <div class="inpWrap">
                        <input type="text" class="text" name="clinic[<?php echo $count;?>][clinic_email]" value="" />                
                    </div>
                </dd></dl>
                </li>
                <li class="split">
                <dl class="clf">            
                <dd>
                    <label>Website</label>
                    <div class="inpWrap">
                        <input type="text" class="text" name="clinic[<?php echo $count;?>][clinic_website]" value="" />                
                    </div>
                </dd>
                </dl>
                </li>
            </div>  
            <?php $count++;?>  
            <?php endif; ?>

            <div id="new_clinics">
                <!--appends new clinics here-->
            </div>
          </ul>

           <input type="button" class="add_clinic" value="Add more clinic" name="add_clinic" />
           <div class="buttons clf">
                <input type="button" class="cancel" value="cancel" onclick="window.location = '<?php echo current_url();?>';" />
                <input type="submit" class="update" value="update" name="submit_business_info" />
           </div>
        </form>
      </div>
      </div>
      <!-- end #content -->
      <div id="sidebar">
        <?php $this->load->view('site/inc/login_sidebar');?>
      </div>
      <!-- end #sidebar --> 

    </div>
  </div>
  <!-- end #page --> 
</div>
<div id="footerWrapper">
  <div id="footer">
    <?php $this->load->view('site/inc/footer');?>
  </div>
</div>
<!-- end #footer --> 


<textarea style="display:none;" id="template">
<div class="transform" id="clinic_{0}">
    <li>
        <h3 style="float:left;">Clinic {0}</h3>
        <span style="padding-left:10px;"><a href="javascript:;" onclick="removeClinic({0});" class="remove_clinic"><img src="<?php echo config_item('site_images');?>close.gif" /></a></span>
    </li>
    <li class="split">
    <dl class="clf">            
    <dd>
        <label>City</label>
        <div class="inpWrap">
            <input type="text" class="text" name="clinic[{0}][clinic_address_1]" value="" />                
        </div>
    </dd>
    <dd class="lastItem">
        <label>State</label>
        <div class="inpWrap">
           <?php echo select_states('clinic[{0}][clinic_state_id]');?>               
        </div>
    </dd></dl>
    </li>
    <li class="split">
    <dl class="clf">            
    <dd>
        <label>Postcode</label>
        <div class="inpWrap">
            <input type="text" class="text" name="clinic[{0}][clinic_postcode]" value="" />                
        </div>
    </dd>
    <dd class="lastItem">
        <label>Phone</label>
        <div class="inpWrap">
       <input type="text" class="text" name="clinic[{0}][clinic_telephone]" value="" /> 
       </div>         
    </dd></dl>
    </li>
    <li class="split">
    <dl class="clf">            
    <dd>
        <label>Mobile</label>
        <div class="inpWrap">
            <input type="text" class="text" name="clinic[{0}][clinic_mobile]" value="" />                
        </div>
    </dd>
    <dd class="lastItem">
        <label>Email</label>
        <div class="inpWrap">
            <input type="text" class="text" name="clinic[{0}][clinic_email]" value="" />                
        </div>
    </dd></dl>
    </li>
     <li class="split">
    <dl class="clf">            
    <dd>
        <label>Website</label>
        <div class="inpWrap">
            <input type="text" class="text" name="clinic[{0}][clinic_website]" value="" />                
        </div>
    </dd>
    </dl>
    </li>
</textarea>


<script type="text/javascript">

jQuery(document).ready(function(){
    jQuery('.bannerLinks a').wrapInner('<span></span>');
     $("input[type=file]").filestyle({ 
     image: "<?php echo config_item('site_images');?>browse.gif",
     imageheight : 22,
     imagewidth : 68,
     width : 250
 });
 jQuery('.file div').hover(function(){
     //var _b = jQuery(this).attr("background");
     //jQuery(this).css("background","<?php echo config_item('site_images');?>browse_h.gif");
     }, function(){
         //jQuery(this).css("background","<?php echo config_item('site_images');?>browse.gif");
     });

    $("#businessForm").validate();  

    var template = jQuery.format($("#template").val());
    function addClinic() {
        $(template(i++)).appendTo("div#new_clinics");
        $('div.transform').jqTransform({imgPath:'<?php echo config_item('site_asset');?>jqtransform/img/'});
    }

    var i = <?php echo $count;?>;

    $(".add_clinic").click(addClinic);
});

function removeClinic(index, cid)
{
    if(cid)
    {
        if(confirm('Are You Sure?'))
        {
            $.post('<?php echo admin_url('members/remove_clinic_tmp');?>', {clinic_id : cid}, function(data){});
        }
        else
            return false;
    }

    $('div#clinic_'+index).remove();

}

</script>
</body>
</html>

I am frustrated finding where the login check is made. can anyone help me Thanks

9
  • 3
    Please debug using die, line by line to find out from which line its redirect to login page let me know the result Commented Nov 15, 2012 at 6:15
  • Might be in the constructor of the parent class. I don't know the structure of that old CI version, it could be under system/core. ALso, if they had hooks in that version, it could be a pre_controller hook behing called to check the session Commented Nov 15, 2012 at 6:19
  • you are loading members_model and then accessing general_db_model... possible issue? in most such cases it is a silent death. things are being redirected to some other page possible as a default error handling configuration lower down in apache. Commented Nov 15, 2012 at 6:29
  • 2
    Please for Constructor name use __construct function, not same as class name - Business.. If you run/update your PHP on latest 5.3/5.4 this may be a problem! You have to debug yourself to find out where is your problem, as @Elby said its best to use exit()/die and to find out where is that redirecting coming from. ! At CI you should be extending CI_Controller not Controller. Commented Nov 15, 2012 at 6:52
  • @Svetlio your last sentence is true only for the later version of CI (>2), older versions extend the Controller class Commented Nov 15, 2012 at 8:09

1 Answer 1

3

My suggestion is to go and have a look into the main Controller in the application/core. Maybe the Controller class is extended right there. Moreover, as it was also said, convert the old-style constructor to PHP 5+ __construct(). Try to set some breakpoints into your application to see where it goes and where it doesn't. I think that it should be related to an extension to the core controller.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.