• Some users have recently had their accounts hijacked. It seems that the now defunct EVGA forums might have compromised your password there and seems many are using the same PW here. We would suggest you UPDATE YOUR PASSWORD and TURN ON 2FA for your account here to further secure it. None of the compromised accounts had 2FA turned on.
    Once you have enabled 2FA, your account will be updated soon to show a badge, letting other members know that you use 2FA to protect your account. This should be beneficial for everyone that uses FSFT.

changing page title dynamically

se4b4ss

Gawd
Joined
Dec 29, 2000
Messages
513
how do i change the title of a page based on php content? for example, when i display a page dynamically created via php/db with a company's information, i'd like the title of the page to be the company's name.

here is an example:

linky

i'd like the page to be titled "legros home inspections."

thanks in advance,
steve
 
There are a few different ways. Probably most preferable is doing it server-side, specifying the title using some php.

Dynamically, using javascript, you set the window title using this code I believe:

Code:
window.title = 'Some text';
 
ok, i got it. don't know why i was thinking i should be titling the page after the header info was complete...i was trying to use ob_start, etc and was only complicating the issue. i am now using php/sql to find the company name while processing the header info and it is working on my test box. i'll put it live in a few minutes after some qc. :D

EDIT* - it's in production.

thanks,
steve
 
i would do something like this
Code:
<title><?php echo $record->company_name ?></title>
 
amidst my teaching myself php, i've created a class for beginning and ending a page. eventually i wanted to be able to add things to the title but couldn't because i already echoed the title. the answer was in fact output buffering.

i won't go and explain everything but feel free to look at/use my class.
http://zero.servequake.com/php/class.main.php.txt

a page might look like:
Code:
<?php
require_once 'inc/base.inc.php';

$thePage = new Page();

require_once 'inc/main.inc.php';

$thePage->foot();
?>
you'll need to remove the stuff i have for DBconnect, SQLquery, $cfg and more just because that's how i do it in my particular situation.

my header.inc.php looks like
Code:
<?php
if (eregi(basename(__FILE__), $_SERVER['PHP_SELF']))
    Header('Location: ./');

echo '<?xml version="1.0" encoding="UTF-8"?>' . "\n";
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
    <title>[color=orange]<?php echo $this->buildTitle();?>[/color]</title>
    <link rel="stylesheet" href="css/style.css" type="text/css" />
    <style type="text/css">
	    /* Use for non NS 4.7 css */
        /* @import "css/style2.css"; */
    </style>
	<script type="text/javascript" src="lib/external.js">
	</script>
</head>
<body>
<?php
echo "\n<table id=\"body\">\n" .
       "  <tr>\n";
require "inc/menu.inc.php";
?>
    <td id="main">
<?php require 'inc/top.inc.php'; ?>
as i've written it, buildTitle() seperates the title parts with '-'. this could of course be changed as needed. note that you use $this because of the scope of when it's included.

you can add something by calling $thePage->addToTitle('Text'[,'url/link/path']); to add parts. $thePage->buildNav() builds a breadcrumb type navigation like
Home > Section > Page
and makes them links for all but the last one (but you can override that).

...eventually i'll make some fuller documentation and put it on my site with my sqlquery class.
 
Back
Top