tothemax Posted September 9, 2007 Share Posted September 9, 2007 Ok I have a problem. The way my script is set up now, I have an index.php which calls on inc files. The problem is that each page (inc file) is using the title set in the php.index. My goal is to have a title for each page. I've looked and looked but can't find anything. Any help would be appreciated. Thanks. Quote Link to comment Share on other sites More sharing options...
tothemax Posted September 9, 2007 Author Share Posted September 9, 2007 Bump. Quote Link to comment Share on other sites More sharing options...
GingerRobot Posted September 9, 2007 Share Posted September 9, 2007 There's really no need to bump your post after half an hour. Anywho, you could do something along the lines of: <?php $page = $_GET['page'];//im assuming that the file you are including is being passed in the URL somehow. include('includes/'.$page.'.php');//again, no idea if this is how you are doing it - thats the trouble with no code being posted //use a switch statement: switch($page){ case 'page1': $title = 'Some title for page 1'; break; case 'page2': $title = 'A different title for page 2'; break; case 'page3': $title = 'Guess what? Another title'; break; default://if no page set - e.g. its just the index page $title = 'Welcome to my website'; break; } //further down your script echo '<title>'.$title.'</title>'; ?> Alternatively, you could define the $title variable within each page that you might include. You'd then set a title on the index page, which would be overridden if you do include a file. For example, index.php: <?php $title = 'Your default title'; $page = $_GET['page']; include('includes/'.$page.'.php'); //further down your script echo '<title>'.$title.'</title>'; ?> Then all of your files to be included: <?php $title = 'Your title for this page'; //the rest of your script ?> Quote Link to comment Share on other sites More sharing options...
tothemax Posted September 9, 2007 Author Share Posted September 9, 2007 Thanks for your help, I'll check back and let you know if it worked. And I apologize for the bump; I'm impatient, but certainly didn't mean to be disrespectful towards anyone. Quote Link to comment Share on other sites More sharing options...
tothemax Posted September 9, 2007 Author Share Posted September 9, 2007 I'm still having problems. I've created a test index.php to have this run correctly, but it's still using the default title. I'm not 100% sure where to put this: echo '<title>'.$title.'</title>'; ?> In the index.php. Quote Link to comment Share on other sites More sharing options...
GingerRobot Posted September 9, 2007 Share Posted September 9, 2007 Sorry, yes its late. That wasn't ever really going to work. Given that you're including a file each time, it should be a simple matter of defining the title in each of these pages. You should only show the title for the index file if no page has been included: <?php if(!isset($_GET['page'])){ ?> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <title>Welcome to my website. This is the Index page</title> </head> <body> Some content </body> </html> <?php }else{ include('includes/'.$_GET['page'].'.php'); } ?> On a side note, if you are including files in this manner, you would be wise to validate the input from the $_GET array to make sure the page you are including is supposed to included. Quote Link to comment Share on other sites More sharing options...
tothemax Posted September 9, 2007 Author Share Posted September 9, 2007 Problem solved. Thank you so much. I can't believe how hysterically easy that was. I want to hit myself hard. Quote Link to comment Share on other sites More sharing options...
GingerRobot Posted September 9, 2007 Share Posted September 9, 2007 No problem. Its always the easy ones that get you Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.