CodeIgniter Forums
Problem with obejct in php4 - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forum-20.html)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forum-23.html)
+--- Thread: Problem with obejct in php4 (/thread-2212.html)



Problem with obejct in php4 - El Forum - 07-23-2007

[eluser]Unknown[/eluser]
Hi,
I have problem:
Quote:Fatal error: Call to a member function on a non-object in (..) system/application/libraries/Access.php on line 34

Line 34: $this->ip1 = $this->obj->session->userdata('ip_address');
Line 35: $this->ip2 = $this->obj->input->ip_address();

File access.php
Code:
<?php  if (!defined('BASEPATH')) exit('No direct script access allowed');
class Access
{
var $obj;
var $ip1;
var $ip2;
function __construct()
{
  $this->obj =& get_instance();
}
function login($user, $password)
{
  $query = $this->obj->db->query("SELECT userId, userNick FROM twp_users WHERE userNick ='$user' AND userPassword = '$password'");
  if($query->num_rows() == 1)
  {
   if ($query->result())
   {
$query = $query->row();
$user = array('userLogin' => $query->userNick,
  'userId' => $query->userId,
  'isLogged' => true);
$this->obj->session->set_userdata($user);
return true;
   }
  }
  else
  {
   return false;
  }
}
function check()
{
  $this->ip1 = $this->obj->session->userdata('ip_address');
  $this->ip2 = $this->obj->input->ip_address();
  if($this->ip1 == $this->ip2 && $this->obj->session->userdata('isLogged') == true)
  {
   return true;
  }
  else
  {
   return false;
  }
}
function logout()
{
  $user = array('userLogin' => null,
    'userId' =>null,
    'isLogged' => null);
   $this->obj->session->set_userdata($user);
   redirect('login');
}
}
?>
I think it doesn't work because i try to use on php4(on php5 work well)
I have php5 in server, but only in .php5 extension(Can`t use .htaccess with "AddType php5-cgi .php")
When i rename access.php to access.php5 doesn't work. Can I rename all files to *.php5?

Sry for my English Wink

EDIT
grr.. "function __construct()" ;D


Problem with obejct in php4 - El Forum - 07-23-2007

[eluser]James Spibey[/eluser]
I think it's because you are getting your pointer to the CI instance (get_instance()) in your constructor which doesn't work on php4 (see http://ellislab.com/codeigniter/user-guide/general/creating_libraries.html for details)