Find the answer to your Linux question:
Results 1 to 6 of 6
So i have Apache2.0 running on my muchine and i'm using it as test ground for my PHP scripts. Here is the script that gives me problem: Code: <?php $tireqty=$_POST&#91;'tireqty'&#93;; ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined! vitalka's Avatar
    Join Date
    Oct 2004
    Location
    Toronto, ON
    Posts
    77

    Problems with PHP script, maybe related to apache settings.


    So i have Apache2.0 running on my muchine and i'm using it as test ground for my PHP scripts.
    Here is the script that gives me problem:
    Code:
    <?php
    $tireqty=$_POST&#91;'tireqty'&#93;;
    $oilqty=$_POST&#91;'oilqty'&#93;;
    $sparkqty=$_POST&#91;'sparkqty'&#93;;
    if &#40;&#40;$tireqty == ""&#41; or &#40;$oilqty == ""&#41; or &#40;$sparkqty == ""&#41;&#41; &#123;
    	header&#40;"Location&#58; http&#58;//localhost/orderform.html"&#41;;
    	exit;
    &#125;
    ?>
    <html>
    <head>
    <title>Bob's Auto Parts - Order Results</title>
    </head>
    <body>
    <h1>Auto Parts</h1>
    <h2>Order Results</h2>
    <?php
    echo "
    
    Order Results&#58;</p>";
    echo date&#40;"H&#58;i, jS F Y"&#41;;
    echo "
    ";
    echo "
    
    Your order is as follows&#58;</p>";
    echo "
    ";
    echo "$tireqty tires
    ";
    echo "$oilqty bottles of oil
    ";
    echo "$sparkqty spark plugs
    ";
    
     $fp = fopen&#40;"$DOCUMENT_ROOT/vitali/filesystem/orders.txt", "W"&#41;;
    if &#40;!$fp&#41;
    &#123;
    echo "
    
    Your order could not be processed at this time. "
    			."Please try again later.</p>";
    exit;
    &#125; else &#123;
    $outputspring = $date. "\t".$tireqty." tires \t".$oilqty.' oit\t'
    					.$sparkqty." spark plugs\t\$".$total
    					."\t". $address. "\n";
    fwrite&#40;$fp, $outputstring&#41;;
    
    fclose&#40;$fp&#41;;
    &#125;
    ?>
    </body>
    </html>
    It gives me the following error:
    Warning: fopen(/home/estonia/public_html/vitali/filesystem/orders.txt): failed to open stream: Success in /home/estonia/public_html/vitali/processorder.php on line 27
    I'v been looking at the code for the past 3 days. Checked many websites and it seems that my script is correct. So te problem might be in Apache or PHP module.

    If any of you guys have any idea, that would be great.

    By the way i'm using Fedora Core3 to run Apache2.0.

    Thank you for your time.

  2. #2
    Linux Newbie
    Join Date
    Jan 2004
    Location
    Belgrade, S&M
    Posts
    177
    Could it be a permissions problem ?

  3. #3
    Just Joined! vitalka's Avatar
    Join Date
    Oct 2004
    Location
    Toronto, ON
    Posts
    77
    Permissions are set to 777, but still it wouldn't work. IF it would not allow to create files in a folder then it would tell me that i don't have permission to do that.

  4. #4
    Just Joined!
    Join Date
    Jan 2005
    Location
    UK
    Posts
    77
    check your apache logs to see if the script is throwing up any errors, it usually tells you any problems straight up.

  5. #5
    Just Joined! vitalka's Avatar
    Join Date
    Oct 2004
    Location
    Toronto, ON
    Posts
    77
    These are last three lines that were added after scipt was executed:

    Code:
    &#91;Fri May 27 19&#58;34&#58;16 2005&#93; &#91;error&#93; &#91;client 127.0.0.1&#93; File does not exist&#58; /var/www/html/favicon.ico
    &#91;client 127.0.0.1&#93; PHP Warning&#58;  fopen&#40;./filesystem/orders.txt&#41;&#58; failed to open stream&#58; Success in /var/www/html/processorder.php on line 27, referer&#58; http&#58;//localhost/orderform.html
    &#91;Fri May 27 19&#58;34&#58;17 2005&#93; &#91;error&#93; &#91;client 127.0.0.1&#93; File does not exist&#58; /var/www/html/favicon.ico
    i hope that can point into the right direction.

  6. #6
    Linux Engineer
    Join Date
    Nov 2004
    Location
    home
    Posts
    796
    Use $_SERVER['DOCUMENT_ROOT'] instead of $DOCUMENT_ROOT . The use of $DOCUMENT_ROOT is deprecated and relies on php being less secure by having register globals on, which you should never ever do.

Posting Permissions

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