Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8741791
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T11:22:46+00:00 2026-06-13T11:22:46+00:00

To be more clear, I do understand how to create a new php file

  • 0

To be more clear, I do understand how to create a new php file with php, I’m using fwrite, like so:

//actually create the file now

$my_file=$post_title_edited . ".php";;

$fh= fopen($my_file, 'w');

fwrite($fh, $head);
fwrite($fh, $body);
fwrite($fh, $php);
fwrite($fh, $php2);
fwrite($fh, $php3);
fwrite($fh, $phpend);
fwrite($fh, $end); 
fclose($fh);

//redirect to created file
header("location:". $post_title_edited .".php");

Now it all works just fine, or rather it would, if it were not for this issue:

$php3='

session_start();

if(isset($_SESSION['login'])){
    $myusername = $_SESSION['login'];

    echo '  <div id="header-logedin">
              <h3>Hello ' . $myusername . '</h3>
              <a href="login/logout.php">Log out</a>
            </div><!--header-logedin-->
         ';
} else {
    echo $log;
}

As you can see, when i begin to set $php3, it is interupted by the apostrophe in the login from my first session call. Therefore it can’t be set and in turn i can’t write it into my new file, also $php2 has this same problem.

What am i trying to do? In a nutshell: user posts from index.php information posts over onto new page created by this code, after data is checked against sql table to make sure it doesn’t already exist, very much like a forum. I really hope this is something complicated and I’m not overlooking something incredibly obvious. Thanks in advance.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T11:22:47+00:00Added an answer on June 13, 2026 at 11:22 am

    It is not very clear what you are trying to do, but you seem to be running into an escaping problem.

    To make the apostrophe not actually end the string, you can either:

    • Escape it with a slash, like so:

      $s = 'string with \'single quotes\' inside'
      
    • Use double quotes inside:

      $s = 'string with "double quotes" inside'
      
    • Use a heredoc.

      $s = <<<END
      This string uses a heredoc. So it doesn't use 'single' or "double" quotes.
      END;
      

    edit:
    Also check if you are trying to do something sensible. Ask yourself: do you really need to create a new PHP file? By doing that you are most certainly putting too much complexity on your code, and also weird, nigh undetectable bugs and probably a bunch of security issues as well.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

To make this more clear, I'm going to put code samples: $file = fopen('filename.ext',
I am trying to make my code more clear using the include function of
UPDATE: I've been playing around with this more, and it seems like tmux's clear-history
Which one is preferable or more clear? public int FrozenRegionWidth { get; set; }
Ok, I'm going to try to make this more clear because my last question
More C++ learning questions. I've been using vectors primarily with raw pointers with a
I wish to understand the way kernel works when a user/app tries to create
More specifically in Raven DB, I want to create a generic method with a
More than one time I have encountered the following problem when building code with
More of a general MATLAB question than looking for programming advice -- if I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.