Annoying PHP error

by 12 replies
14
I have an annoying problem:

I have created a website a few months back. After about a month or so, I've created the version 2.0 of the site, upgrading the site to the OOP model and adding some finesse.

Now the problem seams simple, but it's damn frustrating.

I have a function that regulates access to certain parts of the site based on a session variable. The script works perfectly on the 1.0 version of the site, but gives me a:
type of error when i try to open the index page.

The problem is: I've literally copied the script to the 2.0 version, and I've organized the require_once files as they are in the 1.0 header file... and it's giving me trouble.

One thing I've noticed is: if I switch the position on where the script is included, then I usually get an error that at another script (not even related to index.php) has an error and that the script is calling an undefined function (but the function is defined).

Any insight to what may be the error?

This is the script that checks the session file to grant access:

Code:
   session_start();
    
    ini_set('session.gc_maxlifetime', '86400');
    ini_set('session.cookie_lifetime', '86400');
    
    function logged_in()
    {
        return $_SESSION['logged_in'];
    }
    
    function grant_access()
    {
        if(!logged_in())
            header("Location: index.php");
    }
#programming #annoying #error #php
  • The error you are getting deal with redirection in your script. I doubt that the header("Location: index.php") is causing a problem. For example, if you get into index.php, it checks for logged_in(), right? If logged_in is false, it then redirects to index.php again and again. I think in the header code, you should try to redirect it to somewhere else to see whether the problem still retain.
  • the script redirects to login.php

    and the script is additionally included to parts of the site where it's needed.

    also it's not on index, and it doesn't check the login on the "public access" parts of the site..
    • [2] replies
    • Did you use the Firebug Net panel to see the redirect route of the website?
    • The script you show above redirects to index.php.

      Where is grant_access called from?
  • You need to just Check your script again, i think there is an error that's why you getting deal with redirection in your script.
  • Firefox pops that error on endless loops. Sounds like you bustit something :-)
    Wish I could be more helpful but I can tell you this...

    I bet by now you've fixed it and it was something simple... I've found that problems that have me ready to post on forums always require a couple of hours of sleep then o fix them in 30 seconds lol.
  • You'll need to provide more code than what you gave above for anyone to really shed any light on this issue. I also suggest that you get the Live HTTP Headers plugin for Firefox. You can watch what page your site is trying to request as it happens.

    Interestingly, I actually ran in to a similar problem recently on a site using Zend. There was one place where the code used a header("Location: ...") style redirect instead of the Zend framework redirect, and it was failing. I changed it to use the Zend redirect and it started working.
  • Code:
    <?php
    require_once("includes/session_settings.php");
    require_once("includes/header.php");
    grant_access();
    ?>
    here goes the rest of the site...
    This is how it looks like on the pages that have the grant_access() function...

    this is how it's organized in the 1.0 version f the code, and it works, ever since I've switched to OOP model i've been getting such errors.
  • Well if header.php outputs anything to the browser and gran_access() writes cookies you'll have a problem since you can't create cookies after output is sent to the browser.
    • [1] reply
    • did u even read the code of the grant_access()?

      it merely checks if the session variable is 1 or 0
  • well since this is getting really on my nerves here is an idea I've had:

    Since i must maintain some of the sensitive data in sessions i.e. files stored on the server, I was thinking of making a workaround in such a way that i'd store the information in separate XML files and then just parse them and edit them as needed... they would be given random names and the name would be stored in a cookie...

    What do you think?
  • Here is another error that occurs:

    i have multiple classes on my website, and they are all separated in different files.

    Now the error i'm getting is: even though the class is defined it's telling me that class Message is not defined, but if i put a code snippet that goes like this:

    Code:
    if(class_exists("Message"))
    then i can get it to work with out problems.

    Also a strange thing is happening: every time I open index.php I get the message.php open saying there is an error on it.

    NOTE: the index.php is not even linked to the message.php

    Any bright ideas on this one?

Next Topics on Trending Feed

  • 14

    I have an annoying problem: I have created a website a few months back. After about a month or so, I've created the version 2.0 of the site, upgrading the site to the OOP model and adding some finesse.