{"id":5554,"date":"2014-04-01T02:47:39","date_gmt":"2014-04-01T02:47:39","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2014\/04\/01\/codeigniter-500-internal-server-error-closed-collection-of-common-programming-errors\/"},"modified":"2014-04-01T02:47:39","modified_gmt":"2014-04-01T02:47:39","slug":"codeigniter-500-internal-server-error-closed-collection-of-common-programming-errors","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2014\/04\/01\/codeigniter-500-internal-server-error-closed-collection-of-common-programming-errors\/","title":{"rendered":"CodeIgniter 500 Internal Server Error [closed]-Collection of common programming errors"},"content":{"rendered":"<ul>\n<li><img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/40de750233b3ce8268f235ba0b6a489b?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\nteresko<\/p>\n<p><strong>ANSWERED! IT WAS A TYPO OMG. Always check EVERY CHARACTER<\/strong><\/p>\n<p>I have three controllers, <code>Site<\/code>, <code>Login<\/code> and <code>Admin<\/code>. Site and Login work perfectly. I know I am logging in correctly, because I set the &#8220;incorrect username&#8221; blah blah error message, which shows up if I have incorrect login details. When I log in successfully however, I get a 500 Internal Server Error:<\/p>\n<p><code>HTTP Error 500 (Internal Server Error): An unexpected condition was encountered while the server was attempting to fulfill the request.<\/code><\/p>\n<p>Here&#8217;s the admin controller:<\/p>\n<pre><code>function __construct()\n    {\n        parent::Controller();\n        $this-&gt;isLogged();\n    }\n\n    function isLogged()\n    {\n        $isLogged = $this-&gt;session-&gt;userdata('isLogged');\n\n        if (!isset($isLogged) || $isLogged != true)\n        {\n            redirect('login\/index');\n        }\n    }\n\n    function index()\n    {\n        $data['metaDescription'] = 'Admin area of danaemc.com';\n        $data['keywords'] = '';\n        $data['title'] = 'danaemc :: admin :: home';\n\n        $data['main_content'] = 'admin_view';\n        $this-&gt;load_view('includes\/admin_template', $data);\n    }\n<\/code><\/pre>\n<p>In which where it tries to access <code>index()<\/code>, the 500 error happens.<\/p>\n<p>If you need more code, let me know in a comment. I hope it is something obvious.<\/p>\n<\/li>\n<li><img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/cda115fb749159ff9676b03f87df34cf?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\nDamien Pirsy<\/p>\n<p>Looks like a problem with your function that checks login. From the code you provide, I see this workflow:<\/p>\n<ul>\n<li>User is not logged: he&#8217;s redirected to login\/index and logs in.<\/li>\n<li>I suppose then he&#8217;s redirected to admin controller, right? (when succesfully logged). Ok, now when admin controller is initialized it checks, within the controller itself, if the user is logged.<\/li>\n<li>It is, ok, but you don&#8217;t tell it to go to some other page if the user is logged, so: you go to admin\/index, but the constructor &#8220;intercepts&#8221; your request BEFORE it being routed (since the constructor is called as soon as the class is initialized, before the index() method is ever reached), and it hangs there: index() is called from the URL but the request doesn&#8217;t go past isLogged(), and this discrepancy can cause you those troubles (I had a similar problem once).<\/li>\n<\/ul>\n<p>You should do like this instead of using a controller&#8217;s method:<\/p>\n<pre><code>function __construct()\n{\n       parent::__construct();   \/\/what is parent::Controller() you wrote??\n      if(!isset($this-&gt;session-&gt;userdata('isLogged')) OR $this-&gt;session-&gt;userdata('isLogged') == FALSE)\n      {\n         redirect('login', 'refresh'); \/\/ 'login\/index' should be automatically called\n      }\n\n}\n<\/code><\/pre>\n<p>Moreover, as a side note, I&#8217;d do this check in some method in a library, and have it just return TRUE\/FALSE and use that in my controller&#8217;s constructor. Like<\/p>\n<pre><code> function __construct()\n {\n   parent::__construct();\n   if(FALSE === $this-&gt;myauthlibrary-&gt;is_logged())\n   {\n     redirect('login','refresh');\n   }\n }\n<\/code><\/pre>\n<p>This just for the sake of business logic and encapsulation, but it&#8217;s just an idea and an advice.<br \/>\nIf you still want to use the isLogged() of your Controller (but in this way every controller that checks for login needs is own method&#8230;) just put an ELSE clause, that redirects to index() if the checking gives positive response.<\/p>\n<p><strong>Edited after comment:<\/strong><\/p>\n<p>By chance are you calling a favicon in your meta tags? or whatever url you have? Did you spelled it RIGHT? And don&#8217;t have a <code>href=\"http:\/\/mysite\/favicon_ico\"<\/code>, which CI things is a controller?<\/p>\n<\/li>\n<li><img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/fc411bbef88e5f643bfec258feed13a9?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\nWesley Murch<\/p>\n<p>You have an infinite redirect loop.<\/p>\n<p><code>isLogged()<\/code> is run in <code>__construct()<\/code> before <code>index()<\/code>, so it keeps redirecting as long as your session data isn&#8217;t met.<\/p>\n<p>Another thing: <code>!isset($isLogged)<\/code> will <em>always<\/em> return false, because <code>$this-&gt;session-&gt;userdata()<\/code> will return boolean <code>FALSE<\/code> if there is no value, which <em>is<\/em> set. Make sense?<\/p>\n<p><code>$this-&gt;session-&gt;userdata('anything')<\/code> is always &#8220;set&#8221;.<\/p>\n<p>Quick fix, assuming &#8220;index&#8221; is your login page in the same controller:<\/p>\n<pre><code>function isLogged()\n{\n    $isLogged = $this-&gt;session-&gt;userdata('isLogged');\n    $isLoginPage = $this-&gt;router-&gt;method === 'index';\n\n    if ( ! $isLogged &amp;&amp; ! $isLoginPage)\n    {\n        redirect('login\/index');\n    }\n}\n<\/code><\/pre>\n<p>Also, make sure to redirect somewhere else <em>from<\/em> your login page if the user <em>is<\/em> logged in.<\/p>\n<\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>teresko ANSWERED! IT WAS A TYPO OMG. Always check EVERY CHARACTER I have three controllers, Site, Login and Admin. Site and Login work perfectly. I know I am logging in correctly, because I set the &#8220;incorrect username&#8221; blah blah error message, which shows up if I have incorrect login details. When I log in successfully [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-5554","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/5554","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/comments?post=5554"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/5554\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=5554"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=5554"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=5554"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}