12 replies
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:
The page isn't redirecting properly

Firefox has detected that the server is redirecting the request for this address in a way that will never complete.


* This problem can sometimes be caused by disabling or refusing to accept
cookies.
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");
    }
#annoying #error #php
  • Profile picture of the author Backlinks Weekend
    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.
    Signature
    GET RANK FAST OR MAINTAIN YOUR #1 SPOT - Daily Web 2.0 Submission. Insanely Powerful + Rave Reviews + PROOF!
    {{ DiscussionBoard.errors[2472897].message }}
  • Profile picture of the author TheGodfather
    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..
    Signature

    TheGodfather

    Perception is reality

    {{ DiscussionBoard.errors[2473336].message }}
    • Profile picture of the author Backlinks Weekend
      Originally Posted by TheGodfather View Post

      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..
      Did you use the Firebug Net panel to see the redirect route of the website?
      Signature
      GET RANK FAST OR MAINTAIN YOUR #1 SPOT - Daily Web 2.0 Submission. Insanely Powerful + Rave Reviews + PROOF!
      {{ DiscussionBoard.errors[2474353].message }}
    • Profile picture of the author KirkMcD
      Originally Posted by TheGodfather View Post

      the script redirects to login.php
      The script you show above redirects to index.php.

      Where is grant_access called from?
      {{ DiscussionBoard.errors[2478547].message }}
  • Profile picture of the author deepakg
    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.
    {{ DiscussionBoard.errors[2484461].message }}
  • Profile picture of the author bucksuper
    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.
    Signature
    300% Traffic Return check out Trippy Wire Content Exchange! (100% FREE!)
    Trippy Wire Content Exchage Network

    Trippy Wire is looking for partners in these niches niches: Humor, Movies, Gaming, Celebrities, Entertainment, Sports, Food & Drinks, Hot Women, Technology & Transportation.
    {{ DiscussionBoard.errors[2484626].message }}
  • Profile picture of the author martinkeens
    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.
    {{ DiscussionBoard.errors[2486410].message }}
  • Profile picture of the author TheGodfather
    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.
    Signature

    TheGodfather

    Perception is reality

    {{ DiscussionBoard.errors[2488029].message }}
  • Profile picture of the author bucksuper
    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.
    Signature
    300% Traffic Return check out Trippy Wire Content Exchange! (100% FREE!)
    Trippy Wire Content Exchage Network

    Trippy Wire is looking for partners in these niches niches: Humor, Movies, Gaming, Celebrities, Entertainment, Sports, Food & Drinks, Hot Women, Technology & Transportation.
    {{ DiscussionBoard.errors[2488984].message }}
    • Profile picture of the author TheGodfather
      Originally Posted by bucksuper View Post

      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.
      did u even read the code of the grant_access()?

      it merely checks if the session variable is 1 or 0
      Signature

      TheGodfather

      Perception is reality

      {{ DiscussionBoard.errors[2490370].message }}
  • Profile picture of the author TheGodfather
    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?
    Signature

    TheGodfather

    Perception is reality

    {{ DiscussionBoard.errors[2490566].message }}
  • Profile picture of the author TheGodfather
    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?
    Signature

    TheGodfather

    Perception is reality

    {{ DiscussionBoard.errors[2495638].message }}

Trending Topics