I am finishing setting up my registration system and I have run into a bit of a wall. While everything works I can't seem to call the files from inside my index which contains my default template.

You can see what it's doing here
http://www.texascaching.com/index.php?page=accounts/profile

Any suggestions on how to fix this?

-Thanks

    I'm getting the following message: "...headers already sent .."
    You gotta call session_start(); before you send anything to the browser.
    I think it's a good practice to call it on the first line of your index.php script.

      Yea I knew about it had to be the first thing in the file. I was placing it at the top of each file but I forgot about the index. Makes sense though since it is actually on every page.

      So that leads me to this question. What is the effect of having it on the index. Will that restrict the home page and other content pages where you don't need to be logged in to view? I might have just read it wrong (which is a strong chance I did) but I was under the impression that you included session_start(); at the top of the pages you only needed to be logged into, is this correct? If so wouldn't putting it in the index make the entire site member only? Just curious as I haven't really found any real valuable information on just exaclty how this works. BTW, by it adding to the index it did fix those errors.

      -Thanks

        As far as I understand [FONT=Courier New]session_start()[/FONT] doesn't restrict the whole site by itself if you put it on the index.php page. I'm guessing that you're "serving" your entire site with your index.php script and you might be using [FONT=Courier New]include[/FONT]s inside this script.
        You can use [FONT=Courier New]session_start[/FONT] on every page [just have it on index.php] and if certain page is just for members then check for some special variable/value, something like: [FONT=Courier New]$_SESSION['user_id'][/FONT]. I don't know if it's the best way to do it, though. You might be putting an overhead on the server with many sessions active that are not really needed, but again, I'm not sure about this. It should work anyways.
        What I allways use to get away from problems with [FONT=Courier New]session[/FONT]s is to use Output buffering:
        [FONT=Courier New]ob_start();
        session_start();[/FONT]
        With this you won't get any of those errors that you were having, because the server won't send any html to the browser until you call [FONT=Courier New]ob_end_flush();[/FONT]
        This is really good and usefull when you get used to it, for example, you can use header's anywhere in your script without getting errors. Let's say that you want to redirect your user when you find something is wrong or the user doesn't have some privilieges at the middle of your script, you'd just use:
        [FONT=Courier New]ob_end_clean();//Delete the bufer
        header ("Location: "http://www.domain.com/index.php"); // Redirects the user
        exit(); //Quit the script[/FONT]

        You can look for more information on the functions I mentioned on the php manual.
        Hope I'm being somewhat helpfull! 😉

          a month later
          h4x0rmx wrote:

          [FONT=Courier New]ob_start();
          session_start();[/FONT]

          Very nice, have been looking for this for some time now. Seems every time I attempt any kind of redirect, sessions got in the way. 🆒

            Write a Reply...