logo
Apache Lounge
Webmasters

 


About

Forum Index Downloads Search Register Log in  RSS Apache Lounge
 



Keep Server Online

If you find the Apache Lounge, the downloads and overall help useful, please express your satisfaction with a donation.

or

Bitcoin

A donation makes a contribution towards the costs, the time and effort that's going in this site and building.

Thank You! Steffen

Apache Lounge is not sponsored.

Your donations will help to keep this site alive and well, and continuing building binaries.



Putting info into a title of a page in php

 
Post new topic   Reply to topic    Apache Forum Index -> Coding & Scripting Corner



View previous topic :: View next topic  
Author Message
sb.net



Joined: 22 Sep 2006
Posts: 120
Location: USA

PostPosted: Fri 17 Nov '06 20:30    Post subject: Putting info into a title of a page in php Reply with quote

I have a page that includes a file and changes that include. But I need to put a variable in a title of a page and have it get the title from the include.

I have this title:
Code:
<title>Data_Base | </title>

I want to put a variable in it like this:
Code:
<title>Data_Base | <?php echo $pagetitle; ?></title>
In an include i want it to have:
Code:
$pagetitle="Home";
It would need to get the information from:
Code:
require("pages.php");


How would i do this.
Back to top
Brian



Joined: 21 Oct 2005
Posts: 209
Location: Puyallup, WA USA

PostPosted: Fri 17 Nov '06 22:13    Post subject: Reply with quote

Speaking only for myself, this makes no sense at all. I simply am lost after reading it five times.

What changes?

How do you know which file to include?

Just as an example, may wish to place all of your includes in a single folder. Then you can pass the title and part of the file name as in:

Code:
<?php

$page = $_GET['page'];

echo '<title>Data_Base | ' . $page . '</title>';

require( 'path/to/includes/' . $page . '.inc.php' );

?>


I am taking some liberties here and sort of applying what I am thinking you are trying to do, but again, I just don't understand the question(s)? as they are worded.

So you could place the includes into the path/to/includes/ directory, and then use a naming convention that follows this simple rule:

{name} . inc. php

...where the {name} is the variable you pass as a GET, POST, or what ever other means you see fit. You could even place it in an array, check to see that the name is in that array, and then do some sort of error correction, security stuff, and so on.

Maybe rephrase it, or perhaps others could better help. Sorry I could not do more.
Back to top
sb.net



Joined: 22 Sep 2006
Posts: 120
Location: USA

PostPosted: Fri 17 Nov '06 23:35    Post subject: Reply with quote

Yea, that wouldn't work. I have a couple sections on the site.
Back to top
Brian



Joined: 21 Oct 2005
Posts: 209
Location: Puyallup, WA USA

PostPosted: Sat 18 Nov '06 2:16    Post subject: Reply with quote

You know, at the risk of being a jerk, though just a little bit, the response back was weak. Look, I tried to figure out what you were asking, maybe others could also do a better job than I was able to. but if you are going to ask a question, and you really want the answer, try re-phrasing it or something, it would be nice to be able to assist you, but come on.

So, regarding the code, what part of it would not work, or what aspect was not included / considered?
Back to top
sb.net



Joined: 22 Sep 2006
Posts: 120
Location: USA

PostPosted: Sat 18 Nov '06 2:34    Post subject: Reply with quote

Sorry about that. Crying or Very sad

in the code you made:
Code:
$files = array(
   'animals' => array(
      'path'  => '/includes/animals/',
      'page'  => array(
         'dogs'         => 'dogs.inc.php',
         'cats'         => 'cats.inc.php',
         'birds'         => 'birds.inc.php',
      ),
   ),
   'foods' => array(
      'path'  => '/includes/foods/',
      'page'  => array(
         'fruit'         => 'fruit.inc.php',
         'vegetables'   => 'vegetables.inc.php',
         'bread'         => 'bread.inc.php',
         'meat'         => 'meat.inc.php',
      ),
   ),
   'places' => array(
      'path'  => '/includes/places/',
      'page'  => array(
         'london'      => 'london.inc.php',
         'newyork'      => 'nyc.inc.php',
         'tokyo'        => 'tokyo.inc.php',
         'sydney'      => 'sydney.inc.php',
      ),
   ),
);

i just need it to read a variable in any of those pages.
Back to top
sb.net



Joined: 22 Sep 2006
Posts: 120
Location: USA

PostPosted: Sun 19 Nov '06 0:52    Post subject: Reply with quote

I found the problem.

This is my default.php page:

Code:
<html>
<head>
<title>Data_Base | <?php echo "$page"; ?></title>
<link rel="stylesheet" type="text/css" href="style.css">
<meta name="description" content="Data_Base">
<meta name="keywords" content="data base, software, reviews, downloads, download, tips">
</head>
<body>
<?php
require("stars.php"); // stars script
require("header.php"); // loads the header (logo and google)
require("menu.php"); // loads the menu
require("pages.php"); // pages script
require("footer.php"); // loads the footer
?>
<body>
</html>


Notice the line
Code:
require("pages.php"); // pages script


This is what I have in pages.php:

Code:
$files = array(
   'animals' => array(
      'path'  => '/includes/animals/',
      'page'  => array(
         'dogs'         => 'dogs.inc.php',
         'cats'         => 'cats.inc.php',
         'birds'         => 'birds.inc.php',
      ),
   ),
   'foods' => array(
      'path'  => '/includes/foods/',
      'page'  => array(
         'fruit'         => 'fruit.inc.php',
         'vegetables'   => 'vegetables.inc.php',
         'bread'         => 'bread.inc.php',
         'meat'         => 'meat.inc.php',
      ),
   ),
   'places' => array(
      'path'  => '/includes/places/',
      'page'  => array(
         'london'      => 'london.inc.php',
         'newyork'      => 'nyc.inc.php',
         'tokyo'        => 'tokyo.inc.php',
         'sydney'      => 'sydney.inc.php',
      ),
   ),
);

This code switches "require("pages.php");" to a different page.

One of the pages that it will switch to is page.php. That page has in it:
Code:
$page = 'page';


So in theory it would display "Data_Base | page". Right? It doesn't. I have tested and I found you can not use variables (or functions) in includes.
Back to top
sb.net



Joined: 22 Sep 2006
Posts: 120
Location: USA

PostPosted: Wed 22 Nov '06 5:00    Post subject: Reply with quote

If anybody else wants to help i got more info. The include has to be before the echo of the variable. But the title tag is before the include. How would i fix this?
Back to top


Post new topic   Reply to topic    Apache Forum Index -> Coding & Scripting Corner
Page 1 of 1