PHP variable problem

Discuss all aspects of programming here.

Moderator: The Mod Squad

PHP variable problem

Postby filecore » Sat Apr 21, 2007 4:10 am

Hope you guys can help. I'm trying to set up a program on my site but whenever it reaches the same variable, it stops. The files are PHP. Basically, I have a folder in the root dir called /admin, and another folder called /English, which is set in my admin panel as my default language. The beginning of each document with the problem looks like this:

<?php
include("../config.php");
include("adminlib.php");
$textpart = "eventtypes";
include("../getlang.php");
include("../$mylanguage/admintext.php");
tng_db_connect($database_host,$database_name,$database_username,$database_password) or exit;
include("checklogin.php");


The problem is, when the server parses the file in question, I get the following errors, which seem to indicate that when the line in bold above is parsed, it's not read properly by the server (the variable $mylanguage seems to be missing):

Warning: include() [function.include]: Unable to access ..//admintext.php in /usr/local/psa/home/vhosts/mysite.com/subdomains/family/httpdocs/admin/index.php on line 6

Warning: include(..//admintext.php) [function.include]: failed to open stream: No such file or directory in /usr/local/psa/home/vhosts/mysite.com/subdomains/family/httpdocs/admin/index.php on line 6

Warning: include() [function.include]: Failed opening '..//admintext.php' for inclusion (include_path='.:') in /usr/local/psa/home/vhosts/mysite.com/subdomains/family/httpdocs/admin/index.php on line 6


Any ideas? I'm not terribly brilliant at PHP so I might be missing something silly and obvious.
Home server: Asus P5Q Pro, Core2Quad, 8GB DDR2, ENGTX260 876MB, Zalman 800w, Antec P180 case, 2x1TB and 2x2TB Samsung Spinpoint F1, Windows 7 64-bit, etc

Work server: HP ProLiant ML350 G6, hexacore Xeon E5645 2.4GHz (12 logical cores), 16GB DDR3, 3x300GB SAS RAID5, Server 2008 R2, nVidia GT560Ti 1GB for Hyper-V RemoteFX acceleration
filecore
Black Belt 1st Degree
Black Belt 1st Degree
 
Posts: 1092
Joined: Mon Dec 29, 2003 10:35 am
Location: Trapped inside a virtual machine.

Postby Toby B. » Sat Apr 21, 2007 4:40 am

basically the problem is the setup of the file structures.... As it stands not the code is trying to find a file that does not exist....

Not sure how to go about it, but:
Code: Select all
include("../$mylanguage/admintext.php");


Does not physically exist. The language folder is a seperate folder all together, and the admin file is not in that directory. I understand what you are trying to accomplish but do not know the coarse of action to get there.
Toby B.
Lead Mobo-fu Master
Lead Mobo-fu Master
 
Posts: 14277
Joined: Sun Dec 16, 2001 1:01 am
Location: Maine

Postby filecore » Sat Apr 21, 2007 4:44 am

If I change ../$mylanguage/whatever.php to ../English/whatever.php, then it finds the folder it wants. The problem is that I want dynamic language choice, not to hardcode everything to be English.
Home server: Asus P5Q Pro, Core2Quad, 8GB DDR2, ENGTX260 876MB, Zalman 800w, Antec P180 case, 2x1TB and 2x2TB Samsung Spinpoint F1, Windows 7 64-bit, etc

Work server: HP ProLiant ML350 G6, hexacore Xeon E5645 2.4GHz (12 logical cores), 16GB DDR3, 3x300GB SAS RAID5, Server 2008 R2, nVidia GT560Ti 1GB for Hyper-V RemoteFX acceleration
filecore
Black Belt 1st Degree
Black Belt 1st Degree
 
Posts: 1092
Joined: Mon Dec 29, 2003 10:35 am
Location: Trapped inside a virtual machine.

Postby Toby B. » Sat Apr 21, 2007 5:29 am

filecore wrote:If I change ../$mylanguage/whatever.php to ../English/whatever.php, then it finds the folder it wants. The problem is that I want dynamic language choice, not to hardcode everything to be English.
Like I said I know what you want to do just dont know exactly how to do it.

But the problem is the way the code is being interpited, its trying to find a page in a folder named $mylanguage and not interpiting the $mylanguage as English.
Toby B.
Lead Mobo-fu Master
Lead Mobo-fu Master
 
Posts: 14277
Joined: Sun Dec 16, 2001 1:01 am
Location: Maine

Postby filecore » Sat Apr 21, 2007 11:43 am

Incidentally, the PHP retrieves the language via this method:

<?php
@ini_set( "session.bug_compat_warn", "0" );
session_start();
session_register('session_language');
session_register('session_charset');
$session_language = $HTTP_SESSION_VARS[session_language];
$session_charset = $HTTP_SESSION_VARS[session_charset];
if( $session_language )
$mylanguage = $session_language;
elseif( $HTTP_COOKIE_VARS[tnglangfolder] ) {
$mylanguage = $HTTP_COOKIE_VARS[tnglangfolder];
$session_language = $HTTP_SESSION_VARS[session_language] = $mylanguage;
$session_charset = $HTTP_SESSION_VARS[session_charset] = $HTTP_COOKIE_VARS[tngcharset];
}
else {
$mylanguage = $lang ? $lang : $language;
$session_language = $HTTP_SESSION_VARS[session_language] = $language;
}
if( !$session_charset )
$session_charset = $HTTP_SESSION_VARS[session_charset] = $charset;
?>
Home server: Asus P5Q Pro, Core2Quad, 8GB DDR2, ENGTX260 876MB, Zalman 800w, Antec P180 case, 2x1TB and 2x2TB Samsung Spinpoint F1, Windows 7 64-bit, etc

Work server: HP ProLiant ML350 G6, hexacore Xeon E5645 2.4GHz (12 logical cores), 16GB DDR3, 3x300GB SAS RAID5, Server 2008 R2, nVidia GT560Ti 1GB for Hyper-V RemoteFX acceleration
filecore
Black Belt 1st Degree
Black Belt 1st Degree
 
Posts: 1092
Joined: Mon Dec 29, 2003 10:35 am
Location: Trapped inside a virtual machine.

Postby filecore » Tue Apr 24, 2007 1:32 am

I think I have a solution - apparently it's looking for the webserver root and not the account's root directory, so I need to append this before the include:

$_SERVER['DOCUMENT_ROOT'].


Ie:

include ($_SERVER['DOCUMENT_ROOT'].'/text.php');


I'll give it a try now...
Home server: Asus P5Q Pro, Core2Quad, 8GB DDR2, ENGTX260 876MB, Zalman 800w, Antec P180 case, 2x1TB and 2x2TB Samsung Spinpoint F1, Windows 7 64-bit, etc

Work server: HP ProLiant ML350 G6, hexacore Xeon E5645 2.4GHz (12 logical cores), 16GB DDR3, 3x300GB SAS RAID5, Server 2008 R2, nVidia GT560Ti 1GB for Hyper-V RemoteFX acceleration
filecore
Black Belt 1st Degree
Black Belt 1st Degree
 
Posts: 1092
Joined: Mon Dec 29, 2003 10:35 am
Location: Trapped inside a virtual machine.

Postby rilorilo » Fri May 11, 2007 3:15 pm

Dunno if you have solved your problem.

Line 6:
Code: Select all
include("../$mylanguage/admintext.php");


Should proberly be:
Code: Select all
include("../".$mylanguage."/admintext.php");
rilorilo
Initiate
Initiate
 
Posts: 23
Joined: Fri May 11, 2007 12:57 pm
Location: Denmark

Postby filecore » Sat May 12, 2007 1:04 am

Thanks, I'll give that a try at some point this weekend...
Home server: Asus P5Q Pro, Core2Quad, 8GB DDR2, ENGTX260 876MB, Zalman 800w, Antec P180 case, 2x1TB and 2x2TB Samsung Spinpoint F1, Windows 7 64-bit, etc

Work server: HP ProLiant ML350 G6, hexacore Xeon E5645 2.4GHz (12 logical cores), 16GB DDR3, 3x300GB SAS RAID5, Server 2008 R2, nVidia GT560Ti 1GB for Hyper-V RemoteFX acceleration
filecore
Black Belt 1st Degree
Black Belt 1st Degree
 
Posts: 1092
Joined: Mon Dec 29, 2003 10:35 am
Location: Trapped inside a virtual machine.


Return to Programming

Who is online

Users browsing this forum: No registered users and 3 guests