Results 1 to 10 of 10

Thread: Changing System Paths Within a Page

  1. #1
    Join Date
    Feb 2006
    Posts
    236
    Thanks
    8
    Thanked 3 Times in 3 Posts

    Default Changing System Paths Within a Page

    Hi,

    I have several directories/pages where I want to execute the same php routines. The first is on a page that includes code, and may branch to other files, also with included code, where all the included code is in the same directory (or subdirectories); code example:
    Code:
    <?php 
    	session_start(); 
    	$_SESSION['where'] = "http://earth.engr.ccny.cuny.edu/noaa/wc/Lidar/chainedmenu2.php"; 
    	include_once("inc/auth.inc.php");
    	/*echo "where = "; echo $_SESSION['where'];*/
    	$user = _check_auth($_COOKIE); 
    ?>
    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <html>
    Now, in a different directory I have a similar thing:
    Code:
    <?php 
    	session_start(); 
    	$_SESSION['where'] = "http://earth.engr.ccny.cuny.edu/noaa/wc/DailyData/chainedmenu02.php"; 
    	include_once("inc/auth.inc.php");
    	/*echo "where = "; echo $_SESSION['where'];*/
    	$user = _check_auth($_COOKIE); 
    ?>
    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <html>
    <head>
    The catch is that I want the second page to have the included code from the first, not second directory. If all is ok with the password authentication, it will take me back to the second page by redirect. The second page needs to have the path changed to be equal to what it was when running the first page before the include is done (remember that the include may also have more includes, so the path variable needs to be changed.) I'm using php 4.4.2 with Apache2.

    What system variable do I need to change and how do I change it?

  2. #2
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    You can use the chdir() function to change the working directory of a page.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  3. #3
    Join Date
    Feb 2006
    Posts
    236
    Thanks
    8
    Thanked 3 Times in 3 Posts

    Default

    I see now that it works, but am getting this: Warning: Cannot modify header information - headers already sent by (output started at /webmail/apache/htdocs/noaa/wc/DailyData/chainedmenu02.php:8) in /webmail/apache/htdocs/noaa/wc/Lidar/inc/auth.inc.php on line 32. How do I get around this? My code, so far is:
    Code:
    <?php 
    	ob_start();
    	session_start(); 
    	$_SESSION['where'] = "http://earth.engr.ccny.cuny.edu/noaa/wc/DailyData/chainedmenu02.php"; 
    	$dir = getcwd();
    	chdir('../');
    	chdir('Lidar');
    	ob_end_flush();
    	include_once("inc/auth.inc.php");
    	$user = _check_auth($_COOKIE); 
    	chdir($dir);
    ?>
    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    And the line 32 that it is complaining about in /inc/auth.php is the redirect,
    Code:
        header("Location: login.php");
    It differs only in changing the path from this, which does not generate the warning:
    Code:
    <?php 
    	session_start(); 
    	$_SESSION['where'] = "http://earth.engr.ccny.cuny.edu/noaa/wc/Lidar/chainedmenu2.php"; 
    	include_once("inc/auth.inc.php");
    	/*echo "where = "; echo $_SESSION['where'];*/
    	$user = _check_auth($_COOKIE); 
    ?>
    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    BTW, the ob_start() was an attempt to get rid of this warning by postponing the output.....(didn't work)

  4. #4
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    As you've guessed, it's because you're trying to call header() after some output has already been sent to the browser.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  5. #5
    Join Date
    Aug 2005
    Location
    Other Side of My Monitor
    Posts
    3,494
    Thanks
    5
    Thanked 105 Times in 104 Posts
    Blog Entries
    1

    Default

    Dont forget that header locations SHOULD be complete URLS ( http://somesite.com/folder/page.php ) Not just /page.php

    Also note that I have had this exact same problem, even though the ONLY thing in the php was the redirect, and there was NO error in the script, or white space or anything.

    Eventually I contacted server Admin and there was a problem on their end, which fixed it right up.
    Last edited by BLiZZaRD; 07-06-2006 at 05:28 PM.
    {CWoT - Riddle } {Freelance Copywriter} {Learn to Write}
    Follow Me on Twitter: @InkingHubris
    PHP Code:
    $result mysql_query("SELECT finger FROM hand WHERE id=3");
    echo 
    $result

  6. #6
    Join Date
    Feb 2006
    Posts
    236
    Thanks
    8
    Thanked 3 Times in 3 Posts

    Default

    Twey, could you suggest something of a fix, please tell me how? The problem is caused solely by the chdir() and no placement of ob_start() and ob_end_flush() will help out. It seems that you just can't ever do a chdir(). Likewise, full path does not solve the issue. What happens, is that the header("Location: login.php"); does not execute so the rest of the page displays, bypassing the redirect! (ugg!, then a long sigh....and I'm learning to cuss, which is not good in an academic setting.)

  7. #7
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    That's peculiar -- if you remove the chdir()s, it works?
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  8. #8
    Join Date
    Feb 2006
    Posts
    236
    Thanks
    8
    Thanked 3 Times in 3 Posts

    Default

    Ok, things seemed strange. So, I installed all of the scripts in both directories so I wouldn't get the error until I could work it out. And, of course, the problem surfaced. When I login in directory DailyData, I can access the data correctly, but when I change to the other directory, Lidar, the page won't display saying that redirect is messed up. If I then go and logout, I can then login in Lidar, but DailyData is messed up. I can finagel it so that I login in both places to access the data in both, but not through the correct links. Clearing cookies and sessions frees up both so that I can login on one, but not the other - the second should be accessed immediately because of the cookie and session, but is not.

    So, my take on it is that the session ID is not preserved across the pages accessed through the primary link. I remember something about setting SID somewhere, though, and a quick search turns up nothing yet. Is there a simple answer, I suppose that I just have not discovered it yet.

  9. #9
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    Is there a simple answer, I suppose that I just have not discovered it yet.
    My first guess, after seeing the header() error, would be that there is some data output before you call session_start().
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  10. #10
    Join Date
    Feb 2006
    Posts
    236
    Thanks
    8
    Thanked 3 Times in 3 Posts

    Default

    Data output before the session_start(); is not the problem (I think).

    This is what I now have, and the strangeness of it all. I have copied the program/page files into two directories and everything is identical except for the one line that governs the redirect back to the starting page. If I'm in Directory `DailyData`, the program goes to the login page on a fresh day (cookie(s) expired). I login and the data is accessed correctly. I then change to the `Lidar` directory, where I expect to be still logged in, and the page comes up saying redirect error. If I go back to the `DailyData` directory, I'm still logged in. Back to the `Lidar` directory I still get the same redirect error - page cannot be displayed. I logout from the `Lidar` directory, and it immediately takes me to the login page. Good so far. I login, and the `Lidar` data is accessible. Fine. I go back to the `DailyData` page and immediately access the data - I'm logged in. The converse is true if I wipe out session data and cookies, meaning whatever directory I start in, the other gives me a redirect error until I logout and back in, making both accessible.

    The code on the top of each page is this (with the exception that the one redirect location is appropriately, I think, changed):
    Code:
    <?php 
    	session_start(); 
    	$_SESSION['where'] = "http://earth.engr.ccny.cuny.edu/noaa/wc/Lidar/chainedmenu2.php"; 
    	include_once("inc/auth.inc.php");
    	$user = _check_auth($_COOKIE); 
    ?>
    The code for the login page is this:
    Code:
    <?php
    session_start();
    include_once("inc/auth.inc.php");
    _already_logged($_COOKIE);
    
    if(isset($_POST['submit']))
    {
      $user_data = _check_database(fm($_POST['user']),fm($_POST['pass']));
      if($user_data == 0) login_page();
      else _set_cookie($user_data,fm($_POST['rem']),session_id(),fm($_POST['user']));
    } else
      login_page();
    ?>
    I think the problem has something to do with the session not being acceptable to the _check_auth($_COOKIE) function, probably that the session has changed. So.....now, any ideas? I'm confused on how to keep the sessions the same. BTW, I can't find my cookie to see if the SID is changing. Where is it? (not is C:\Documents and Settings\`user`\Cookies) Any suggestions, pleeeeeze

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •