Hi, all I have several small problems and if you people here could give me any help with any of them, that would be great.

I still consider myself a PHP n00b, so please bear with me.

(1) I'm making a web site for a client of mine here. And notice how the stylesheet has the word "About Us" highlighted? Well PHP tells the stylesheet to do that if the user is in that section of the site, based upon string matching. But if you click on another menu item, such as "nursing homes", or "news"... they also highlight, but only ONE is supposed to be highlighted at a time.

I'm using stristr() to check if the URL matches a string in my array. However the main index page is "index.php" and since several of the sub pages are "index.php" as well, it highlights two of them! :o

Here's some of my PHP code:

<?php
$url = $_SERVER['PHP_SELF'];
$c = 0; 
$num = 1; $num2 = 1;
/* the main topics accross the top */
 $navigation = array(  
"nav" => array('/index.php','/nursinghome/','/pressroom/','/events/','/services/','/joinacc/','/partners/'),
"link" => array('About Us','Nursing Homes','News','Calendar','Services','Join Us','Volunteer'),
); /* begin nav */ foreach($navigation['nav'] as $val) {
echo ""; if (stristr($url, $val)) { echo "<a href='". $val ."' id='gl". $num++ ."' class='active' onmouseover='ehandler(event,menuitem". $num2++ .");'>" . $navigation["link"][$c++] . "</a>\n"; } else { echo "<a href='". $val ."' id='gl". $num++ ."' onmouseover='ehandler(event,menuitem". $num2++ .");'>" . $navigation["link"][$c++] . "</a>\n"; } } /* end nav */ ?>

(2) Addtionally, my clients host has some rather strange PHP settings. They are running PHP as CGI, and I sometimes get this "No input file specified." error... Look here.

I have a ErrorDocument set inside my .htaccess file to bring up my /page404.php file but it only works SOMETIMES. So I'm not exactly sure if there is anything I can do on my end to fix this.

Thanks in advance.

    Hi,

    use $SERVER['REQUEST_URI'] instead of $SERVER['PHP_SELF'] because PHP_SELF just contains the script name which is always index.php in this case.

    "no input file specified" in most cases means that the file could not be found/read. Check the filename and the access rights on the file. It should be readable (and maybe executable in case of PHP running as CGI, can't test it now) for all.

    Please post the .htaccess file (the ErrorDocument part).

    Thomas

      Thats great thanks. But there is still a small problem. When a user is inside any of the subnav pages the section they are in is supposed to remain highlighted.

      While inside the "About Us" area, click on the "Profile" subnav. When you do that the "About Us" part is no longer highlighted anymore.

      But it should stay highlighted because they are still within that area of the site.

      http://www.accsv.org/index.php

      I have an idea which might fix this, but I just don't know how to write the PHP code 🙂

      If(PHP_SELF contains one slash '/') echo highlighted "About Us" nav item. elseif(PHP_SELF contains 2 or more slashes) echo About as it is normally. else default appearance.

      Would this work? And how can I write this??

      Also, here's the contents of my .htaccess file. I chmod the page404.php file to 777 and still got the "No input file specified." message.

      ErrorDocument 404 [url]http://www.accsv.org/page404.php[/url]
      ErrorDocument 403 [url]http://www.accsv.org/page404.php[/url]
      
      SetEnvIfNoCase User-Agent "^WebStripper" bad_bot
      SetEnvIfNoCase User-Agent "^WebWhacker" bad_bot
      SetEnvIfNoCase User-Agent "^WebZIP" bad_bot
      SetEnvIfNoCase User-Agent "^Wget" bad_bot
      SetEnvIfNoCase User-Agent "^JOC" bad_bot
      SetEnvIfNoCase Referer "accsv.org" local_ref=1
      
      DirectoryIndex index.html index.php index.htm
      

        I tried to open your site in my browser but there's just an error message on the index page and the other pages display nothing.

        Thomas

          Try something like this:

          $url = $_SERVER['PHP_SELF'];
          $path = dirname($url);
          if ($path != "/")
            $path .= "/";
          

          And change the array to

          $navigation = array(   
          "nav" => array('/','/nursinghome/','/pressroom/','/events/','/service/','/joinacc/','/partners/'),
          "link" => array('About Us','Nursing Homes','News','Calendar','Services','Join Us','Volunteer'),
          );

          Then check which menu to highlight with:

          /* begin nav */ 
          foreach($navigation['nav'] as $val) {   
          echo "";
          if ($val == $path) {
          echo "<a href='". $val."index.php' id='gl". $num++ ."' class='active' onmouseover='ehandler(event,menuitem". $num2++ .");'>" . $navigation["link"][$c++] . "</a>\n";
          } else {
          echo "<a href='". $val ."index.php' id='gl". $num++ ."' onmouseover='ehandler(event,menuitem". $num2++ .");'>" . $navigation["link"][$c++] . "</a>\n";
          } } /* end nav */

          Thomas

            Excellent! Works perfectly. Your brilliant! 😃 But, can you explain this part to me?

            $url = $_SERVER['PHP_SELF']; 
            $path = dirname($url); 
            if ($path != "/") 
              $path .= "/";
            

            I've always had a hard time trying to figure out what this operator means ".="

            Also, any clues about the "No input file specified." error? I notice it only comes up when I put in a URL that doesn't exist which ends with a ".php" extension.

            On this page here a user talks about it, but I don't really know if its something I'm able to fix or not.
            http://us2.php.net/features.commandline

              .= means string concatenation and is the short form of

              $path = $path."/";

              The code does the following:

              // get script name including path relative to DOCUMENT_ROOT
              $url = $_SERVER['PHP_SELF'];  
              // extract the path itself $path = dirname($url);
              // but the path doesn't end with / so we concatenate / // with one exception: don't concatenate / if the path is // / (or DOCUMENT_ROOT) itself. if ($path != "/")
              $path .= "/";

              About that "no input file ..." error:

              I'm not sure but setting the ErrorDocument using .htaccess should work with PHP running as CGI. But the web server configuration must allow that which can be done by setting e.g. AllowOverride All in httpd.conf. The .htaccess file will be ignored if that configuration directive is set to none.

              Thomas

                No, the .htaccess file is working okay because if you go to this URL:

                http://www.accsv.org/dgdg

                it works, but if you go to a fake URL which ends with ".php" then it does not.

                http://www.accsv.org/blah.php

                Why it does this... I have no clue. I also discovered that the host had some kind of open_basedir restriction set, so it only allowed includes from the root if they were within a certain allowed folder. One of the allowed folders was called "/tmp" (but I guess PHP is looking for this /tmp folder outside my web root, because I created a /tmp folder within my local web space and PHP says it still can't find it!)

                http://www.accsv.org/testpage.php

                This is driving me insane!!!!!!!!! :mad:

                  Create a little phpinfo() script. There should be a line with the open_basedir setting. Post the value.

                  Additonally, try to include tmp/time.php instead of /tmp/time.php

                  Thomas

                    The open_basedir setting is turned on, with only a few options... they are:

                    /u/web:/tmp:/usr/local/lib/php4

                    Also, lastly... I tried using "tmp/foo.php" and that works fine. However the SOFTWARE I'm using (Macromedia Contribute 2/3) can't render PHP includes in edit mode when they are relative like that.

                    So I'm still screwed.

                    It doesn't make sense that the server won't allow "/tmp/foo.php" ... I simply don't know what to do, and the client has recommended once that perhaps I should use ASP instead :mad:

                      I think you can use the full path to the script. The name of the include directory doesn't need to be tmp as long as it is in DOCUMENT_ROOT. Is /u/web the DOCUMENT_ROOT ? Check the phpinfo script. There should be a line showing the full path of the phpinfo script. Let's say /u/web is the DOCUMENT_ROOT and /u/web/tmp is the directory you created. In that case

                      include "/u/web/tmp/foo.php"

                      should work. But I'd suggest to have e.g. the following structure:

                      /u/web/htdocs => DOCUMENT_ROOT
                      /u/web/include => php includes
                      /u/web/cgi-bin => cgi-bin directory

                      put scripts that contain confidential data like configuration data or username/password information for database connections into the include directory.
                      Generally: put all scripts that are not requested directly into that directory. That makes it harder to view the contents of that scripts by requesting them directly.

                      Thomas

                        Write a Reply...