page title in URLs

General discussions related to php

Moderators: egami, macek, gesf

Post Reply
User avatar
ejsexton82
New php-forum User
New php-forum User
Posts: 86
Joined: Mon Jun 04, 2012 10:05 pm
Location: Ankara, Turkey
Contact:

Tue Jun 05, 2012 10:38 am

So if you have some URL:

http://www.some.url/index.php?c_id=4&m=4&title=Page+Title

You can set the page title with the following code:

Code: Select all

<html>
	<head>
		<title><?php echo $_GET['title']; ?></title>
	</head>
	<body>
		<!-- Body Goes Here -->
	</body>
</html>

User avatar
ejsexton82
New php-forum User
New php-forum User
Posts: 86
Joined: Mon Jun 04, 2012 10:05 pm
Location: Ankara, Turkey
Contact:

Wed Jun 06, 2012 11:10 am

I am not sure you can do that without some sort of redirect:

Code: Select all

$pageTitle = urlencode('Title of the Page');
if(empty($_SERVER['QUERY_STRING']) || strpos($_SERVER['QUERY_STRING'],$pageTitle) === false) {
	if(empty($_SERVER['QUERY_STRING'])) {
		$queryString = $pageTitle;
	}
	else {
		$queryString = $_SERVER['QUERY_STRING'] . '&' . $pageTitle;
	}
	header("Location: ?{$queryString}");
	exit;
}
There may also be a way to accomplish the redirect using JavaScript.

Post Reply