Fwrite不写if语句

时间:2013-07-27 21:32:32

标签: php

我有一个fwrite编写每个业务的页面,但我想要它,以便它只显示页面的HTML,当你去有效会话的网址,所以我写了   FWRITE($ FP”

然而,当它写入页面时,它会写入此内容。 isset语句已从​​if语句中删除。

    <?php

$recid = $_POST['recid'];
$username = $_POST['name'];
$email = $_POST['email'];
$ownername = $_POST['ownername'];

include ("connection.php");


$result = $db->query("UPDATE users SET verified='y' WHERE recid='$recid'"); 

$doctype      = "<!DOCTYPE html>";
$htmlOpen     = "<html>";
$head         = "<head> <meta http-equiv='Content-Type' content='text/html; charset=ISO-8859-1'>
                 <script src='http://code.jquery.com/jquery-1.9.1.min.js'> </script>
                 <script src='http://code.jquery.com/ui/1.10.2/jquery-ui.js'> </script> 
                 <script src='Scripts/dropdown.js'> </script> 
                 <link rel='stylesheet' href='CSS/businesspages.css'> 
                 <link rel='stylesheet' href='http://code.jquery.com/ui/1.10.2/themes/smoothness/jquery-ui.css'> 
                 <script src='Scripts/postdata.js'> </script>
                 </head>";

$bodyOpen     = "<body>";
$header       = "<div id='header'> </div>";
$wcImage      = "<img src='wc.png' id='wc'>";
$accountTable = "<table id='accountinfo'> 
                 <tr> <td id='accountinfotd1'> </td> </tr> 
                 <tr> <td id='accountinfotd2'>{$username}</td> </tr> 
                 <tr> <td id='accountinfotd3'>{$ownername}</td> </tr> 
                 </table>";

$linksTable   = "<table id='links'> 

                <tr> <td> <input type='text' id='post' placeholder='Post' name='post'> </td> </tr>

                <tr> <td> <img src='images/profile.jpg' id='profile'> </td> </tr> 

                <tr> <td> <div id='profileDiv'>
                <table>
                <tr> 
                <td> <input type='password' id='changePSW' name='changePSW' placeholder='Change Password' tabindex=2> </td>
                <td> <input type='password' id='verifyPSW' name='verifyPSW' placeholder='Verify Password' tabindex=3> </td>
                <td> <input type='image' id='changePSWBtn' src='images/changeBtn.jpg' name='changePSWBtn'> </td>
                </tr>
                <tr> 
                <td> <input type='text' id='changeLA' name='changeLA' placeholder='Latitude' tabindex=6> </td>
                <td> <input type='text' id='changeLO' name='verifyPSW' placeholder='Longatude' tabindex=7> </td>
                <td> <input type='image' id='changeLLBtn' src='images/changeBtn.jpg' name='changeLLBtn'> </td>
                </tr>
                </table>
                </div> </td> </tr> 

                <tr> <td> <img src='images/legal.jpg' id='legal'> </td> </tr> 

                <tr> <td> <div id='legalDiv'>
                <a href='Legal_Documents/termsofuseweb.pdf' target='_blank'> Web Terms Of Use </a> </br>
                <a href='Legal_Documents/termsofuseios.pdf' target='_blank'> iOS Terms Of Use </a> </br>
                <a href='Legal_Documents/enduserlisenceagreement.pdf' target='_blank'> End Of User Licensee </a>
                </div> </td> </tr> 

                <tr> <td> <img src='images/help.jpg' id='help'> </td> </tr> 

                <tr> <td> <div id='helpDiv'> 
                <p> If you need help you can contact Phil Pilon or Matt Muehlemann info@wolfeboroconnection.com </p>
                </div> </td> </tr> 

                </table>";

$bodyClose    = "</body>";
$htmlClose    = "</html>";
$isset = "{$_SESSION['id']}";

$filename = str_replace(" ","_", trim($username) ); 
mkdir("Business_Pages/" . $filename."/");

if( $fp = fopen("Business_Pages/" . $filename . "/" . $filename . ".php", "w") )
{
  fwrite($fp,"<?php session_start();");
  fwrite($fp, "if(isset({$_SESSION['id']})) { ?");
  fwrite($fp, $doctype.$htmlOpen.$head.$bodyOpen.$header.$wcImage.$accountTable.$linksTable.$bodyClose.$htmlClose);
  fwrite($fp,"<?php } else { echo \"User not logged in\";} ?>");
  fclose($fp);
}

这是它写的页面

    <?php session_start();if() { ?><!DOCTYPE html>
<html><head> <meta http-equiv='Content-Type' content='text/html; charset=ISO-8859-1'>
                 <script src='http://code.jquery.com/jquery-1.9.1.min.js'> </script>
                 <script src='http://code.jquery.com/ui/1.10.2/jquery-ui.js'> </script> 
                 <script src='Scripts/dropdown.js'> </script> 
                 <link rel='stylesheet' href='CSS/businesspages.css'> 
                 <link rel='stylesheet' href='http://code.jquery.com/ui/1.10.2/themes/smoothness/jquery-ui.css'> 
                 <script src='Scripts/postdata.js'> </script>
                 </head>
                 <body>
                 <div id='header'> </div><img src='wc.png' id='wc'><table id='accountinfo'> 
                 <tr> <td id='accountinfotd1'> </td> </tr> 
                 <tr> <td id='accountinfotd2'>test </td> </tr> 
                 <tr> <td id='accountinfotd3'></td> </tr> 
                 </table><table id='links'> 

                <tr> <td> <input type='text' id='post' placeholder='Post' name='post'> </td> </tr>

                <tr> <td> <img src='images/profile.jpg' id='profile'> </td> </tr> 

                <tr> <td> <div id='profileDiv'>
                <table>
                <tr> 
                <td> <input type='password' id='changePSW' name='changePSW' placeholder='Change Password' tabindex=2> </td>
                <td> <input type='password' id='verifyPSW' name='verifyPSW' placeholder='Verify Password' tabindex=3> </td>
                <td> <input type='image' id='changePSWBtn' src='images/changeBtn.jpg' name='changePSWBtn'> </td>
                </tr>
                <tr> 
                <td> <input type='text' id='changeLA' name='changeLA' placeholder='Latitude' tabindex=6> </td>
                <td> <input type='text' id='changeLO' name='verifyPSW' placeholder='Longatude' tabindex=7> </td>
                <td> <input type='image' id='changeLLBtn' src='images/changeBtn.jpg' name='changeLLBtn'> </td>
                </tr>
                </table>
                </div> </td> </tr> 

                <tr> <td> <img src='images/legal.jpg' id='legal'> </td> </tr> 

                <tr> <td> <div id='legalDiv'>
                <a href='Legal_Documents/termsofuseweb.pdf' target='_blank'> Web Terms Of Use </a> </br>
                <a href='Legal_Documents/termsofuseios.pdf' target='_blank'> iOS Terms Of Use </a> </br>
                <a href='Legal_Documents/enduserlisenceagreement.pdf' target='_blank'> End Of User Licensee </a>
                </div> </td> </tr> 

                <tr> <td> <img src='images/help.jpg' id='help'> </td> </tr> 

                <tr> <td> <div id='helpDiv'> 
                <p> If you need help you can contact Phil Pilon or Matt Muehlemann info@wolfeboroconnection.com </p>
                </div> </td> </tr> 

                </table></body></html><?php } else { echo "User not logged in";} ?>

1 个答案:

答案 0 :(得分:2)

原因是您使用以下行:

fwrite($fp, "if(isset({$_SESSION['id']})) { ?");

因为您使用双引号,这意味着在通过fwrite写入文件之前,PHP将解析会话值{$_SESSION['id']}。如果您将引号更改为单引号,则不会出现此问题,因为PHP将仅保留单引号字符串 - 即不为变量解析它们:

fwrite($fp, 'if(isset($_SESSION["id"])) { ?');

你还应该删除会话var上的周围花括号,除非你希望你的php在重新解析时是错误的。

这是假设您在文件中想要的结果是:

if(isset($_SESSION["id"])) { ?