Welcome Guest, Not a member yet? Register   Sign In
sessio problem
#1

[eluser]peter34[/eluser]
i m about to learn codeigniter new. I have a session problem. I run my function but ı have a problem with session. this is the code that ı have problem with
this is index :
function index()
{
$this->output->enable_profiler(TRUE);
$this->load->helper(array('form', 'url'));
//if( !class_exists('CI_Session') ) $this->load->library('session');
//$this->session->sess_destroy();
if($this->session->userdata('izin'))
{
echo $this->session->userdata('kullanici_adi');
//$data['query']=$this->db->get('makale');
$this->load->view('ana_view');
}else
{

//redirect(site_url('login/giris_yap'));
$this->load->view('login_view');
}
}

ı redirect the code below:

function bolum_sec()
{

if($this->session->userdata('izin'))
{

if( !class_exists('CI_Form_validation') )
$this->load->library('form_validation');

$this->load->model('kullanici_model');
$data['query']=$this->db->get('bolum');
$this->form_validation->set_rules('bolum_adi', 'bolum_adi', 'required');
//$this->load->view('bolum_getir_view',$data);
if ($this->form_validation->run() == FALSE)
{
$this->load->helper('url');
$this->load->view('bolum_getir_view',$data);
}
else
{
$this->load->model('kullanici_model');
$bolum_id=$this->input->post('bolum_adi');
if($gelen_kategori['query'] = $this->kullanici_model->kategori_getir($bolum_id))
{
$this->load->view('kategori_getir_view',$gelen_kategori);

}
}
}
}
function makale_kaydet()
{
//if( !class_exists('CI_Session') ) $this->load->library('session');
if($this->session->userdata('izin'))
{

if( !class_exists('CI_Form_validation') ) $this->load->library('form_validation');

$this->load->model('kullanici_model');
$this->form_validation->set_rules('test', 'test', 'required');
$this->form_validation->set_message('required', '%s bilgisini girmelisiniz.');
if ($this->form_validation->run() == FALSE)
{
$this->load->helper('url');
redirect('login/bolum_sec');
//$this->load->view('kategori_getir_view');
}else
{
$this->load->model('kullanici_model');
$kategori_id = $this->input->post('kat_adi');
$makale=$this->input->post('test');

$kadi=$this->session->userdata('kullanici_adi');

if($this->kullanici_model->makale_ekle($kategori_id,$makale,$kadi))
{

$this->session->set_flashdata('hata', 'Başarıyla Eklendi');

$this->load->helper('url');
//$this->load->view('ana_view');
redirect('login','refresh');

}
}
}
}

but session unset and ı see again the login page
#2

[eluser]LuckyFella73[/eluser]
Would be nice if you could place CODE tags around your script.
It's no fun to read that much unformated code ..
#3

[eluser]peter34[/eluser]
Code:
function index()
  {
      $this->output->enable_profiler(TRUE);
      $this->load->helper(array(‘form’, ‘url’));
      //if( !class_exists(‘CI_Session’) ) $this->load->library(‘session’);
      //$this->session->sess_destroy();
      if($this->session->userdata(‘izin’))
      {
        echo $this->session->userdata(‘kullanici_adi’);
        //$data[‘query’]=$this->db->get(‘makale’);
        $this->load->view(‘ana_view’);
      }else
      {
      
        //redirect(site_url(‘login/giris_yap’));
        $this->load->view(‘login_view’);
      }
  }

Code:
function bolum_sec()
  {
  
      if($this->session->userdata(‘izin’))
      {
        
        if( !class_exists(‘CI_Form_validation’) )
        $this->load->library(‘form_validation’);
        
        $this->load->model(‘kullanici_model’);
        $data[‘query’]=$this->db->get(‘bolum’);
        $this->form_validation->set_rules(‘bolum_adi’, ‘bolum_adi’, ‘required’);
        //$this->load->view(‘bolum_getir_view’,$data);
        if ($this->form_validation->run() == FALSE)
        {
          $this->load->helper(‘url’);
          $this->load->view(‘bolum_getir_view’,$data);
        }
        else
        {
          $this->load->model(‘kullanici_model’);
          $bolum_id=$this->input->post(‘bolum_adi’);
          if($gelen_kategori[‘query’] = $this->kullanici_model->kategori_getir($bolum_id))
          {
              $this->load->view(‘kategori_getir_view’,$gelen_kategori);
              
          }
        }  
      }
  }
  function makale_kaydet()
  {
      //if( !class_exists(‘CI_Session’) ) $this->load->library(‘session’);
        if($this->session->userdata(‘izin’))
        {
          
          if( !class_exists(‘CI_Form_validation’) ) $this->load->library(‘form_validation’);
        
          $this->load->model(‘kullanici_model’);
          $this->form_validation->set_rules(‘test’, ‘test’, ‘required’);
          $this->form_validation->set_message(‘required’, ‘%s bilgisini girmelisiniz.’);
          if ($this->form_validation->run() == FALSE)
          {
              $this->load->helper(‘url’);
              redirect(‘login/bolum_sec’);
              //$this->load->view(‘kategori_getir_view’);
          }else
          {
              $this->load->model(‘kullanici_model’);
              $kategori_id = $this->input->post(‘kat_adi’);
              $makale=$this->input->post(‘test’);
              
              $kadi=$this->session->userdata(‘kullanici_adi’);
              
              if($this->kullanici_model->makale_ekle($kategori_id,$makale,$kadi))
              {
                
                $this->session->set_flashdata(‘hata’, ‘Başarıyla Eklendi’);
                
                $this->load->helper(‘url’);
                //$this->load->view(‘ana_view’);
                redirect(‘login’,‘refresh’);
                
              }
          }
        }
  }
[quote author="LuckyFella73" date="1299769629"]Would be nice if you could place CODE tags around your script.
It's no fun to read that much unformated code ..[/quote]
#4

[eluser]LuckyFella73[/eluser]
Thanks for using code tags now Smile

At the first glance I see you are using a variable/array in one of your
if statements that is not set:
Code:
function bolum_sec(){
// ...
// ...
if($gelen_kategori[‘query’] = $this->kullanici_model->kategori_getir($bolum_id))
// $gelen_kategori[‘query’] !

You are loading your model multiple times what is not needed. Just load your
model once in your controller constructor and it is available in your whole
controller!
#5

[eluser]peter34[/eluser]
ok ı load the model only once to my controller constructor but this is not the problem. my problem is after starting the function 'makale_kaydet' it redirects here: "$this->load->helper('url'); redirect('login','refresh');" but it again shows the login_view and session unset

[quote author="LuckyFella73" date="1299771044"]Thanks for using code tags now Smile

At the first glance I see you are using a variable/array in one of your
if statements that is not set:
Code:
function bolum_sec(){
// ...
// ...
if($gelen_kategori[‘query’] = $this->kullanici_model->kategori_getir($bolum_id))
// $gelen_kategori[‘query’] !

You are loading your model multiple times what is not needed. Just load your
model once in your controller constructor and it is available in your whole
controller![/quote]
#6

[eluser]LuckyFella73[/eluser]
Loading the model once was just a basic tip.

Please don't get me wrong but your approach seems to
be a bit unstructured.

I would recommend you to set up a login method handling
the post vars from a login form and setting a session var
like "logged = 1" or "logged = 0" depending on validation.
If "1" than save personal data of the logged user like
username or whatever you need to display on your pages in
session vars.

In all areas you need to check for a logged-in user place
code in your controller/method like
Code:
if ($this->session->userdata('logged') != 1){ /* redirect to login form */ }

I hope I didn't missunderstood what you are trying to do. For me it's not easy
to understand that because your vars and fieldnames of your input fields
are written in a language I don't know Wink
#7

[eluser]peter34[/eluser]
Code:
function index()
  {
      $this->output->enable_profiler(TRUE);
      $this->load->helper(array(‘form’, ‘url’));
      //if( !class_exists(‘CI_Session’) ) $this->load->library(‘session’);
      //$this->session->sess_destroy();
      if($this->session->userdata(‘logged’))
      {
                $this->load->view(‘homepage_view’);
      }else
      {
      
        
        $this->load->view(‘login_view’);
      }
  }

//ı redirect the code below:

function selection_select()
  {
  
      if($this->session->userdata(‘izin’))
      {
        
        if( !class_exists(‘CI_Form_validation’) )
        $this->load->library(‘form_validation’);
        
        $this->load->model(‘kullanici_model’); // this is my model
        $data[‘query’]=$this->db->get(‘bolum’);
        $this->form_validation->set_rules(‘selection_name’, ‘selection_name’, ‘required’);
        //$this->load->view(‘bolum_getir_view’,$data);
        if ($this->form_validation->run() == FALSE)
        {
          $this->load->helper(‘url’);
          $this->load->view(‘bolum_getir_view’,$data);
        }
        else
        {
      
          $bolum_id=$this->input->post(‘selection_name’);
          if($gelen_category[‘query’] = $this->kullanici_model->kategori_getir($selection_id))
          {
              $this->load->view(‘kategori_getir_view’,$gelen_category);
              
          }
        }  
      }
  }
  function article_save()
  {
      //if( !class_exists(‘CI_Session’) ) $this->load->library(‘session’);
        if($this->session->userdata(‘logged’))
        {
          
          if( !class_exists(‘CI_Form_validation’) ) $this->load->library(‘form_validation’);
        
          
          $this->form_validation->set_rules(‘test’, ‘test’, ‘required’);
          $this->form_validation->set_message(‘required’, ‘%s bilgisini girmelisiniz.’);
          if ($this->form_validation->run() == FALSE)
          {
              $this->load->helper(‘url’);
              redirect(‘login/selection_select’);
              //$this->load->view(‘kategori_getir_view’);
          }else
          {
              $this->load->model(‘kullanici_model’);
              $category_id = $this->input->post(‘cat_id’);
              $makale=$this->input->post(‘test’);
              
              $kadi=$this->session->userdata(‘username’);
              
              if($this->kullanici_model->article_add($kategori_id,$makale,$kadi))
              {
                
                $this->session->set_flashdata(‘hata’, ‘Added...’);
                
                $this->load->helper(‘url’);
                //$this->load->view(‘homepage_view’);
                redirect(‘login’,‘refresh’);
                
              }
          }
        }
  }





if ($this->session->userdata('logged') != 1)
if($this->session->userdata('izin')) (redirect homepage) (izin=logged)
this two codes are the same..

i will change this turkish vars to englishSmile)

plsss help me

[quote author="LuckyFella73" date="1299779803"]Loading the model once was just a basic tip.

Please don't get me wrong but your approach seems to
be a bit unstructured.

I would recommend you to set up a login method handling
the post vars from a login form and setting a session var
like "logged = 1" or "logged = 0" depending on validation.
If "1" than save personal data of the logged user like
username or whatever you need to display on your pages in
session vars.

In all areas you need to check for a logged-in user place
code in your controller/method like
Code:
if ($this->session->userdata('logged') != 1){ /* redirect to login form */ }

I hope I didn't missunderstood what you are trying to do. For me it's not easy
to understand that because your vars and fieldnames of your input fields
are written in a language I don't know Wink[/quote]




Theme © iAndrew 2016 - Forum software by © MyBB