We as a developer while working on projects whether it is website or any application write
code to implement logic and execute it. But here I will you how to display complete PHP
code in browser without executing it. You can do this following below code with an example:
Here main key is to pass php code into htmlspecialchars() function.
$php_code = '
if (extension_loaded(\'sockets\')) {
//Create socket IPv4
$socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP) ;
if($socket === false) {
$errorcode = socket_last_error() ;
$errormsg = socket_strerror($errorcode);
echo "
Error socket IPv4: ".$errormsg."
\n" ;
}
else {
echo "
Socket IPv4 supported
\n" ;
socket_close($socket);
}
//Create socket IPv6
$socket = socket_create(AF_INET6, SOCK_STREAM, SOL_TCP) ;
if($socket === false) {
$errorcode = socket_last_error() ;
$errormsg = socket_strerror($errorcode);
echo "
Error socket IPv6: ".$errormsg."
\n" ;
}
else {
echo "
Socket IPv6 supported
\n" ;
socket_close($socket);
}
}
else echo "
Extension PHP sockets not loaded
\n" ;?>';
echo htmlspecialchars($php_code);