Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New to the CF scene
    Join Date
    Aug 2011
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Exclamation Dynamic title using PHP

    I know this topic is everywhere but I cant find a solution to my particular problem. I have been using a download center script for about a year. http://download.redgalaxy.net/ However, the title is static, keeping with the predefined one. I am trying to get the title to change so it matches the file name shown on the display page "index.php/?nav=display&file=25". I have spent days trying to figure something out with absolutely no luck. Does anyone have an idea how to get the title to change when dynamically? Out of desperation i used an onload javascript but it doesnt work with crawlers. Thank you in advanced.

    Index.php
    PHP Code:
    <?php
    /*
        PHP Download Center
        Copyright (C) 2007  Chris LaPointe

        This program is free software: you can redistribute it and/or modify
        it under the terms of the GNU General Public License as published by
        the Free Software Foundation, either version 3 of the License, or
        (at your option) any later version.

        This program is distributed in the hope that it will be useful,
        but WITHOUT ANY WARRANTY; without even the implied warranty of
        MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
        GNU General Public License for more details.

        You should have received a copy of the GNU General Public License
        along with this program.  If not, see <http://www.gnu.org/licenses/>.
    */

    //error_reporting(E_ERROR);
    define("PHP_DOWNLOADCENTER"1);
    include_once(
    'settings.php');

    //Include all files in 'inc' directory
    $path 'inc/';
    $handle opendir($path);
    while (
    false !== ($file readdir($handle))) {
        if (
    substr($file01) != '.')
            include(
    $path.$file);
    }
    closedir($handle); 


    //Start session for me!
    session_start();
    if (
    mysql_connect($mysql_host$mysql_username$mysql_password) == FALSE){
        if (
    file_exists("install.php")){
            echo 
    '<HTML><HEAD><meta http-equiv="refresh" content="0;url=install.php"></HEAD></HTML>';
            exit;
        }else{
            die(
    "Fatal error.  Unable to access database.  In addition, unable to go to install.php to setup access!");
        }
    }
    if (
    mysql_select_db($mysql_database) == FALSE){
        if (
    file_exists("install.php")){
            echo 
    '<HTML><HEAD><meta http-equiv="refresh" content="0;url=install.php"></HEAD></HTML>';
            exit;
        }else{
            die(
    "Fatal error.  Unable to access database.  In addition, unable to go to install.php to setup access!");
        }
    }

    //because of the way it is handled, there should never be any HTML passed via arguments
    //do a check here
    foreach ($_GET as $key => $value){
        
    $_GET[$key] = strip_tags(html_entity_decode($valueENT_NOQUOTES), '<i><b>');
    }

    //Run the now (Just code, ie login code)
    if ( isset($_GET['now']) ){
        
    $nowfile "pages/".$_GET['now'].'.now.php';
        if (
    file_exists($nowfile)){
            include(
    $nowfile);
        }else{
            echo 
    "<b>Warning:</b> Now file '$nowfile' doesn't exist";
        }
    }

    ?>


    <HTML>
    <HEAD>
    <TITLE><?php echo $page_title?></TITLE>
    <link rel="stylesheet" type="text/css" href="style.css">
    </HEAD>


    <BODY>


    <!--TOP SECTION (banner)-->
    <table width=100% border=0 cellspacing=2 cellpadding=0>
    <TR>
        <TD valign="top"><img src="theme/page/banner.gif"></TD>
        <TD valign="middle"><div align="right"><?php include('ads/ad_top.php'); ?></div></TD>
    </TR>
    </TABLE>

    <!--MIDDLE SECTION-->
    <table width=100% border=0 cellspacing=2 cellpadding=0>
    <TR>
        <TD width=150px valign="top"><?php require('left.php'); ?></TD>
        <TD valign="top">
            <table width=100% border=0 cellspacing=2 cellpadding=0>
                <TR><TD><?php include('nav.php'); ?></TD></TR>
                <TR><TD><?php include('body.php'); ?></TD></TR>
            </table>
        </TD>
    </TR>
    </table>

    <BR>
    <div align="center"><font size="1">
    This page is under the <a href="http://gplv3.fsf.org/">GPLv3</a> by <a href="http://www.redgalaxy.net" target="_blank">Red Galaxy</a>.  Each file is copyrighted by its respective owner.<BR>
    This page is not to be held responsible for any uploaded files.  It is each user's responsibility to check the legality of files they upload.<BR>
    Please contact <i><?php echo $info_name?></i> at <?php echo str_replace('@'"'AT'"str_replace('.'"'DOT'"$info_email)); ?> with any questions.<BR>
    <?php echo $info_misc?></font>
    </div>

    </BODY>
    </HTML>

    <?php
    mysql_close
    ();
    ?>
    nav.php
    PHP Code:
    <?php
    if (!defined('PHP_DOWNLOADCENTER'))
        exit;
    ?>

    <table width=100% border=0 cellspacing=0 cellpadding=0>
    <TR>
    <TD>
    <a href="?nav=home">Home</a> | <a href="?nav=recent">Recent Files</a>
    </TD>
    <TD align="right">
    <form action="?nav=search_results" method="post"><INPUT type="text" size="20" name="search"><INPUT type="submit" value="Search"></form>
    </TD>
    </table>
    body.php
    PHP Code:
    <?php
    if (!defined('PHP_DOWNLOADCENTER'))
        exit;

    if (!isset(
    $_GET['nav'])){
        
    $location 'pages/home.php';
    }else{
        
    $location 'pages/'.$_GET['nav'].'.php';
    }

    if (isset(
    $_GET['message'])){
        echo 
    '<div align="center">';
        echo 
    BeginBorder("Message""50%");
        echo 
    stripslashes(urldecode($_GET['message']));
        echo 
    EndBorder();
        echo 
    '</div>';
    }

    if (
    file_exists($location))
        include(
    $location);
    else
        include(
    "pages/404.php");


    ?>

    display.php
    PHP Code:
    <?php

    $fid 
    $_GET['file'];
    $results mysql_query("SELECT * FROM files WHERE id=$fid LIMIT 1");
    if (
    mysql_numrows($results) == 0){
        echo 
    "File not found.  It may have been removed.";
        return;
    }

    $who getUserNameById(mysql_result($results,0,"uid"));

    echo 
    BeginBorder(mysql_result($results0"title"), "90%");

    ?>
    <TABLE width=100% border=0 cellspacing=0 cellpadding=0>
    <TR><TD width=50% valign="top">
    <TABLE width=100% border=0 cellspacing=1 cellpadding=2>
    <TR bgcolor=#F0F0F0>
        <TD width=50%>Name:</TD>
        <TD><?php echo mysql_result($results0"title"); ?></TD>
    </TR>
    <TR bgcolor=#F0F0F0>
        <TD>File:</TD>
        <TD><?php echo mysql_result($results0"filename"); ?></TD>
    </TR>
    <TR bgcolor=#F0F0F0>
        <TD>Size:</TD>
        <TD><?php echo roundmysql_result($results0"filesize")/1024/1024,2).'MB'?></TD>
    </TR>
    <TR bgcolor=#F0F0F0>
        <TD>Extension:</TD>
        <TD><?php echo mysql_result($results0"filetype"); ?></TD>
    </TR>
    <TR bgcolor=#F0F0F0>
        <TD>Category:</TD>
        <TD><?php echo mysql_result($results0"category"); ?></TD>
    </TR>
    <TR bgcolor=#F0F0F0>
        <TD>User:</TD>
        <TD><?php echo $who?></TD>
    </TR>
    <TR bgcolor=#F0F0F0>
        <TD>Date Uploaded:</TD>
        <TD><?php echo mysql_result($results0"date"); ?></TD>
    </TR>
    <TR bgcolor=#F0F0F0>
        <TD>Download Count:</TD>
        <TD><?php echo mysql_result($results0"dcount"); ?></TD>
    </TR>
    <TR bgcolor=#F0F0F0>
        <TD>Downloads This Month</TD>
        <TD><?php echo mysql_result($results0"dmonth"); ?></TD>
    </TR>
    </TABLE>
    </TD>
    <TD valign="top">
    <center>
    <a href="<?php echo '?nav=download&file='.$fid?>"><img src="theme/download.png" border=0></a>
    <?php
    if (mysql_result($results0'private') == '1')
        echo 
    "<br>You must be logged in to download this file.</b>";
    ?>
    </center><BR><BR>
    <?php
    //PREVIEW IMAGE IF EXISTS
    $realname mysql_result($results0"filename");
    $small_preview 'images/'.$realname.'.small.jpg';
    $large_preview 'images/'.$realname.'.large.jpg';
    if (
    file_exists($small_preview)){
        echo 
    "<div align='center'><a href='$large_preview' target='_blank'><img src='$small_preview' border='0'></a></div><BR>";
    }


    //ADMIN CONTROLS
    if (isUserAdmin()){
        echo 
    '<b>Admin:</b> <a href="?nav=delete&file='.$fid.'">Delete This File</a> | <a href="?nav=edit&file='.$fid.'">Edit</a><BR>';
    }
    ?>
    </TD></TR>

    </TABLE>

    <HR>
    <b>Description:</b><BR>
    <?php echo mysql_result($results0"description"); ?>


    <?php
    echo EndBorder();
    ?>
    Last edited by rpcob; 08-30-2011 at 08:27 PM.

  • #2
    Regular Coder dniwebdesign's Avatar
    Join Date
    Dec 2003
    Location
    Carrot River, Saskatchewan
    Posts
    846
    Thanks
    15
    Thanked 10 Times in 10 Posts
    Try this as your index.php page...

    Basically, all you have to do, is select the title of the download file and store it however you want before you set the <title> tags. Such as I did. It checks for the "nav" variable to make sure it's for the display page and should show the title of the download in the title bar.

    index.php
    PHP Code:
    <?php
    /*
        PHP Download Center
        Copyright (C) 2007  Chris LaPointe

        This program is free software: you can redistribute it and/or modify
        it under the terms of the GNU General Public License as published by
        the Free Software Foundation, either version 3 of the License, or
        (at your option) any later version.

        This program is distributed in the hope that it will be useful,
        but WITHOUT ANY WARRANTY; without even the implied warranty of
        MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
        GNU General Public License for more details.

        You should have received a copy of the GNU General Public License
        along with this program.  If not, see <http://www.gnu.org/licenses/>.
    */

    //error_reporting(E_ERROR);
    define("PHP_DOWNLOADCENTER"1);
    include_once(
    'settings.php');

    //Include all files in 'inc' directory
    $path 'inc/';
    $handle opendir($path);
    while (
    false !== ($file readdir($handle))) {
        if (
    substr($file01) != '.')
            include(
    $path.$file);
    }
    closedir($handle); 


    //Start session for me!
    session_start();
    if (
    mysql_connect($mysql_host$mysql_username$mysql_password) == FALSE){
        if (
    file_exists("install.php")){
            echo 
    '<HTML><HEAD><meta http-equiv="refresh" content="0;url=install.php"></HEAD></HTML>';
            exit;
        }else{
            die(
    "Fatal error.  Unable to access database.  In addition, unable to go to install.php to setup access!");
        }
    }
    if (
    mysql_select_db($mysql_database) == FALSE){
        if (
    file_exists("install.php")){
            echo 
    '<HTML><HEAD><meta http-equiv="refresh" content="0;url=install.php"></HEAD></HTML>';
            exit;
        }else{
            die(
    "Fatal error.  Unable to access database.  In addition, unable to go to install.php to setup access!");
        }
    }

    //because of the way it is handled, there should never be any HTML passed via arguments
    //do a check here
    foreach ($_GET as $key => $value){
        
    $_GET[$key] = strip_tags(html_entity_decode($valueENT_NOQUOTES), '<i><b>');
    }

    //Run the now (Just code, ie login code)
    if ( isset($_GET['now']) ){
        
    $nowfile "pages/".$_GET['now'].'.now.php';
        if (
    file_exists($nowfile)){
            include(
    $nowfile);
        }else{
            echo 
    "<b>Warning:</b> Now file '$nowfile' doesn't exist";
        }
    }
    if(
    $_GET["nav"]=="display") {
        
    $fid $_GET['file'];
        
    $results mysql_query("SELECT * FROM files WHERE id=$fid LIMIT 1"); 
        
    $page mysql_result($results0"title");
        
    $page_title "DNI Web Design :: Download Center :: $page";
    }
    else {
        
    $page_title "DNI Web Design :: Download Center";
    }
    ?>


    <HTML>
    <HEAD>
    <TITLE><?php echo $page_title?></TITLE>
    <link rel="stylesheet" type="text/css" href="style.css">
    </HEAD>


    <BODY>


    <!--TOP SECTION (banner)-->
    <table width=100% border=0 cellspacing=2 cellpadding=0>
    <TR>
        <TD valign="top"><img src="theme/page/banner.gif"></TD>
        <TD valign="middle"><div align="right"><?php include('ads/ad_top.php'); ?></div></TD>
    </TR>
    </TABLE>

    <!--MIDDLE SECTION-->
    <table width=100% border=0 cellspacing=2 cellpadding=0>
    <TR>
        <TD width=150px valign="top"><?php require('left.php'); ?></TD>
        <TD valign="top">
            <table width=100% border=0 cellspacing=2 cellpadding=0>
                <TR><TD><?php include('nav.php'); ?></TD></TR>
                <TR><TD><?php include('body.php'); ?></TD></TR>
            </table>
        </TD>
    </TR>
    </table>

    <BR>
    <div align="center"><font size="1">
    This page is under the <a href="http://gplv3.fsf.org/">GPLv3</a> by <a href="http://www.redgalaxy.net" rel="nofollow" target="_blank">Red Galaxy</a>.  Each file is copyrighted by its respective owner.<BR>
    This page is not to be held responsible for any uploaded files.  It is each user's responsibility to check the legality of files they upload.<BR>
    Please contact <i><?php echo $info_name?></i> at <?php echo str_replace('@'"'AT'"str_replace('.'"'DOT'"$info_email)); ?> with any questions.<BR>
    <?php echo $info_misc?></font>
    </div>

    </BODY>
    </HTML>

    <?php
    mysql_close
    ();
    ?>
    Dawson Irvine
    CEO - DNI Web Design
    http://www.dniwebdesign.com

  • #3
    New to the CF scene
    Join Date
    Aug 2011
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts
    thank you. that worked exactly as i need it to.

  • #4
    New to the CF scene
    Join Date
    Aug 2011
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Just as an addition for anyone that found this useful the following is needed if the file was deleted

    PHP Code:
    if($_GET["nav"]=="display") {
        
    $fid $_GET['file'];
        
    $results mysql_query("SELECT * FROM files WHERE id=$fid LIMIT 1"); 
        if (
    mysql_numrows($results) == 0){
            
    $page_title "Coding - File Not Found";
        }
        else {
        
    $titlename mysql_result($results0"title");
        
    $page_title "Coding - $titlename";
        }
    }
    elseif (
    $_GET["nav"]=="recent") {
        
    $page_title "Coding - Recent Downloads";
    }
    elseif (
    $_GET["nav"]=="browse") {
        
    $page_title "Coding - Downloads";
    }
    elseif (
    $_GET["nav"]=="popular") {
        
    $page_title "Coding - Popular Downloads";
    }
    elseif (
    $_GET["nav"]=="cat") {
        
    $page_title "Coding - Download Categories";
    }
    elseif (
    $_GET["nav"]=="search_results") {
        
    $page_title "Coding - Search Results";
    }
    elseif (
    $_GET["nav"]=="download") {
        
    $fid $_GET['file'];
        
    $results mysql_query("SELECT * FROM files WHERE id=$fid LIMIT 1"); 
        
    $titlename mysql_result($results0"title");
        
    $page_title "Coding - Downloading: $titlename";
    }
    else {
        
    $page_title "Coding - Downloads";



  •  

    Tags for this Thread

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •