0

below is my code where i am writing a code in php and calling it in body. When i run it and view source, the code gets visible. I have seen some site where nothing gets shown on source but a form appears on webpage. How can i do it too?

<?php
{   $avatar_form  = '<form id="avatar_form" enctype="multipart/form-data" method="post" action="myphoto.php">';
    $avatar_form .=   '<h4>Change your avatar</h4>';
    $avatar_form .=   '<input type="file" name="avatar" required>';
    $avatar_form .=   '<p><input type="submit" value="Upload"></p>';
    $avatar_form .= '</form>';
}


?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Avatar</title>
</head>

<body>
<div><?php echo $avatar_form; ?></div>
</body>
</html>

Thanks Shail

8
  • If you're seeing PHP code in the browser, your server's not set up right. That, or your filename doesn't end in .php. Commented Jul 25, 2014 at 4:27
  • 1
    Presumably you have put it into an .html file. And your web server has no idea that it needs to process it as php Commented Jul 25, 2014 at 4:27
  • i think you want to hide your html source you can check this link stackoverflow.com/questions/12543704/… Commented Jul 25, 2014 at 4:30
  • @zerkms/cHao - there are other php codes too on the file which has several logics and they are not visible, only this is becoming visible. My whole project is on php, i havent used html even on a single page. Commented Jul 25, 2014 at 4:43
  • 1
    For reference, there's not really such a thing as hiding HTML source. The browser has to see the HTML before it knows what to show the user. And telling it to betray the user and not show that HTML even when asked, is harder and more trouble than it's worth. Commented Jul 26, 2014 at 7:46

2 Answers 2

1

Why not write it in html? There should not be any code showing like that:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Avatar</title>
</head>

<body>
<div>
<form id="avatar_form" enctype="multipart/form-data" method="post" action="myphoto.php">
<h4>Change your avatar</h4>
<input type="file" name="avatar" required>
<p><input type="submit" value="Upload"></p>
</form>
</div>
</body>
</html>

just using php to echo html is sometimes not faster or useful then writing it directly in .html files.

Sign up to request clarification or add additional context in comments.

Comments

1

This is Output of the code, And this is the page source showing at my side my browser.. Check whether the file type is .php or .html? if html, it will show the php code. If so, save it as .php

8 Comments

it is php. i am not using html
Dear Shail, I copied you entire code and tested, its not showing any php code in view source, so can you please tell me more details so that I may help you out. Thanks.
is it possible to add a png file here
this whole is shown in body part on source code. i dont want this to appear to user. <body> <div><form id="avatar_form" enctype="multipart/form-data" method="post" action="myphoto.php"><h4>Change your avatar</h4><input type="file" name="avatar" required><p><input type="submit" value="Upload"></p></form></div> </body> </html>
Do you like to use right click disable jquery code in you programmed code? it will stop to click right. $(document).ready(function() { $("img").bind("contextmenu",function(){ return false; }); });
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.