Jump to content

php_joe

Members
  • Posts

    175
  • Joined

  • Last visited

    Never

Posts posted by php_joe

  1. I think we might need a bit more information about what you're trying to achieve in order to help you with your function.

     

    Nothing specific at the moment, but I've occationally run into a situation that I'd want to repeat, maybe with a slightly altered set of circumstances.

     

    If you had a situation where the function was in an endless loop (like, you'd set the timeout at 0) would it continue to loop if the visitor closed the webpage?

  2. is there a command that will abort a function and rewind it back to the beginning?

     

    Something along the lines of this:

     

    <?
    if($handle = fopen($url)){
    fwrite($handle, $info);
    fclose($handle);
    }else{
    
    // here is where I want it to return to the beginning of the function
    
    }
    ?>

  3. "Visitors" use PHP via the webserver to access your pages; they don't do it directly.  So whichever user the webserver runs under is who is accessing your filesystem and permissions+ownership will apply to that user.

     

    I've seen websites that have a folder full of images. If you try to view the image directly then it redirects you or says "forbidden" but it still shows up on the webpages.

     

    I tried changing the folder's permissions, but whenever I deny access to the folder all I get is a red X where the image on the webpage should be.

     

    I know that I can put all the remote files in a secret folder. I'm just worried about some hacker guessing the member account's folder's name, or using a search program to find it.

  4. Are these files ever executed? Is the path accessible to the user, i.e., they can type it into the address bar?

     

    Some are, some are not. What I'm mainly worried about is someone injecting a file into a folder and using it to create new files or modify & damage existing files.

     

    chmod dir to 555 or 755?

     

    It might help also to restrict your world writeable files to a specific directory.

     

    I'll try 555, thanks!

     

    Do you know how to resitrict access to the folder so that files on my site can access it but visitors can not access it directly?

  5. I have a webpage that some hacker managed to load a file onto.

     

    My website's help support suggested that I should not use chmod 0777 since it is not secure.

     

    However, I need to allow my site's visitors to open files & write information to them.

     

    My question:

    Is there a setting that will allow site members to create, open, write to, and delete files using my pages but will not allow them to create their own pages outside of my control?

  6. 1. make a PHP page like this:

     

    <?
    $info = "$text\n";
    $handle = fopen("./record.txt", "a+");
    fwrite($handle, $info);
    fclose($handle);
    ?>

     

    I'm calling it record_text.php.

     

    Now you can use javascript's onsubmit function to refresh a frame or iframe every time a user submits a text in the chat room.

  7. Hey guys, I'm a beginner and trying to figure out some things in php.

     

    Let's say I have a script count.php and i want it to add all the numbers generated from multiple remote files (number.php)

     

    so count.php is at domain1.com

     

    The number.php would be at domain2.com

     

    and i want count.php to get the number generated from number.php into a variable inside count.php

     

    How would I code count.php to fetch the number from the remote file (number.php)?

     

     

    Sorry if my word is a little confusing. but i will really appreciate anyone who try to help

     

    merci d'avance.

     

    So, assuming that domain1.com requres a variable input and will display just the number (without any other stuff) then you could do this:

    <?
    $number = file_get_contents("http://www.domain1.com?some_variable=value");
    if(!is_numeric($number)) unset($number);
    ?>

  8. I am trying to write a function that will strip tags and reduce multiple line breaks & tabs to just one. There's probably a better way of doing this, but this is what I've come up with on my own.

     

    This strips the tags, breaks each line into an array, separates by tabs, then removes white space.

     

    function strip_whitespace($code){
    $code = strip_tags($code);
    $lines = explode("\n", $code);
    foreach($lines as $lkey => $line){
    $pieces = explode("\t", $line);
    foreach($pieces as $pkey => $piece){
    $newpiece[$pkey] = trim($piece);
    } // end pieces
    $newline[$lkey] = implode("\t", $newpiece);
    $newline[$lkey] = trim($newline[$lkey]);
    } // end lines
    $output = implode("\n", $newline);
    return($output);
    }

     

    However, I still end up with double tabs & double line breaks, so I tried this:

     

    function strip_whitespace($code){
    $code = strip_tags($code);
    $lines = explode("\n", $code);
    foreach($lines as $lkey => $line){
    $pieces = explode("\t", $line);
    foreach($pieces as $pkey => $piece){
    $newpiece[$pkey] = trim($piece);
    if(!$newpiece[$pkey]) unset($newpiece[$pkey]); // This reverses the array
    } // end pieces
    $newline[$lkey] = implode("\t", $newpiece);
    $newline[$lkey] = trim($newline[$lkey]);
    if(!$newline[$lkey]) unset($newline[$lkey]); // but this one works fine
    } // end lines
    $output = implode("\n", $newline);
    return($output);
    }

     

    Why does the $newpiece array order reverse when I unset() the empty values?

  9. Hi, I'm having some problems with a math function not giving me the answer that I expect.

     

    Wikipedia says that you can find a side of a triangle if you know an angle and 2 sides using the law of cosine:

    a2c3a9527af895a3fa6e8e9d0bb1b30d.png

    http://en.wikipedia.org/wiki/Law_of_cosines

     

    so I used this code:

    <?
    $a = '5';
    $b = '5';
    $c = sqrt(pow($a, 2) + pow($b, 2) - (2 * $a * $b * cos(135)));
    echo "$c";
    ?>

    And it gave me the correct (I think) answer: 9.9902148003463

     

    But when I try to find a side using 2 angles and a side using the law of sine it doesn't work.

     

    The equation that I have is "b = (12 Sin 65)/(sin 50)" from http://home.alltel.net/okrebs/page93.html so I used this code:

    <?
    $b = 12 * sin(65) / sin(50);
    echo "$b";
    ?>

    Which, according the the website that I got it from, should have printed "14.2", but I got "-37.815911143213" instead.

     

    What am I doing wrong?

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.