Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 14 of 14
  1. #1
    Regular Coder
    Join Date
    Apr 2004
    Posts
    684
    Thanks
    24
    Thanked 1 Time in 1 Post

    Making a new php file within a php file..

    How can you do this?

    If I do this..

    PHP Code:
    $fd = fopen("files/$snf", "w");

    fputs($fd, "<?php");
    fputs($fd, "
    $fileid $sn;");
    fputs($fd, "
    ?>");

    fclose($fd);

    include("files/$snf");
    It won't work... do you escape it someway?

    Thanks!
    Last edited by cyphix; 05-15-2004 at 02:20 PM.

  • #2
    raf
    raf is offline
    Master Coder
    Join Date
    Jul 2002
    Posts
    6,589
    Thanks
    0
    Thanked 0 Times in 0 Posts
    i suppose you're looking for
    PHP Code:
    $fd = fopen('./files/' . $snf, 'w'); 

    fputs($fd, '<?php'); 
    fputs($fd, '
    $fileid =' . $sn . ';'); 
    fputs($fd, '
    ?>'); 

    fclose($fd); 

    include('./files/' . $snf);
    So always use single quotes for strings that need to be taken literal, and concatenate your variables instead having them parsed inside doublequoted strings.
    --> it will be faster
    --> it's easier to read because the colourcoding clearly shows which are literals and which are variables that wil be replaced by heir assigned value
    Posting guidelines I use to see if I will spend time to answer your question : http://www.catb.org/~esr/faqs/smart-questions.html

  • #3
    Regular Coder
    Join Date
    Apr 2004
    Posts
    684
    Thanks
    24
    Thanked 1 Time in 1 Post
    Thanks... still getting some errors tho..

    Warning: Unexpected character in input: '\' (ASCII=92) state=1 in xxxxxxxxxxxxxxxxxxxx/files/127file.php on line 1

    Parse error: parse error in xxxxxxxxxxxxxxxxxxxxxxxxxx/files/127file.php on line 1

    That is the new file it created.

  • #4
    Regular Coder
    Join Date
    Apr 2004
    Posts
    684
    Thanks
    24
    Thanked 1 Time in 1 Post
    Plus I can't get the "\n" to work either.

  • #5
    Regular Coder
    Join Date
    Apr 2004
    Posts
    684
    Thanks
    24
    Thanked 1 Time in 1 Post
    nm.. I figured out a much better way to do what I'm trying to achieve.

  • #6
    Senior Coder missing-score's Avatar
    Join Date
    Jan 2003
    Location
    UK
    Posts
    2,194
    Thanks
    0
    Thanked 0 Times in 0 Posts
    would you be so kind as to share your better method

  • #7
    raf
    raf is offline
    Master Coder
    Join Date
    Jul 2002
    Posts
    6,589
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by missing-score
    would you be so kind as to share your better method
    or maybe explain what you are trying to achieve or where you have/had problems with and what content you're trying to write to the file.

    seems to me you don't understand the difference between single and double quotes and when you should escape special characters.
    Posting guidelines I use to see if I will spend time to answer your question : http://www.catb.org/~esr/faqs/smart-questions.html

  • #8
    Regular Coder
    Join Date
    Apr 2004
    Posts
    684
    Thanks
    24
    Thanked 1 Time in 1 Post
    Well, what I was trying to achieve was I needed to carry unique values over several different script runs..

    But I just figured out that I couldn't do it that way as if I stored the info in a file there would be no way on the second run the script would know what file to refer to & I couldn't refer to the variables any longer on the 2nd run; so I store the values from the previous page in hidden input tags on the next page & then I can carry them from page to page.

    seems to me you don't understand the difference between single and double quotes and when you should escape special characters.
    I'm not very well versed in them no.

  • #9
    raf
    raf is offline
    Master Coder
    Join Date
    Jul 2002
    Posts
    6,589
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by cyphix
    Well, what I was trying to achieve was I needed to carry unique values over several different script runs..

    But I just figured out that I couldn't do it that way as if I stored the info in a file there would be no way on the second run the script would know what file to refer to & I couldn't refer to the variables any longer on the 2nd run; so I store the values from the previous page in hidden input tags on the next page & then I can carry them from page to page.
    using sessionvariables might be easier ...
    Posting guidelines I use to see if I will spend time to answer your question : http://www.catb.org/~esr/faqs/smart-questions.html

  • #10
    Regular Coder
    Join Date
    Apr 2004
    Posts
    684
    Thanks
    24
    Thanked 1 Time in 1 Post
    Haven't learnt about them yet heh

  • #11
    Supreme Overlord Spookster's Avatar
    Join Date
    May 2002
    Location
    Marion, IA USA
    Posts
    6,278
    Thanks
    4
    Thanked 83 Times in 82 Posts
    Quote Originally Posted by cyphix
    Haven't learnt about them yet heh
    Well you might want to start. You are trying to reinvent the wheel.

    All you need to do is

    PHP Code:
    session_start()
    $_SESSION['variablename'] = "value"
    Now you can access that value anywhere in your site during that browser session just by doing:

    PHP Code:
    session_start();
    echo 
    "The variable value was: " $_SESSION['variablename']; 
    Spookster
    CodingForums Supreme Overlord
    All Hail Spookster

  • #12
    Regular Coder
    Join Date
    Apr 2004
    Posts
    684
    Thanks
    24
    Thanked 1 Time in 1 Post
    OK thanks!

    When setting variables do I need to use this:

    PHP Code:
    session_start() 
    ..before every varaiable I set?

    Cheers!

  • #13
    Regular Coder anarchy3200's Avatar
    Join Date
    Mar 2003
    Location
    England
    Posts
    261
    Thanks
    0
    Thanked 1 Time in 1 Post
    no you do not need to put this before every variable but just put

    PHP Code:
    <?PHP
    session_start
    ();
    ?>
    at the very top of each page you wish to use them on

  • #14
    Regular Coder
    Join Date
    Apr 2004
    Posts
    684
    Thanks
    24
    Thanked 1 Time in 1 Post
    Thanks!


  •  

    Posting Permissions

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