Specifying page title while using this script.. :(

Reply

Join Date: Jul 2008
Posts: 1
Reputation: lukus89 is an unknown quantity at this point 
Solved Threads: 0
lukus89 lukus89 is offline Offline
Newbie Poster

Specifying page title while using this script.. :(

 
0
  #1
Jul 30th, 2008
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

  1. 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!
Reply With Quote Quick reply to this message  
Join Date: Mar 2008
Posts: 100
Reputation: petr.pavel is an unknown quantity at this point 
Solved Threads: 14
petr.pavel's Avatar
petr.pavel petr.pavel is offline Offline
Junior Poster

Re: Specifying page title while using this script.. :(

 
0
  #2
Sep 4th, 2008
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.
  1. <script language="JavaScript">
  2. document.title = 'new title';
  3. </script>
This is just for the user though, search engines won't see it, they will still read the original value (Home).
Petr 'PePa' Pavel

The more information you give the more relevant answer you get.
Please consider using "Add to ... Reputation" and mark your thread as Solved if you found what you were looking for. By giving feedback you help others.
Reply With Quote Quick reply to this message  
Join Date: Aug 2008
Posts: 381
Reputation: langsor is an unknown quantity at this point 
Solved Threads: 33
langsor langsor is offline Offline
Posting Whiz

Re: Specifying page title while using this script.. :(

 
0
  #3
Sep 5th, 2008
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['act'] value ...

  1. <?php
  2. $act = $_GET['act'];
  3. if ( file_exists( "./pages/$act.php" ) ) {
  4. if ( !preg_match( "/^(http|https|ftp)\:\/\//i", $act ) ) {
  5. require( "./pages/$act.php" );
  6. $title = ucfirst( $act );
  7. }
  8. } else {
  9. require("./pages/home.php");
  10. $title = 'Home';
  11. }
  12. ?>
  13. <html>
  14. <head>
  15. <title><? print $title ?></title>
  16. </head>
  17. <body>
  18. ...
  19. </body>
  20. </html>

Cheers
Google is the answer to all of your questions -- the trick is knowing what question to ask in your specific predicament.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC