Hi there, I'm trying to write a small cms for my portfolio, the idea is that both the cms and the portfolio itself would be in both English and Spanish. Being identical in appearance and pulling data from two identical tables on the database with the texts on the two languages.

I have the database up and running etc.. but I wanted to make it as "intelligent as possible" so there is a minimum (if any) duplication of code...

I have register globals off so I'm using superglobal arrays. I've played around with things and it all works but what I've written doesn't look like the most efficient/ elegant solution so any suggestions would be greatly appreciated.

this is a testing file for the index page of the cms... I was thinking on braking it down afterwards so the top bit with the session and cookie management goes into an include file... (is that a good idea?)

here's the code...

PHP Code:
<?php


#if received a request to change language set new cookie and set the session
if (isset($_GET['changeLang'])) {

#get value from url
 
$value $_GET['changeLang'] ;

#set the cookie
setcookie ('CMS_lang'$valuetime()+3600'/');

### session start
session_start();
if (!isset(
$_SESSION['dataBaseTable'])) {
  
$_SESSION['dataBaseTable'] = "portfolioG_".$_COOKIE['CMS_lang'];
  }
  
header ("Location: ".$_SERVER['PHP_SELF'] ); 
}

#if thereis no cookie set it and start session
# default to english database 
if (!isset($_COOKIE['CMS_lang'])) {
setcookie ('CMS_lang''en'time()+3600'/');

### session start
session_start();
if (!isset(
$_SESSION['dataBaseTable'])) {
  
$_SESSION['dataBaseTable'] = "portfolioG_".$_COOKIE['CMS_lang'];
  }
  
header ("Location: ".$_SERVER['PHP_SELF'] ); 
}

# check  wheter the session is alive
### session start

# Do I have to do session_start(); for each page??

#session_start();
#if (!isset($_SESSION['dataBaseTable'])) {
  
$_SESSION['dataBaseTable'] = "portfolioG_".$_COOKIE['CMS_lang'];
 
# }
 
#print all cookies
print_r($_COOKIE);

?>

<!-- this are just testing links to swich the value of the cookie therefore the value of $_SESSION['dataBaseTable'] -->
<br />
<a href="<?php echo $_SERVER['PHP_SELF']."?changeLang=es" ?>">change to spanish</a>

<a href="<?php echo $_SERVER['PHP_SELF']."?changeLang=en" ?>">change to english</a>

<br /><a href="<?php echo $_SERVER['PHP_SELF'?>">reload</a>

<br /><br /><br /><hr>

<?php

#function db_connect - private generic function to connect to database
function db_connect() {
    
$hostname "";
    
$database "";
    
$username "";
    
$password "";
    
$link = @mysql_connect($hostname$username$password);
    if (!
$link) {
        echo(
"Unable to connect to database!");
        exit();
    }
    
mysql_select_db($database$link);
    return 
$link;
    
mysql_close($link);
}


#print contents of database
$db db_connect();
$langDB $_SESSION['dataBaseTable'];
$query "SELECT * FROM $langDB";
$result mysql_query($query) or die("SQL Error (in get list of projects): " mysql_error() . " in Query: $query");
while (
$row mysql_fetch_array($result)) {

echo     
"project:".$row['projectName']."\n".

# how do i mantain and access the value of the $_SESSION['dataBaseTable'] accross pages??

# will it be with the session_start(); on the included page??

        
"<a href=\"edit_project.php?projectID=$row[id]&lang=$_SESSION['dataBaseTable'] \">edit</a>  |".
        
"<a href=\"delete_project.php?projectID=$row[id]&lang=$_SESSION['dataBaseTable'] \">Delete</a>  |".
        
"<a href=\"image_add.php?projectID=$row[projectName]&lang=$_SESSION['dataBaseTable'] \">Add picture</a>".
        
"<br />";
    }
    
echo 
"<br /><a href=\"add_project.php?&lang=$_SESSION['dataBaseTable'] \"> ADD PROJECT </a>";
echo 
$strings["S_database"];

?>

I've included comments where I had doubts...

cheers