0

so i have xampp installed on windows the address is localhost and i have a page test.php to preview my code
a couple days ago everything worked fine when echoing

<?php
echo '<'.htmlentities('?php if ($_SESSION[\'Username\']==\'nume\') { echo \'right name\'; } else { echo \'wrong name\'; } ?').'>';
?>

and when i tried to test it yesterday the page showing is blank why?

3
Contributors
8
Replies
33
Views
3 Years
Discussion Span
Last Post by andreiviziru
0

Write the code out properly:

<?php

if ($_SESSION["Username"] == "name") {
    echo "Right Name";
} else {
    echo "Wrong name";
}

?>

I swapped 'nume' to 'name' I don't know if it was meant to be like that?

Mat

1
echo '<'.htmlentities('?php if ($_SESSION[\'Username\']==\'nume\') { echo \'right name\'; } else { echo \'wrong name\'; } ?').'>';

This will echo an xml-type tag to the page <...>
So of course, it won't be displayed, but if you look in the browser's "view source", you should see it.

Not sure what output you need or want with this. Are you looking to display php code to the screen?

If so, here's something I knocked up that you could modify...

function codify($str)
{
    //newline -> <br />, \t, tabs and 4 spaces to 4 non-breaking spaces 
    return '<code>' . str_replace(array("\t",'   ','    '),'&nbsp;&nbsp;&nbsp;&nbsp;', nl2br(htmlentities($str))) . '</code>';
}

This lets you work with nowdoc and heredoc syntaxes...

NOWDOC

$str = <<<'CODE'
<?php
if($_SESSION['Username']=='nume')
{
    echo 'right name';
}else{
    echo 'wrong name';
}
?>
CODE;

HEREDOC

$str2 = <<<CODE2
<?php
if(\$_SESSION['Username']=='nume')
{
    echo 'right name';
}else{
\techo 'wrong name';
}
?>
CODE2;

You can test them like this...

echo codify($str);
echo '<br />';
echo codify($str2);
0

the point is that i want to echo it out as php code because i put the string into the "fwrite" function to write an entire php page

Edited by andreiviziru

0

I think I'm missing something here. You want to write the formatted/converted output to a file? For what purpose? I don't understand why you need to do this.

0

So do you want the content of the file to be 'runnable' as php code or should it be 'htmlentitied', so it actually looks like this...

&lt;?php
    ...
?&gt;
0

i will leave this like this right now because i made a script to auto write the code for testing thanks

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.