PDA

View Full Version : PHP Header Question



bigperm
June 16th, 2001, 18:15
Ok, I am retarded. I want to have a dynamic page title. So since I no exactly not ---- about PHP, I wanted to run this by yuse guys.

The header part

<html>
<head>
<title><?php echo "$title" ?></title>
<body>

Then in the main part I put

<?php $title="Silly Jews" ?>

What am I doing wrong?

You can see it at www.yupapa.com/~bigperm/test3.php

lucifer
June 16th, 2001, 18:26
try this (http://www.yupapa.com/~bigperm/test3.php?title=crazy)

just do <? $title="..."?> before you use it in <title>...

bigperm
June 16th, 2001, 19:32
Well, that works, but what I really want to do is be able to specify the title in the main part, and have the variable in the header.

I saw a website that shoed how to do this, but I never bookmarked it... something like <?php require "something" ?>

What is the require thing?

And is there any way to specify a variable on the main part and have it used in the header that is called from a different file?

Cheap Bastard
June 16th, 2001, 19:48
personally i prefer not to use require, but i'm just another moron.

if you use

<? include "file.extension"; ?>

you could basically make an extension to your dynamic title thing... (useful if you change titles a lot).
that way, you could make a file.extension and for example put in there

<?
$title_main = "Main page, enjoy";
$title_jews = "Silly Jews";
$something_else = "Another title";
?>

(doesn't have to have title in it, but it keeps things clear)
not sure if it needs those extra <? and ?> tags, and if it does not sure if the file.ext would have to be file.php or not (lucifer, help me out here)

like lucifer pointed out, if you wanted different titles for your page depending on, say, which link they click, you could use

main.php?title=Silly+Jews or
main.php?title=testing

(if i'm not wrong in this case the space would be encoded a + rather than a %20 as in normal URLs)

lucifer
June 16th, 2001, 19:56
i prefer include "..." but their's little in it - they work differently but it's not important yet

require inserts the info in the file specified into the file it's in

so if file bits.php3 is

<?
$title="my title";
$message="hello world";
?>

and mypage.php3 is

<HTML><HEAD>
<TITLE><? echo $title ?></TITLE>
</HEAD>
<BODY>
<? echo $message ?>
</BODY>
</HTML>

that what you wanted?

bigperm
June 16th, 2001, 20:48
I am not sure. On my site, every page will have the same header, pulled from the same file. With this, as it is, all of your pages have the same title. I want my pages to have a different title reflecting what they are. So my main page title may be "Bigperm Online", but I want my links page to have "Links" as the title.

So... I wanted to know how you could include a variable in the header file, and then define that variable in the main part of the page.

lucifer
June 17th, 2001, 05:58
so if file bits.php3 is

<?
$title="<<<$title>>>";
?>

and mypage.php3 is

<?
$ title="some crappy page";
include "bits.php3";
?>
<HTML><HEAD>
<TITLE><? echo $title ?></TITLE>
</HEAD>
<BODY>
<? echo $message ?>
</BODY>
</HTML>

I forgot the include last time too - doh