Hi All, i'm new here but hoping someone can give me some much needed help! :)

I'm new to PHP Completely, the script i currently use to pull pages for this website is something i borrowed from a freind.

I Kinda understand this one script, but the rest is unknown to me... so heres my issue.

This script pulls the pages when a user clicks a link

if (file_exists("./pages/$_GET[act].php")) { if (!preg_match("/^(http|https|ftp)\:\/\//i", $_GET[act])) { require("./pages/$_GET[act].php"); } } else { require("./pages/home.php"); }

Now, i specify the page title in the main index.php file, but that then means i can't change the page title by what page the user is going on :(

Example, on home.php (default) the page title is set to Home. If i put it on about, its still home even if in the about.php i set the title to About.

Please help if you can, i'd be very greatful! :)

I'm afraid you're not giving the full story here.
Is this script is embedded in a HTML document that has the Home title?
And you need to include (using require()) a part of this HTML document, right?
If my guesses are right then:

You cannot have two TITLE tags in one HTML document - there can only be one and it must be in HEAD (HEAD is at the very beginning of a HTML document). That's why you cannot use TITLE later on in the included file that comes into BODY part of the parent document.

The quick'n'dirty solution is to use JavaScript to change the title.

<script language="JavaScript">
document.title = 'new title';
</script>

This is just for the user though, search engines won't see it, they will still read the original value (Home).

Member Avatar for langsor

You might try using this at the very top of you page ...
and including the results of this in your title ...
or passing additional values along with your $_GET value ...

<?php
$act = $_GET['act'];
if ( file_exists( "./pages/$act.php" ) ) { 
  if ( !preg_match( "/^(http|https|ftp)\:\/\//i", $act ) ) { 
    require( "./pages/$act.php" );
    $title = ucfirst( $act );
  } 
} else { 
  require("./pages/home.php"); 
  $title = 'Home';
}
?>
<html>
<head>
<title><? print $title ?></title>
</head>
<body>
...
</body>
</html>

Cheers

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.