سؤال

(I'm a complete novice programmer)

I recently came across a problem with my custom CMS. I want to make it SEO friendly so I tried to echo out the title by the page loaded e.g.

www.blaa.com/index.php?page=about //code here grabs the required page title from the mysql db $title = $row['title']; <title><?php echo $title; ?></title>

I can't see if this actually worked because when I view source it only displays this code:

<table> <tr><td>Custom Module<br><br>

My custommodule cus any html goes in here

</td></tr> <tr><td>Menu Body <br><br> <a href='home.html'> home</a><br><a href='about page.html'> about page</a><br><br><br> </td></tr> <tr><td>body<br> cant believe im so a<br></div> </td></tr> <tr><td>Footer<br> links go here to various pages<br></td></tr> </table>

Is there a way to make all of the HTML code display in the view source?

هل كانت مفيدة؟

المحلول

You have to echo or print a variable to show it. You could also do a var_dump to check what the values are.

<?php
$title = isset($_GET['title'])? $_GET['title'] : "No title.";
?>
<!DOCTYPE html>
<html>
<head>
  <title><?php echo htmlspecialchars($title); ?></title>
</head>

I added htmlspecialchars to prevent script injection, I don't know if it would work in the title tag but I added it just in case. Plus you should know whenever you write user input into your HTML page you should use htmlspecialchars to cancel out any html code & scripts.

If your custom module is a load of HTML you wanted to display, you should use the inlude command:

<body>
<?php include("path/to/custom_module.php"); ?>
</body>
</html>

# custom_module.php
<div>Hello, I'm the custom module.</div>
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top