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.
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:
Use double quotes inside:
Use a heredoc.
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.