2

config.php ( edited but still have same problems ):

<?
$judul ="my site title";
?>

my index.php:

<?php
session_start();
include('config.php');
mysql_connect($server,$login,$pass) or die("Nggak bisa koneksi");
mysql_select_db($db);
$fail = "&nbsp;";
 ?>

<title><? echo "$judul"; ?></title>
</head> 

the result is my website title is

<? echo "judul; ?>

not like i want to...

Is there anything that I should change? the goal is: I want to put some variable like footer copyright title inside config.php so if I need to edit it's only need to edit config.php

----edited---- by the way thank you for all answer it is work now

i use @Tanuel comment

once again thankyou

i vote answer ( green checklist ) based on the first answer, since i use syntax from comment

5 Answers5

2

config.php

define('title','Hello Word');

index.php

include('config.php')

`<title><?php echo  title; ?></title>`
Parth Chavda
  • 1,819
  • 1
  • 23
  • 30
2

First, you have a mistake in your config.php. You forgot $. Second, you $judul is not declared in your index.php. May be you must change it to $title after correcting config.php?

nagiyevel
  • 397
  • 3
  • 16
0

Use this code

config.php

<?php
     define('title','my site title');
 ?>

my index.php

<?php
     session_start();
     include('config.php');
     mysql_connect($server,$login,$pass) or die("Nggak bisa koneksi");
     mysql_select_db($db);
     $fail = "&nbsp;";
 ?>

<title><?php echo title; ?></title>
</head> 
Ajeet Kumar
  • 805
  • 1
  • 7
  • 26
0

In config.php, the variable declaration is incorrect. Use the below code for that.

<?php
$title = "Site Title";
?>

If your idea was to define the title as a constant, use the below code instead (on config.php)

<?php
define('title',"Site Title");
?>

In the index.php, incorrect variable is used. Use $title to get the actual title initialized in config.php (if you are using variable to get title). Use the below code on index.php

<?php
session_start();
include('config.php');
mysql_connect($server,$login,$pass) or die("Nggak bisa koneksi");
mysql_select_db($db);
$fail = "&nbsp;";
 ?>
<head>
<title><?php echo $title; ?></title>
</head> 

If you want to use the constant instead, use the below code

<?php
session_start();
include('config.php');
mysql_connect($server,$login,$pass) or die("Nggak bisa koneksi");
mysql_select_db($db);
$fail = "&nbsp;";
 ?>
<head>
<title><?php echo title; ?></title>
</head> 
AeJey
  • 1,447
  • 20
  • 40
0

Define the variable config.php as global variable.

<?php
global $pageTitle;
$pageTitle = "Site Title";
?>

And in the index.php again you have to call it as global variable.

<?php
session_start();
include('config.php');
mysql_connect($server,$login,$pass) or die("Nggak bisa koneksi");
mysql_select_db($db);
$fail = "&nbsp;";

global $pageTitle;
 ?>
<head>
<title><?php echo $pageTitle; ?></title>
</head> 

If you want in multiple pages just use it like array. In config.php

<?php
global $pageTitle;
$pageTitle['page1'] = "Site Title 1";
$pageTitle['page2'] = "Site Title 2";
?>
Manish Rane
  • 559
  • 2
  • 5
  • 15