Mind blowing SEO improving and Google rank increasing Signature Rotator SEO Tool.

Thread: 

Dynamic Title Tag in PHP - How to

Ads
invisibe_dude Offline referral

Posts: 820
Joined: May 2013
Reputation: 24

#1
Posting Freak
Hi everyone here I will show you how to dynamically populate the title tag and description on a website. Add it to your index.php page. This code replaces title and description tags with the directory name. For instance: http://letsforum.com/Forum-Money-Making
This code will automatically set your title and description to "Forum Money Making".
Also this PHP code removes trailing slash!


Code:
<?php
echo '<title>'.str_replace("-", " ", basename(realpath('./'))).' - Your Extra Text</title>';
echo '<meta name="description" content="Your Extra Text - '.str_replace("-", " ", basename(realpath('./'))).'">';
?>
maya Offline referral

Posts: 1,058
Joined: May 2013
Reputation: 34

#2
Posting Freak
Great PHP tutorial. Could you tell me please add this php code to html?
invisibe_dude Offline referral

Posts: 820
Joined: May 2013
Reputation: 24

#3
Posting Freak
(06-26-2013 01:07 PM)Maya Wrote:  Great PHP tutorial. Could you tell me please add this php code to html?

Code:
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<?php
echo '<title>'.str_replace("-", " ", basename(realpath('./'))).' - Your Extra Text</title>';
echo '<meta name="description" content="Your Extra Text - '.str_replace("-", " ", basename(realpath('./'))).'">';
?>
<meta name="keywords" content="your separate keywords with commas">
</head>
<body>
</body>
</html>

Save it as index.php
gamer Offline referral

Posts: 192
Joined: May 2013
Reputation: 4

#4
Member
Actually pretty useful tutorial!
victor Offline referral

Posts: 638
Joined: Jun 2013
Reputation: 33

#5
Senior Member
WOW. I just used it and it works. I am using it to add tag links to my website
chod Offline referral

Posts: 860
Joined: Jul 2013
Reputation: 85

#6
Posting Freak
Have you tested this is XSS safe when being sent a crafted URL?
www.AdminEmpire.com
www.BlimptonTech.com - Best Free Online JavaScript tool to minify JavaScript files.
chod Offline referral

Posts: 860
Joined: Jul 2013
Reputation: 85

#7
Posting Freak
The reason I ask is doing things like this you can use a simple vector to close the title tag with encapsulated malicious code
Code:
</TITLE><SCRIPT>alert("XSS");</SCRIPT>

I wont show with anything malicious in it but this example should give you the idea of what can be done and like I said this is a pretty basic technique used.
I would play with this string and see what you can do with the code you posted and see what can be done to prevent issues or if you are preventing the issue, why? Wink Just a little exercise to try if you want.
Cool code, might be convenient and pretty. But secure then cool code is life long Tongue
www.AdminEmpire.com
www.BlimptonTech.com - Best Free Online JavaScript tool to minify JavaScript files.
invisibe_dude Offline referral

Posts: 820
Joined: May 2013
Reputation: 24

#8
Posting Freak
Hi chod sorry I didn't. One day I was trying to make something similar so my friend that knows more about PHP helped me.





User(s) browsing this thread: 1 Guest(s)