Results 1 to 15 of 15

Thread: making php file with fopen()

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Feb 2003
    Location
    EGYPT
    Posts
    103

    making php file with fopen()

    how could i save a php code into a php file with fopen()

    for examble i want to save this code into php file

    PHP Code:
    <?php
    $a
    =fopen("one.php","w");
    fwrite($a,"any thing");
    fclose($a);
    ?>



  2. #2
    Lively Member morrowasted's Avatar
    Join Date
    Aug 2003
    Location
    Houston, TX
    Posts
    118
    PHP Code:
    <? 
    $input_code = "whatever";
    $file="file.php"; 
    $write=fopen($file,'w');
    fputs($write,$input_code); 
    fclose($write);
    ?>
    im not php expert, mind you, but i think that works

    -morrowasted

  3. #3
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    Yep, it works, and you can even include() the file afterwards.

    Though eval is probably more efficient in that case.
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  4. #4
    Lively Member morrowasted's Avatar
    Join Date
    Aug 2003
    Location
    Houston, TX
    Posts
    118
    i made a PHP script that works without any help!!!!

    -morrowasted

  5. #5

    Thread Starter
    Lively Member
    Join Date
    Feb 2003
    Location
    EGYPT
    Posts
    103
    thank's all for your reply's

    but

    look at this code

    PHP Code:

     <?  
    $input_code = "
     <?  
    $input_code = "whatever"; 
    $file="file.php";  
    $write=fopen($file,'w'); 
    fputs($write,$input_code);  
    fclose($write); 
    ?> 
    "; 

    $file="file.php";  
    $write=fopen($file,'w'); 
    fputs($write,$input_code);  
    fclose($write); 
    ?>
    i inserted just a few lines in the $input_code

    but what's happened if i inserted a big script in it ??

    it will be alot of error's , parse and etc , so is there any way to do it with out error's , some way make the parser get over the inputed code ??

  6. #6
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687
    Why are you doing it like that?
    If you already have the code, why not jsut put it in a PHP file to begin with?

    TG
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  7. #7
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    The problem is the matching of quotes. As the syntax highlighter points out, the quotes within your string end your string. You must escape them.
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  8. #8
    PowerPoster
    Join Date
    Sep 2003
    Location
    Edmonton, AB, Canada
    Posts
    2,629
    For PHP to manually escape characters for you, try addslashes().

    To use it with what you are doing, you're going to have to grab the actual code from somewhere, like a POST or GET form.

    EG:

    PHP Code:
    $input_code addslashes($_POST['code']); 
    Where the user has inputted the code into a text box named "code".
    Last edited by kows; Dec 31st, 2003 at 01:06 AM.
    Like Archer? Check out some Sterling Archer quotes.

  9. #9
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    Which is about the worst security leak you could ever open.
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  10. #10
    Frenzied Member
    Join Date
    Nov 1999
    Posts
    1,337
    how is addslashes a security leak?

    if you write to a file how is it a security leak? unless of course they stripslahes and inlcude it somewhere

  11. #11
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    The security leak is taking code from the user and executing it as PHP.
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  12. #12
    Frenzied Member
    Join Date
    Nov 1999
    Posts
    1,337
    yes, I agree, I just read your post a different way.

    why would you take code from a user and execute it?

    that is almost like saying, here, delete my database.

  13. #13
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    Well, combine the results of this thread and you have it.

    1)
    Code:
    $input_code = addslashes($_POST['code']);
    2)
    Code:
    $file="file.php";
    $write=fopen($file,'wt');
    fputs($write,$input_code);
    fclose($write);
    3) (as according to my first post)
    Code:
    include($file);
    Happy cracking
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  14. #14
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 2001
    Location
    Michigan
    Posts
    7,256
    Sounds like fun. I'll try it.
    My evil laugh has a squeak in it.

    kristopherwilson.com

  15. #15

    Thread Starter
    Lively Member
    Join Date
    Feb 2003
    Location
    EGYPT
    Posts
    103
    thank's all

    i found a new code which made the parser getover the code

    PHP Code:
    $link= <<<EOF

    $fp = fopen ("file.txt", "w+");
    <br/>fwrite (
    $fp, "Test");
    fclose (
    $fp);

    EOF; 
    i think it's great

    The security leak is taking code from the user and executing it as PHP.
    thank's for the advice , it's very important

    the user's maybe put a dangours code like phpshell code of other

    but i will need the way soon


Posting Permissions

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



Click Here to Expand Forum to Full Width