Sgnifus Posted November 22, 2013 Share Posted November 22, 2013 Hi, please, I have a strange problem... I do not know how to solve it, I'm trying for numerous hours... And sorry for my english. I prepared the following synthesis: --- All file in the server root of the web site contain only the statement: <?php require(’server/general.php’); ?> --- general.php basically read an external text file which contains the static html code for that web page identified by - $currentFileName = basename($_SERVER[’PHP_SELF’]); and then print his contents. (This approach allows a fluid management of central contents like the menu or links, particolar issues or appearance, and so on, through a file that contains some meta-informations about the site map) general.php concludes itself setting (in javascript) the html parameters (like input or hinnerHTML): <script> <?php $formParameter = isset($_POST[”u”]) ? $_POST[”u”] : ””; $x = ”xxx”; require(”server/”.$currentFileName); ?> </script> --- Let be that $formParameter isn’t a void value, for example it is ”Pippo”. In the file named ”server/”.$currentFileName, there are these statements: print $formParameter; print $x; // this invalidates javascript, but it is now for php debugging [and, correctly, ouput is: ”Pippo”, ”xxx”] if (!existingValue($x)) { print ”xxxxxxxxxxxxxxx”; writeLog(”x=_”.$x.”_”); clientMessage(...some parameter...); } [and, correctly, no output is done] if (!existingValue($formParameter)) { [And here there is the problem] print ”yyyyyyyyyyyyyyy”; // $formParameter = ”abcdef”; [now it is commented] writeLog(”formParameter is _”.$formParameter.”_”); clientMessage(...some parameter...); } After this if-statement, I print again the parameter: print ”after if: ”.$formParameter; --- prefixing that: 1# the soubroutine existingValue is only: function existingValue($T) { return ( trim($t)!=”” ); } 2# the soubroutine writeLog() write something in a text file 3# clientMessage() soubroutine postpones to a new web page, writing a message for the user , I see that: A# correctly, no print yyyyyyyyyyyyyyy in the last if-statement B# ?!?... writeLog executes! writing in the text file the string ”formParameter is __” C# correctly, not executes clientMessage() soubroutine D# then the flow of the program behaves as if it had never entered if, so it prints the string ”after if: Pippo”. Moreover, if after the statement - print ”yyyyyyyyyyyyyyy”; I uncomment - $formParameter = ”abcdef”; then output of B# became: ”formParameter is _abcdef_”. Why yyyyyyyyyyyyyyy isn’t printed (within the javascript code) but $formParameter is setted? Strange. The flow enters in the if-statement (but it should not do!) and does this only partially? --- Now, really, it isn’t a serious error because the program works equally (see point D#). But I need to understand why exists some aspect of the matter in which $formParameter is evalutated void, because I must make the check of client’s input Note: removing the include and carrying hits contents directly in the parent file (general.php), the problem disappears... but I cannot do this, because general.php has a general role, disconnected from a form-input. THANK YOU FOR YOURS ADVICES Quote Link to comment Share on other sites More sharing options...
Ch0cu3r Posted November 22, 2013 Share Posted November 22, 2013 (edited) How are you checking the output of the PHP code? If you are outputting text within <script></script> tags then you wont see it in the browser. You need to right click view source to see the javascript code. Also note. PHP code is executed on the server. So anything within the <script></script> tags will be treated as javascript, not as PHP! Also when posting code in the forum please press the code button ( the <> button). This will make your posts more clearer. Edited November 22, 2013 by Ch0cu3r Quote Link to comment Share on other sites More sharing options...
Sgnifus Posted November 23, 2013 Author Share Posted November 23, 2013 How are you checking the output of the PHP code? If you are outputting text within <script></script> tags then you wont see it in the browser. You need to right click view source to see the javascript code. Also note. PHP code is executed on the server. So anything within the <script></script> tags will be treated as javascript, not as PHP! Also when posting code in the forum please press the code button ( the <> button). This will make your posts more clearer. Thanks you for answere, but was a tilt of EasyPHP, because I opened several browser window, now it work correctly :-) Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.