Jump to content


Photo

PHP and CSS- how to style comment site


Best Answer requinix, 12 November 2017 - 07:24 PM

You have a much larger problem than just the styling of the comments: people can execute PHP code on your site, let alone put HTML (and Javascript) on your site.

Do you want people to write HTML? Please say no because allowing that is painful. Replace

<?php include "comments.html"; ?>
with
<?php readfile("comments.html"); ?>
and
fwrite($handle,"<b>" . $name . "</b>:<br/>" . $content . "<br/><br>");
with
fwrite($handle,"<b>" . htmlspecialchars($name) . "</b>:<br/>" . htmlspecialchars($content) . "<br/><br>");
Now go into your comments.html and make sure there isn't anything bad in it.

With that taken care of, find and fix the problem with your starting <head> tag. I expect the browser was able to recover gracefully from it, though, as you would have noticed otherwise.


Anyways,

If you need help with the appearance of your site then we need to see the HTML (your PHP isn't complicated so that's okay) and the CSS. Preferably with a link to the site, but don't provide a link until you do the comment thing I said above. Go to the full post


  • Please log in to reply
2 replies to this topic

#1 hgkhkhk

hgkhkhk
  • Members
  • PipPip
  • Member
  • 11 posts

Posted 12 November 2017 - 06:44 PM

I am building a comment section for my system. While it is working successfully, I cannot seem to style the comments the way I want to. All the comments appear at the very left side of the screen. Essentially I want to bring them to the center, color the username, and maybe put a border around the username and comments. I have tried everything such as using span classes and div classes, but nothing is working. If someone could please tell me where to put the span or div classes, I would appreciate it. Thank you.

<?php

if($_POST) {
    $name = $_POST['name'];
	$content = $_POST['commentContent'];
	$handle = fopen("comments.html","a");
	fwrite($handle,"<b>" . $name . "</b>:<br/>" . $content . "<br/><br>");
	fclose($handle);
}
?>
	

<!doctype html>

<html>

</head>

<link rel="stylesheet" type="text/css" href="commentstyle.css">
<link rel="icon" href="Icon.jpg">

<title>Comment</title>

</head>

<body>

<div class="header">

<img class="icon" src="Icon.jpg"> 
<div class="search">Comment </div>

</div>

<a href="homepage.php"><span class="home">Homepage</span></a>

<div class="select">View comments</div>
<br>

<?php include "comments.html"; ?>

<hr>

<div class="box">
<form action = "" method = "POST">
Name:<br> <input type = "text" name = "name"><br/>
Comment: <textarea rows = "10" cols = "30" name = "commentContent"></textarea><br/>
<input type = "submit" value = "Submit"><br/>


</form>
</div>
</body>

</html>


#2 requinix

requinix
  • Administrators
  • Lazy Administrator
  • 9,374 posts
  • LocationWA

Posted 12 November 2017 - 07:24 PM   Best Answer

You have a much larger problem than just the styling of the comments: people can execute PHP code on your site, let alone put HTML (and Javascript) on your site.

Do you want people to write HTML? Please say no because allowing that is painful. Replace
<?php include "comments.html"; ?>
with
<?php readfile("comments.html"); ?>
and
fwrite($handle,"<b>" . $name . "</b>:<br/>" . $content . "<br/><br>");
with
fwrite($handle,"<b>" . htmlspecialchars($name) . "</b>:<br/>" . htmlspecialchars($content) . "<br/><br>");
Now go into your comments.html and make sure there isn't anything bad in it.

With that taken care of, find and fix the problem with your starting <head> tag. I expect the browser was able to recover gracefully from it, though, as you would have noticed otherwise.


Anyways,

If you need help with the appearance of your site then we need to see the HTML (your PHP isn't complicated so that's okay) and the CSS. Preferably with a link to the site, but don't provide a link until you do the comment thing I said above.
The Reimann Zeta Function Trolley Problem | "Summer is when I, the great ice fairy, can show my true power!"

#3 hgkhkhk

hgkhkhk
  • Members
  • PipPip
  • Member
  • 11 posts

Posted 12 November 2017 - 07:51 PM

@requinix

 

Thank you so much for your help. I have done everything as you explained above and have also managed to solve the styling problem. Your help is appreciated,






0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users