SitePoint Sponsor

User Tag List

Results 1 to 11 of 11
  1. #1
    SitePoint Member
    Join Date
    Aug 2007
    Posts
    7
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    PHP cannot read files at all.

    I recently setup a testing server on my windows comp (production is on linux) because I was tiredof uploading and running database modifications when I workedon something.

    So I downloaded Apache and PHP and set it up. I had to mess with PHP a little to get it to work, but phpinfo(); went off just fine and I was happy.

    Until today. Unsure how PHP's MySQLi handled a DESC statement, I wrote off a short test program that needed to require() a general function php. That was 7 hours ago. It never worked.

    I wrote some debug statements - here is the php file
    PHP Code:
     print "Read Opening"
     
    //test php 
      
     
    $myfile "C:\webroot\chardisp\genfunc.php"
     print 
    is_file($myfile); 
     
    clearstatcache(); 
     print 
    is_readable($myfile); 
     
    clearstatcache(); 

     print 
    "Preparing to require"
     require 
    $myfile
     print 
    "..."
      
     
    $dbconn connectdb(); 
     print 
    "Am I even running?"
     
    $result $dbconn->query("DESCRIBE rpchar curr_msve"); 
     
    print_r($result); 
     
    $dbconn->close(); 

    I get this for output
    "Read Opening11Preparing to require" and it then fails silently.

    Running it in the standalone executable gets the same. The errors.txt file records no error emssages, and it is set to E_STRICT.

    Nor does Apache record anything. I tried filegetcontents(); but it too, failed silently. What's going on here?

    PHP.ini's include path is ".;" and I'm running Apache 2.2.4/PHP 5.2.3 (PHP as a module, Apache runing under Local Service)
    Last edited by Tokorona; Aug 11, 2007 at 14:22. Reason: Dummy statement.

  2. #2
    . shoooo... silver trophy logic_earth's Avatar
    Join Date
    Oct 2005
    Location
    CA
    Posts
    9,013
    Mentioned
    8 Post(s)
    Tagged
    0 Thread(s)
    require is not failing silently. If it failed you would get a fatal error so there is no problem there.

    What is the code in the include file?

    PHP Code:
    <?php

    header
    ('content-type: text/plain');

    print 
    "Bring in a new file\n\n";

    require 
    './test.php';
    #require './bad_test.php';

    print $test;
    PHP Code:
    <?php

    print "Inside Test file\n\n";

    $test 'Mew';
    Logic without the fatal effects.
    All code snippets are licensed under WTFPL.


  3. #3
    SitePoint Member
    Join Date
    Aug 2007
    Posts
    7
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Well. Failing Silently may not be the best term. But PHP stops executing at this point.

    I've commented out all of the include file before, but here it is:

    PHP Code:
    <?php
      
    print "I am included.";
      
      function 
    writeHTMLHeader()
       {
        print 
    "\<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>\n";
        print 
    "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.1//EN\" \n";
        print 
    "  http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd\">\n";
        print 
    "<html xmlns=\"http://www.w3.org/1999/xhtml\" xml:lang=\"en\">\n";
       }

        function 
    connectdb()
        {
            
    $dbconn = new mysqli($dbserver$dbuser$dbpass$dbname);

            
    /* check connection */
            
    if (mysqli_connect_errno()) {
                
    printf("Connect failed: %s\n"mysqli_connect_error());
                exit();
            }
            
    //connection made. Return the object
            
    print "Connection Made";
            return 
    $dbconn
        }

        
        function 
    parseMiltaryAlliance($milall)
        {
            
    //added in an extra rank, even though it is unlikely to matter.
            
    switch ($milall){
               case 
    'PTA':
                    return 
    "PT Academy Forces";
                    break;
               case 
    'NA':
                    return 
    "Not Applicable";
                    break;
                case 
    'EA':
                    return 
    "Earth Alliance Forces";
                    break;
                case 
    'EFF':
                    return 
    "Earth Federation Forces"
                    
    break;
                case 
    'REA':
                    return 
    "Rebel Earth Alliance Forces";
                    break;
                case 
    'KN':
                    return 
    "Kafarion Navy Forces";
                    break;
                case 
    'ZAFT':
                    return 
    "Zodiac Alliance Forces Treaty";
                    break;
                default:
                    return 
    "ERROR";
                }
                
            return 
    "ERROR";
        }
        
        function 
    generateUniqueID($dbobject)
        {
        
         
    //array.
         
    $uni_id = array("0");
         
         
    //longer function.
         
    $result $dbobject->query("SELECT madeupid FROM rpchar");
            while (
    $row $result->fetch_row()){
                
    $uni_id[] = $row[madeupid];
            }
         
    $result->close(); //free the now unused result.
         
         //now that we have the listing of previously assigned uniqueid's, let's describe the format.
         //Capped at 50 characters. 
         //Should be 3 numeric, 4 alphabetic, then a 8 character string mixing with numbers and characters. Then three greek letters (5 letter only)
         // Total 3+4+8+(assume max)+6*3= 15+18=33. Addding a string of numbers after that. (5) long.
         
    $greekLetter = array("Alpha","Beta","Delta","Theta","Psi","Xi","Nu","Mu","Tau","Omega","Chi",
                              
    "Kappa","Lamda","Iota","Gamma","Eta","Zeta");
                              
         
    $customid rand(100,999);
         
    $customid $customidgensafevalue(). gensafevalue() . gensafevalue() . gensafevalue();
         
         
    //the fun thing. The next bit needs to be a mixture, so basically, use rand to generate a number. If it's not in "safevalue" range, regenerate a one digit 
         //   number.
         
         // To be a "fair" number, i put the minimum at 33. It's 57 units away from 90, so the top is 147.
         
         //loop 8 times.
         
    for ($i 1$i <= 8$i++) {
            
    $number rand(33,147);
            if (
    $number <= 90)
                
    $customid $customid gensafevalue();
            else 
                
    $customid $customid rand(0,9);
        }
        
        
    //now add 3 greek letters
        
    for ($i 1$i <= 3$i++) {
            
    $number rand(1,count($greekLetter));
            
    $customid $customid " "$greekLetter[$number];
        }
        
        
    //FINALLY. Add in 5 more numbers.
        
    $customid $customid rand(10000,99999);
        
        return 
    $customid//return it
    }
        
    //returns an alphabetic character
        
    function gensafevalue()
        {
          
    $num 60//init at a number that forces the while loop to execute
          //created because 59-64 (inclusive) is not safe.
          
    while ($num 59  && $num 64)
          {
            
    $num rand(33,90);
          }
          
    //return the character
          
    return chr($num);
        }
        
        function 
    generatepadding($numchars)
        {
            for (
    $i 0$i $numchars$i++)
                print(
    " ");
        }
    ?>

  4. #4
    From space with love silver trophy
    SpacePhoenix's Avatar
    Join Date
    May 2007
    Location
    Poole, UK
    Posts
    5,077
    Mentioned
    103 Post(s)
    Tagged
    0 Thread(s)
    I've found that this way of including files seems to be more reliable:

    require_once $_SERVER['DOCUMENT_ROOT'] . '/path/to/file/anincludefile.php

  5. #5
    SitePoint Member
    Join Date
    Aug 2007
    Posts
    7
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks for the suggestion but it too doesn't work. (Although, I believe from now on that I will use that format)

  6. #6
    . shoooo... silver trophy logic_earth's Avatar
    Join Date
    Oct 2005
    Location
    CA
    Posts
    9,013
    Mentioned
    8 Post(s)
    Tagged
    0 Thread(s)
    You have an error in parseMiltaryAlliance function
    PHP Code:
    case 'EFF':
        return 
    "Earth Federation Forces"
        
    break; 
    missing a ; after echo
    Logic without the fatal effects.
    All code snippets are licensed under WTFPL.


  7. #7
    SitePoint Member
    Join Date
    Aug 2007
    Posts
    7
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Fixed. Still not working.

  8. #8
    . shoooo... silver trophy logic_earth's Avatar
    Join Date
    Oct 2005
    Location
    CA
    Posts
    9,013
    Mentioned
    8 Post(s)
    Tagged
    0 Thread(s)
    Does the code I posted a few post above work on your system?
    Logic without the fatal effects.
    All code snippets are licensed under WTFPL.


  9. #9
    SitePoint Member
    Join Date
    Aug 2007
    Posts
    7
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yes.

  10. #10
    SitePoint Member
    Join Date
    Aug 2007
    Posts
    7
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Addendum:

    Tested it in the subdirectory. STILL works. I guess the problem must be that something in genfunc.php causes it to stop PHP from parsing.

    Verified when I unlinked genfunc.php

  11. #11
    SitePoint Member
    Join Date
    Aug 2007
    Posts
    7
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    ..relinked it. It's now working fine. Thanks for all your help.


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
  •