Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9076519
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T19:07:38+00:00 2026-06-16T19:07:38+00:00

I am trying to set the HTML title of a page dynamically from PHP.

  • 0

I am trying to set the HTML title of a page dynamically from PHP. I have a page which sets the title element based upon an entry in a database. I am trying to make the title change dynamically based on the current page’s H2 content. This content is, once again, retrieved from the database.

I have tried to do this using session variables, but obviously due to the load order this doesn’t work as the header is loaded, and then the content. On page refresh the title is then set correctly, but this is not good.

I currently am using JavaScript to update the title but again this is no good for search engine bot that don’t have JS enabled.

PHP

session_start(); <--both header and dynamic page -->

<title><?php echo $_SESSION['dynamictitle'];?></title> <-- Header -->

$jobTitle = $rs2row['fldRoleTitle']; <-- dynamic page -->

$_SESSION['dynamictitle'] = $jobTitle;

JavaScript

var currentTitle = "<?php Print($jobTitle) ?>" + " | " + document.title;
document.title = currentTitle;
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T19:07:39+00:00Added an answer on June 16, 2026 at 7:07 pm

    Separate the loading and processing of the data for the template from the actual output/rendering of the template, e.g. determine the variables before putting them in the template, e.g.

    <?php // handlerForThisPage.php
    
        session_start();
        $dynamicTitle = $_SESSION['dynamictitle'];
        …
        $jobTitle = $rs2row['fldRoleTitle'];
        …
    
        include '/path/to/header.html';
        include '/path/to/templateForThisPage.html';
    

    And then just echo the variables in the respective templates, e.g.

    // header.html
    <html>
        <head>
            <title><?php echo $dynamicTitle ?></title>
             …
    

    and whatever should go into templateForThisPage.html then. This is much more convenient and sane to maintain than having a linear script mixing data fetching, processing and output in one big messy file. If you want to extend on this approach, consider reading about the MVC pattern.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to get an html table from a dynamic php page on my
I'm trying to set my default page to Index.html on an ASP.NET site running
I'm trying to set a value from the database into a Html component, the
I am trying to access an HTML table from code behind, and set its
I have a HTML element <frame src=# title=Content Frame name=content id=content /> I want
Okay, so I have the form set to my PHP page. I also have
I'm trying to set up the SC html 5 api located here: http://w.soundcloud.com/player/api.js However
I am trying to set up a NSURLRequest to download a simple index.html with
How to set entire HTML in MSHTML? I am trying using this assignment: (Document
Following the spring-security documentation: http://static.springsource.org/spring-security/site/docs/3.0.x/reference/ldap.html I am trying to set up ldap authentication (very

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.