Page 1 of 1

Defining <title>

Posted: Sat Apr 21, 2007 10:14 pm
by ScottByers
feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


I'm trying to make part of my title custom, defined on each page of my site, with the other part displayed on every page.

So it will look like...

[b]Specific Page Title | Domain.com[/b]

but I can't seem to get it to work. Here is my current code on the main page...

Code: Select all

<?php
define ('TITLE', 'Page Title Here'); 
//requre the header file      
require('http://domain/includes/header.php');
include('http://domain.com');
?>
And on the header.php...

Code: Select all

<title><?php if (defined ('TITLE')) {
                    print TITLE;
                } else {
                    print 'Site Title Not Set.';
                    }
        ?></title>
But it always seems to display "Site Title Not Set", rather than the title I've defined within the page.

Any idea what I could be doing wrong? I'm very much a beginner when it comes to php, so don't laugh if my code is terribly stupid :oops:

Thanks in advance :)


feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]

Re: Defining <title>

Posted: Sat Apr 21, 2007 10:25 pm
by volka
ScottByers wrote:require('http://domain/includes/header.php');
Why is it a request via http:// ?

webserver gets a request via http. It is configured to let php handle the request for a .php file. A new instance of php is created. This instance reads the source code from the .php file. The php instance processes the script. The output is sent to the client. When the script is done the php instance is removed.

require('http://domain/includes/header.php');
php sends a http request for /includes/header.php to the server domain via http.
domain is configured to let php handle requests for .php file. A new instance of php is created. This instance reads the source code from the file includes/header.php. The new php instance processes the script. There's no TITLE defined in the new instance -> Site Title Not Set. The output is sent back to the client which is the php instance processing the require.

Posted: Sat Apr 21, 2007 10:37 pm
by ScottByers
I changed it to ../includes/header.php and it seems to work.

Thanks a bunch :D