943,693 Members | Top Members by Rank

Ad:
  • PHP Discussion Thread
  • Unsolved
  • Views: 755
  • PHP RSS
Jul 30th, 2008
0

Specifying page title while using this script.. :(

Expand Post »
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

PHP Syntax (Toggle Plain Text)
  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!
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
lukus89 is offline Offline
1 posts
since Jul 2008
Sep 4th, 2008
0

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

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.
html Syntax (Toggle Plain Text)
  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).
Reputation Points: 27
Solved Threads: 16
Junior Poster
petr.pavel is offline Offline
116 posts
since Mar 2008
Sep 5th, 2008
0

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

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 ...

PHP Syntax (Toggle Plain Text)
  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
Reputation Points: 30
Solved Threads: 36
Posting Whiz
langsor is offline Offline
389 posts
since Aug 2008

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in PHP Forum Timeline: Help with preg_match
Next Thread in PHP Forum Timeline: php eway implemntation help need





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC