CodeIgniter Forums
Login Function Works Locally But Not When Live? - 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: Login Function Works Locally But Not When Live? (/thread-26640.html)

Pages: 1 2


Login Function Works Locally But Not When Live? - El Forum - 01-19-2010

[eluser]JamesTaylor[/eluser]
I am using the following code to check whether a user is logged in, it works as expected when used in the local environment but now i have uploaded the site to a temporary live location it doesn't work?

Whats strange is that i'm sure this work previously when i had uploaded to a temporary live location and the code hasn't been changed since?? That could just be an issue i didn't notice at the time but it would be a pretty big thing to miss!

Code:
class Home extends MY_Controller {

//Makes check for logged in run each time
    function __construct(){
    parent::MY_Controller();    
    
    $this->checklogin();
        
    $this->output->set_header('Last-Modified: ' . gmdate("D, d M Y H:i:s") . ' GMT');
    $this->output->set_header('Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0');
    $this->output->set_header('Pragma: no-cache');
    $this->output->set_header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');    
    }    
    
//Check Session data to see if logged in    
    function checklogin()
    {
    $admin_is_logged_in = $this->session->userdata('admin_is_logged_in');
    
    if(!isset($admin_is_logged_in) || $admin_is_logged_in !=true)
        {
            redirect("Admin/LogIn");
        }
    }

It seems that at present the when view in the live location none of the code function __construct() is actually run as if i place an echo value anywhere within it nothing is returned, yet when i do this locally the echo value is written as the 1st thing on the page??

Can anyone point out my wher emy mistake is here?


Login Function Works Locally But Not When Live? - El Forum - 01-19-2010

[eluser]mattpointblank[/eluser]
Is your cookie domain setting in your config/config.php file the same on your remote server? Maybe it can't create the userdata to check?


Login Function Works Locally But Not When Live? - El Forum - 01-19-2010

[eluser]cahva[/eluser]
If the __construct() method is not run, maybe the liveserver is only PHP 4? If this is the case, you need to move the site to server with PHP 5 or change the class code to be compatible with PHP 4. I suggest to move the site to a decent server as PHP 4 is not supported anymore.


Login Function Works Locally But Not When Live? - El Forum - 01-19-2010

[eluser]JamesTaylor[/eluser]
Thanks for the suggestions,

matt, i haven't set a cookie domain? i didn't do this previously and as i say i'm sure worked?? But i have tried setting one and uploaded to live environment with no difference? The site is currently at a temp address which is http://IP.ADD.RE.SS/domain.co.uk/index.php/Admin/Home so i am presuming that the correct cookie domain would be IP.ADD.RE.SS/domain.co.uk or domain.co.uk - i have tried both ways with no joy, can you comfirm if i'm implementing this correctly?

cahva, the server should bee running PHP5, by default it runs PHP 4 but i have the option to switch to 5 which i have done, i can't see a way to verify that it is running v5 however? how would i make the code php 4 compatible so i can run a quick test?

sorry to ask basic questions regarding the help you have given but i'm still on the learning curve with many of these issues!

Thanks again


Login Function Works Locally But Not When Live? - El Forum - 01-19-2010

[eluser]Vikeoar[/eluser]
James

You can use the phpinfo() function on a test page to view the version and configuration of the live server installation. When you're done checking delete this page from the server though.


Login Function Works Locally But Not When Live? - El Forum - 01-19-2010

[eluser]mattpointblank[/eluser]
Hi James,

Easiest way to check your version of php is to put this code in a file and run it:

Code:
<?php
phpinfo();
?>

This will give you a big page of data, with a version number somewhere near the top. Have a look on both your local and remote site and see if there's any difference - this sounds more probable than my suggestion, which depended on you already having something in your cookie domain config (it should just work if it's blank).


Login Function Works Locally But Not When Live? - El Forum - 01-19-2010

[eluser]cahva[/eluser]
Easiest way to see the environment you are in is to create a script with contents like this:
Code:
<?php
phpinfo();
?>

Difference between PHP 4 and PHP 5 constructor is that in PHP 5 its __construct() and in PHP 4 its the same name as the class. Heres the difference in code:
Code:
// PHP 4
class Home extends MY_Controller {

    // Constructor
    function Home()
    {
        parent::MY_Controller();
    }
}

// PHP 5
class Home extends MY_Controller {

    // Constructor
    function __construct()
    {
        parent::__construct();
    }
}

I suspected that you are on PHP 4 server if nothing in your constructor is executed.


Login Function Works Locally But Not When Live? - El Forum - 01-19-2010

[eluser]JamesTaylor[/eluser]
Thanks for the quick replys again,

I have run
Code:
<?php
phpinfo();
?>

and it shows that the server is running PHP 5.2.11......

But strangely enough the pages have started to work as expected now? I think what may have happened is that there have been some problems with the server (i've looked at the service status page the hosting company provide and it say there have been some 'adverse performance issues' which are currently being looked into) perhaps this has meant that its been temporarly rolled back to PHP 4 so my constructors weren't executing???

I'm very confident that this function worked previously and i haven't changed anything... so why the problems this time?

I'm kinda questioning my sanity now!!

Anyway thanks for your help people... apologies also as i may have been time wasting?!

Cheers

James


Login Function Works Locally But Not When Live? - El Forum - 01-19-2010

[eluser]mattpointblank[/eluser]
Not time wasting - you've learned to use phpinfo (useful for lots more than just version numbers), so we're happy to help. You might be right about the 'adverse performance issues' too... who knows! One of the mysteries of web dev...


Login Function Works Locally But Not When Live? - El Forum - 01-19-2010

[eluser]JamesTaylor[/eluser]
another quick thought if my theory is in anyway correct...

if the server was temporarly rolled back to PHP4 whilst they were checking performance issues that could have caused a serious security issue where login features such mine require PHP5 which is worring? To be fair mine isn't that critical in this occasion, perhaps that just come with the ground on shared hosting?