Tracking Forums, Newsgroups, Maling Lists
Home Scripts Tutorials Tracker Forums
 
  HOME    TRACKER    PHP




How To Dynamically Change Page Title Using Php And Require_once?


This is an elementary question, but I've not been able to find the
answer, so here goes:

I am developing a site using php. I have the html header information
in a file that I include in all the pages using the require_once
function.

That is, each page includes the line

<?require_once('PageStart.php')?>

The PageStart.php file essentially defines the header. Omitting the
boring stuff, it's laid out like so:

<html>
<head>
<title>The Title of the Page</title>
<?require_once('styles/PageStyles.css')?>
</head>

<boring stuff snipped>

This works great. The only complaint I have is that there are LOTS of
pages on the site, and using this approach means that every page is
titled "The Title of the Page" When scanning my browser history, I
could have surfed to 30 different pages in the site and they all have
the same title. Makes it hard to know which page I'd like to go back
to.

I'd like to have a way to pass a (sometimes) dynamically generated
page title to the PageStart.php file. I say sometimes because certain
pages (the Main one for example) will always have the same title, so
that could be passed statically. There is another series of pages in
which the same php file accesses a MySQL database to display
information about various family members, and I'd like that title to
be generated dynamically (for example, "All about Mary" or "All about
Ted" depending on the person being described in the page).

Now I KNOW that with php there's a way to do this. I just can't find
it.




View Complete Forum Thread with Replies

See Related Forum Messages: Follow the Links Below to View Complete Thread
Can I Change The Title Of A Page
Maybe this is a stupid question, but is it possible to randomly change the title of a page with PHP?

Dynamically Managing Certain Document Aspects (e.g. Title)
I have this Javascript code snippet which I add to the "onload" event
of the "<body>" tag:

document.title = document.getElementById('column_title').innerHTML;

The element id "columnt_title" is the id of a heading ("<h1>") on the
page that happens to be the title of the main article on that page.

I couldn't find this in the help or main reference documents on
php.org. I'm sure it's pretty simple. Is it....

Change Window Title Of WebServer
I have a webserver that I host. The problem is, when the URL is entered, it shows the IP address of the server in the address bar, and not the URL (i.e. www.mysite.com). The server used to be hosted by a company, but now we have them forward the URL requests to our server.

How To Change Data Dynamically ...
I'm developing a system where user has a previlage to select
his/her COUNTRY then STATE then CITY respectively. i've put all the
Country names, State names and City name in a Drop-Down combos which
is filled dynamically from the MySQL database. Now my problem is that
i want it in such a way that if one select USA as COUNTRY then all the
STATE(s) of USA should be displayed on the STATE combo not any other.
and then when user selects the STATE in the next combo the CITY combo
should be populated with cities related to that STATE only and not
with any other.

Dynamically Change META Tags
I am just wondering, if it is possible to dynamically change META tags through the use of PHP?

Any help is much appreciated. And yes, i am a beginner, on page 93 of Sam's PHP & MYSQL web development...

Making Dynamically Created Checkboxes Check On Value Change?
I have no idea if this is more a PHP question or Javascript question,
because my problem hinges equally on both.

I have a PHP script that queries a database and creates a list of rows
for each item, each with their own checkbox one can select to do stuff
later. The PHP script this form posts to creates an array of all the
selected checkboxes and does stuff.

But, on the form, I want to be able to have the checkboxes auto-check
when someone changes the value of a textfield on that row.

With some stuff cut out, here's what I have on the form:

<!-- Begin
function NotEmpty() {
if (document.f.trackno$oim.value!="") {
document.f.remship.checked = true ;
}
}
// End -->

<form name="f" id="f" method="post"
action="trackpareportproc.bkk">
<input name="remship[]" type="checkbox" value="$oim"
class="remship">
<input type="text" name="trackno$oim" size="40"
onBlur="NotEmpty();">

Obviously I think the problem rests in how do I get the JavaScript to
know which checkbox to check. I can't make the NAME for each checkbox
unique otherwise that would mess up the array that's created later
based on which checkboxes are selected.

How To Populate Selects With Years=>months=>days That Dynamically Change?
What I'm thinking of doing is in my admin page have three different selects. They will form the day of sales at my shop.

-YEAR- -MONTH- -DAY-

The years will have 2002 -> 2005 and the months will be the 12 months of the year of course but I need the number of days to change with the particular month selected.

Page Title
I have another post on here for this problem but I think I have overcomplicated the matter.. Ok in it's simplest form: Is there a way to retrieve the current page title and place it into a PHP variable?

something like"

$pagetitle = **** Title of the current page I'm viewing ****

How To Get Page Title, In Not An Easy Way
ok, here is the situation

i have included header.php into index file but
i have this in index.php:
[php]
switch($_GET['action']) {
case 'page':
$pages[0] = "news0.php";
$pages[1] = "news1.php";
.
.

if ($_GET['page'] != "") {
$to_include = $_GET['page'];
include ($pages[$to_include]);
}
break;
default:
include("news.php");
[php]


i tried all sort off stuff like implode, pregmatch,ordinary passing $title variable, $_PHPSELF, and nothing seems to be working.

all i want to do is to get title like domain.com-news.

can anybody give me a tip what should i do?

Page Title Into Database
i am trying to make a script that will get the title of a page amd add it to a database.
PHP Code:

Setting The Page Title
I want all of my web pages to look like this

<?php $title = 'My site'
include('http://mySite.com/layout/page_begin.php'); ?>
.... HTML of page body goes here
<?php include('http://mySite.com/layout/page_end.php'); ?>

But, I can't even get the first bit working :-(

here is page_begin.php

<META HTTP-EQUIV="Content-Type" CONTENT="text/html;
charset=ISO-8859-1">
<link type="text/css" rel="stylesheet" href="/layout.css">
<HTML>
<HEAD>
<TITLE>' <?php print $title ?> '</TITLE>
</HEAD>
<BODY>

The $title evaluates to an empty string - what obvious thing am I
overlooking? I thought that include would inline the php file, thus
making $title available.

Changing Title Of Page
does anyone know how to use PHP to change the title of a page?

Let's say my title is currently "GOGOGO" , but I want to add a string "$x" to it

so it says "GOGOGO $x", using PHP does anyone know how to do that?

Obtaining Page Title
I was wondering if someone could tell me the easiest way to obtaining the page title of a specific url? I've tried to use fopen and those functions but I got the below error.

QuoteWarning: fopen() [function.fopen]: URL file-access is disabled in the server configuration in /home/web/ute.php on line 2

Getting The Page Title For The Sub Menu?
how I could get the page title for the sub menu? I have been working on this one for hours and am getting nowhere. How can I make my php code display the syntax highlighting? I have forgotten. Code:

Page <title> From Include Variable?
I have something like this:

<title><?php print($pagetitle); ?></title>
<body>
<?php include("folders/my_include.php"); ?>
</body>
</html>

and my_include.php contains the value to the variable ($pagetitle). How do I
get the value before the code for the <title> is written. This is just a
basic example I used to try and put across my question, my site has a whole
bunch of includes dynamically generated from user input. I'd just like to
get the <title> to change according to a variable in the includes......but
Im stuck?

I should say also that all my includes have includes themselves, they
include a html template. So placing <?php include("folders/my_include.php");
?> before the title tag won't look very good :)

PHP To Grab Page TITLE And Check For 404 Help
I am looking for a way to pull the <TITLE> from a web page. Does anyone know
a PHP routine or method that can help?

Also, I am looking for a way to test if a page is active. The ping returns
the website is there (But also returns true on a 404 error), But I want to
know if a page is "dead" (404 or other error) or active.

How To Extract A Page Title From An HTML File
I am trying to extract the page title, description and keywords from an HTML page. Description and Keywords are easy, using get_meta_tags().

[PEAR:QuickForm] Dynamically Change A Dropdown Menu According To Another Menu?
I've been using QuickForm for a few months now and I am now given a
new challenge:

I've got a search form with a dozen of dropdown menus, the first
dropdown menu being "Brand". If you select either Brand A, B, C, D...
Z, the second dropdown menu "Model" must be dynamically changed to
model AA, AB, AC, AD..., according to the models manufactured by the
brand selected in the first box.

I've seen that done on quite a few sites, but never found if QuickForm
had a quick & clean way of doing that.

$title Not Displaying In <title>$title</title>
For some reason $title will not display in the <title></title> using print or echo. I've tried modifying the if staments to ifelse, and even fiddled with $_GET to get this working. Tried dbl/single quotes, even changed the variable around thinking $title might be a global. nothing working yet. Any ideas?

<?php
$page == 'home'
$title == "Welcome!";
if ($page == 'home') { $title == "Welcome!"; }
elseif ($page == 'about') { $title == "about us"; }
elseif ($page == 'products') { $title == "Products"; }
elseif ($page == 'services') { $title == "Services"; }
elseif ($page == 'repair') { $title == "Upgrades & Repairs"; }
elseif ($page == 'network') { $title == "Network Solutions"; }
?>
<html>
<head>
<meta http-equiv="Content-Language" content="en-us">
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<title>My Site - <?php print "$title";?></title>
</head>
<body bgcolor="#FFE0C1">
...

Dynamically Create New Web Page
i'm making a cms, and I have a good portion done, I have it set up where the admin can log in and create a new post which goes to the database. I am just wondering how I can make this post a new web page? I have been trying to study how they do it in wordpress but with no avail. Anyone have any suggestions?

Dynamically Create And Save Php Page
Here is my code:
$filepointer=fopen("http://www.mysite.org/usersetup/newusers/" . $SESSION_UID . "/configsite.php", "w+");

$data = "<? $name = ' . $datatosave. '
?>";

fputs($filepointer, $data);

fclose($filepointer);

My goal is to dynamically create a .php file with the contents of
<? $name = "variable data"; ?>

My code doesn't work. Something with the php page, I think. I and using similar code to populate .txt files with dynamic data, without variables, and it works file. Apparently, a quick change to .php is harder than I thought. I"ve even tried sending a simple line of data to the php page with no luck. Heck, I even tried doing it as a text file and rename to .php but it didn't like my rename.

Link To Form Results Page Dynamically
I have a dropdown box that pulls information from a database. What I want to achieve is that when a caller selects an option, the option determines that page that comes up.

I tried setting the form action to the name of the option, but this down not bring up anything; actually the resulting page is .php. I also tried moving the form action statement after ther selection, but that does not work either - the Submit button does not work. PHP Code:

How To Change One Page To Change All?
i need to know how to create a page where i only have to change one thing on one page so it changes that text or image on every page of my site. in other words i want to be able to create a template, so if i do want to vchange something in the duture, i only have to change on page, instead of changing each individual page.

Dynamically Populate Drop-down List And Dynamically Include Html File
We have a drop down list on a PHP page, with several product names, and
when people click one item, we will refresh the same page with the
product name as parameter, and in turn we want to include a HTML file
into the content area of the same page.

I know it is recommended to put everything into database, but we want
the web site to be very "portable", so the drop-downlist and the
content should both in text files.

Let's say the drop-down list will be poplulated from the product.txt
file, and there will be a file for each corresponding item in the
drop-down list. From the user point of view, if he wants to add a new
product, he will just need to open the product.txt file, and add a new
line with the product name, "Laptop", then add a new text file named
"laptop" in the same folder which contains the HTML fragment to be
included in the content area.

What is the easiest way to do this?

Change Data On The Same Page To Something Else
I'm trying to change data on this line of code using a drop down option box.

map.centerAndZoom(new GPoint(-79.89505, 40.85708), 10);

When the page opens I want the above data to be used.

I want to use a drop down menu to select a different radius. Lets say 30 miles. I want to update the page so that the above line of code will update and look like this.

map.centerAndZoom(new GPoint(-79.89505, 40.85708), 30);

Here is some sections of code I am using.

<form action='<?php echo $_SERVER['PHP_SELF'];?>' method='post'>
<select name="radius" class="selectBoxes">
<option value="20">20 miles</option>
<option value="30">30 miles</option>
<option value="40">40 miles</option>
</select>
<input type='submit' name='submit' value='Click To Update Map'>
</form>

<script>
map.centerAndZoom(new GPoint(-79.89505, 40.85708), 10);
</script>

Change Variable In Another Page
i have my form displaying information from my mssql database 1 record.  When i click next it goes to php page which from there i want to change the value of a variable in my other php page whihc loads the query for my form then reload my form page with the new record.

Detect Change Of Remote Page
i have some links on my site, i need to be absolutely sure that the
html has not been modified, even one character. i would rather not
rely on http headers, just the html (so it is not dependant on the
webserver). should i make a database to actually mirror the page, and
then check against my copy? any better ideas? :)

Page Info Change On Submit
I have a menu on my site that is all pulled out of a MySQL database. So the links actually look like this: <a href="about">About Us</a> And when the user clicks on this link I want the page to go to the database and get the info for "about" and then refresh the page and display the info.

Change The Web Page Contents On Click
I want to sort the data displayed on web page on click of button. I have a combo in which all user have to select the sort order in which he wants to see the data...(The combo box or drop down box contains values "Name, Department Salary and Grade")

The user select the order (say name) by clicking the combo box or drop down box. The moment the user releases the combo or drop down box, I want to refresh the page with new sort order.

Using A Link To Change Page Content
Basically I have a page to enter data into a mysql db via a form. After the data has been input, this form disappears and instead (on the same page) the data is shown in the same format, just not editable anymore.

What I need to do is have a link that will be able to switch between the two states, being 'edit' and 'view'.

Page Editor, Preview As Change
I have a simple html editor on my page that edits the left portion of my page. I wanted to know if I could make the left side of the page load the html from the textbox as I change the html in the textbox. Here is my code for the editing and such: Code:

I Need Information From To ......
I have to retrive the title tag information? can you tell me. i
am new to the php ........

can you give the example to get the information between <title> to </title> from the web page...... how shall i get it.

Convert ##TITLE## To $title
Im half way through making an article manager for a new site im launching. If i type ##TITLE## into a text box, when i display the artcile, how do i turn the placeholder ##TITLE## into $title of the article.

i looked at str_replace but i dont think thats what i need... i need something that searched through the text of a var and if it finds anything within ##*## to convert the * into the $var.

Refreshing A Page To Display Change In Data
I have a page that scrolls out information from a database. When one
of the records has been completed by the user, they press delete at
the end of the row, and it sends the record id to a processing page
that deletes that record from the database, then returns to the
scrolling page. However, the deleted record still shows on the page
until one presses the refresh tab on the browswer.

Is there some way I can have the page refresh when the processing is
done, so that the changes made will be reflected immidiatly, instead
of the user having to press the refresh button themselves?

Change An Image Based On Landing Page - Possible?
I have 2 landing pages and I need to display a different contact phone number as an image for each page.

The thing that's got me thinking is that I need this image (which is in a standard header file) to stay the same for each visitor across all the pages on my site, depending on which landing page they came in from. I need the phone number image to stay the same for 30 minutes even if a user revisits one or more of the landing pages within that 30 minutes.

So is a visitor comes in from landingpage1 they see phonenumber1 throughout the site for 30mins - if a visitor comes in from landingpage2 they see phonenumber2 across the site for 30mins. What would be the best way to do this? php? javascript? would it need cookies?

Best Way To Change Values Of Fields Depending On Page Function.
I have at the moment a create_user.php and edit_user.php

they are the same, create has <input type="text" value="" name="xx"> for a field, and edit has <input type="text" value="<?=$row['rowhere']?>" name="xx"> - I would much rather have just the one page where if page function was edit then it calls in the row otherwise leaves value blank. How can I do this other than

if ($pagefunction == "create") {
echo "<input type="text" value="" name="xx">";
}
elseif ($pagefunction == "edit") {
<input type="text" value="<?=$row['rowhere']?>" name="xx">
}

on every field!?

Change Zoom Level While Opening HTML Page
Can anybody tell, How will i change the Zoom Level while opening HTML
Page.

How To Change Template Menu Link Text Color For Page Currently Viewed ??
Say you have a left menu that stays the same on every page within in your site. Obviously you would make this menu a template or library item, so that when you edit one version, all the others are updated.

Let's say the left menu is the following:

Page_1
Page_2
Page_3

Now, when I am viewing Page_1, I want the "Page_1" text in the left menu to be red, so that the viewer knows what page they are on. When I click on the left menu link for "Page_2", then I want the "Page_1" text to go back to black and the "Page_2" text to be red.

Require_once()
require_once() does not include files if they were already included, does it mean that it would reuse the previous included file, and retain it as though it were included?

Require_once Problem
I hava several php files in different folders.

I tried to use relative paths. But when I call a script from another
folder that has another depth, it cannot find the files that are
embedded via require once within the included file.

sample:

fileA.php (in the root dir!)
-----
require_once 'common_inc.php'
....
-----

classes/fileB.php (in /classes)
-----
require_once '../fileA.php'
....
-----
No it trys to find the 'common_lib in the /classes folder insted of the
root dir.

Well, I tried now to specify absolute paths like
"http://127.0.0.1:8080/projectname/common_inc.php"
But it cannot be included then. Thats the browser string of the file.
Why doesn't it work?

How can I solve this problem?
It doesn't matter for me if relative or absolute paths specifications
are used. It should only work :)

Require_once() Errors
Im making a website and i am writing a php script for a register form. The script checks for required fields if a required field is missed out then a error is generated. I think the problem might be on the server site.

There errors i am getting are

Warning: require_once() [function.require-once]: open_basedir restriction in effect. File(/Connections/userlogin.php) is not within the allowed path(s): (/tmp:/usr/share/pear:/home/fhlinux169/m/maltmandarkblues.co.uk/user) in /home/fhlinux169/m/maltmandarkblues.co.uk/user/htdocs/Register.php on line 2

Warning: require_once(/Connections/userlogin.php) [function.require-once]: failed to open stream: Operation not permitted in /home/fhlinux169/m/maltmandarkblues.co.uk/user/htdocs/Register.php on line 2

Fatal error: require_once() [function.require]: Failed opening required '/Connections/userlogin.php' (include_path='.:/usr/share/pear-php5') in /home/fhlinux169/m/maltmandarkblues.co.uk/user/htdocs/Register.php on line 2

The code:

Problem With Require_once() In Windows
I have been hoping to use my laptop as a porta-server but ran into
this problem. It seems that require_once() is not working for me!

The child class file has a 'require_once()' to the parent class file
and I'm sure it is correct (this works fine in *nix environments). But
I get this error message:

Fatal error: Class sessionmodel: Cannot inherit from undefined class
model in ...includemodel-session.php on line 7

Anybody know what might be up with this?
I am using Windows XP Professional, with the latest apache 1.x and
php4. No extra libraries installed, everything pretty much default
settings.

Does Require_once Cache Files At All?
I have a file that looks like this: PHP Code:

Require_once, Undefined Function?
I have a script:

http://www.mydomain.com/test/admin/foo.php

That looks like this:
<?php
$baseDir = "http://" . $_SERVER[ "SERVER_NAME" ] . "/test";

require_once( $baseDir . '/helpers/helper.php' );

something();
?>

something() is a function in helper.php.

I get:
Call to undefined function: something() in
/home/mydomain/public_html/test/admin/foo.php on line 6

The require_once doesn't fail (well, I don't get an error message), so I'm
assuming that it finds helper.php OK. something() definitely exists in
helper.php.

If I put foo.php and helper.php in the same folder, lose all the $baseDir
crap and use require instead of require_once it works fine (not sure if it's
the $baseDir part or the require_once that is tripping it up), however I
need them to be in seperate folders and I'd rather use require_once than
require in case I end up including something twice by accident, it's so much
easier not to have to worry about it.

I've been fiddling with this for about an hour now and it's starting to get
really annoying.

Require_once('DB.php') Failure
I'm using a relatively simple php script to query a mySQL database and
return values formatted to a variable string for interpretation by an
embedded swf. There is one php file that handles the connection to the
db (db_login.php) and one that handles the query (db_getProjects.php).
If I call up the db_getProjects.php file it simply spits back a
"&varibale=value..." blah blah string. The problem is that it works
only half the time...it'll be fine for a while then simply stop working
at all for a while...then start working again. When it isn't working
it is failing to even get past the require_once('DB.php') statement -
anything after that is never reached.

What could I be doing that is causing the require_once('DB.php') to
fail after working flawlessly for stretches?

note: I am making sure to close the connection at the end of each DB
call, so I don't think its due to open DB connections piling up, though
that seems to be the only logical answer.

Undefined Variable With Require_once
I get the following notice whenever I try to call a function from my file :
Notice: Undefined variable: database_mainsqldb in F:mysiteSite Templateincludesmyfunc.php on line 7

this variable "$database_mainsqldb" is defined in this file "../Connections/mainsqldb.php" and I include this file like that:
<?php require_once('../Connections/mainsqldb.php'); ?>

I tried to use the same function in the same calling page and it work fine without the previous notice!! the error appear only when I try to call it from myfunc.php Code:

Callback Function And Require Or Require_once
I'm trying to get a handle on callback functions right now, but I'm not sure I understand them or even if they apply to my question.

Is there a way to have a user function taking place of the require or require_once which will perform the same thing of the php require, but will also do something else I want it to, like send me an email or make a log entry so that I can be on top of stuff like this and address it as it happens?

Does this have anything to do with a call back function? And I want the code to include a file to be the same:

require("filname.php");
or
require_once "filename.php";

Require_once Confussion - Compile Error..
If I understand the manual, require_once() is used when code should
only be included once. I have a funcs.php that contains several
functions used by various scripts. When I have a.php that uses
require_once('funcs.php'), then I start a script as follows:

<?php
require_once('funcs.php');
require_once('a.php'); // barfs here
// do some cool stuff
?>

I get an error from the Zend debugger, "Compile Error..funcs.php line
4 - Cannot redeclare func_name() (previously declared in funcs.php".
What am I doing wrong? The php manual says "if the code from a file
has already been included, it will not be included again".
Apparently, the require_once() function is not working or I'm not
understanding its' usage.

I can see were this could become a real nightmare trying to keep track
of what's included in deeply nested files. Is there a way to protect
against this error?

Require_once Fails With File In Same Directory
Has anyone come across this problem with require_once?

I was working on my local machine with apache and have included a file
like this:

require_once "welcome_patient.php";

Works fine, the file that "requires" this is in the same directory

/
/sections <- both file and required file in here
/images

On our live server, the require_once fails every time, include path
says: include_path='.:./includes:/usr/share/pear:'

Strange thing is, if I change require_once to include_once it works fine
but I'd prefer the script to fall over if it doesn't find the include.

PS. Only other difference between servers is my local machine is Windows
and live is Linux, but I checked the include path delimiters were correct.


Copyright © 2005-08 www.BigResource.com, All rights reserved