[SOLVED] now it is a register_global problem :)

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
dethron
Forum Contributor
Posts: 370
Joined: Sat Apr 27, 2002 11:39 am
Location: Istanbul

[SOLVED] now it is a register_global problem :)

Post by dethron »

Hi everyone;

I have 3 servers, and I'm trying to get some communication between them. Here is the scenario;

SERVER 1
it contains fname1.php which is as follows;

Code: Select all

<?php
    if($mVar == 2)
        echo "This is second server";
    else if($mVar == 3)
        echo "This is third server";
    else 
        echo "This is first server";		
?>
SERVER 2
it contains fname2.php which is as follows;

Code: Select all

<?php
    $file_adr = "http://server1/fname1.php?mVar=2";
    $content = file($file_adr);
?>
SERVER 3
it contains fname3.php which is as follows;

Code: Select all

<?php
    $file_adr = "http://server1/fname1.php?mVar=3";
    $content = file($file_adr);
?>

But when i open fname2.php and fname3.php in my browser, I get different content.
So I think this stems from configuration of my servers.
While server 2 succesfully parse the file an create an output
"This is second server", server 3 gives "This is first server".
Here is the versions of the installed PHP on servers.

SERVER 2 : PHP Version 4.3.3
SERVER 3 : PHP Version 4.2.2

Thnx a lot.
Last edited by dethron on Thu Jun 17, 2004 5:43 pm, edited 3 times in total.
User avatar
Weirdan
Moderator
Posts: 5978
Joined: Mon Nov 03, 2003 6:13 pm
Location: Odessa, Ukraine

Post by Weirdan »

at least you need to change your conditions to use comparison operator instead of assignment:

Code: Select all

// was:
 if($mVar = 2) 
//should be:
 if($mVar == 2)
User avatar
dethron
Forum Contributor
Posts: 370
Joined: Sat Apr 27, 2002 11:39 am
Location: Istanbul

Post by dethron »

Ok. let it be so,
The problem is not just a simple syntax error or something like that.
I just simplified the problem as above.
The main problem is file() function.

When the file,which will be parsed using file() function, outputs differently according to given parameter,
one server takes parameter in file() function, and the other doesn't.

But again, thanks for help.
User avatar
dethron
Forum Contributor
Posts: 370
Joined: Sat Apr 27, 2002 11:39 am
Location: Istanbul

Post by dethron »

As Weirdan points, there is a simple mistake. But the problem is the same.
I edited my first post to correct this simple mistake.
User avatar
markl999
DevNet Resident
Posts: 1972
Joined: Thu Oct 16, 2003 5:49 pm
Location: Manchester (UK)

Post by markl999 »

It's weird. It sounds like a register_globals problem but it can't be as SERVER1 should exhibit the same behaviour regardless of where it's called from. The only way i can see it being a SERVER2 vs SERVER3 register_globals problem is if the mVar variable in those url's isn't actually hard coded (as in your examples) but is coming from 'somewhere else' *shrug*
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

have you tried this with [php_man]curl[/php_man]? Have you tried echoing the request uri ($_SERVER['REQUEST_URI']) on Server1?
User avatar
dethron
Forum Contributor
Posts: 370
Joined: Sat Apr 27, 2002 11:39 am
Location: Istanbul

Post by dethron »

yes i did it, the URL is correct for both request.
by the way, i used

Code: Select all

<?php

	//echo $mVar;
   $register_globals = (int) ini_get('register_gobals');
   echo $register_globals;

?>
and both servers returned 0. So the possibility for global variables become 0 :(
i've been working on for 10 hours. And finally found that the problem is in Server 3 exactly.
Since some shared accounts responds as Server 2, and this is what should be, i got this idea.

I will do some tests on Server 3, and will find another model(scenario) which is simpler to solve.
Thanks for anyone :)

Kind Regards.
User avatar
dethron
Forum Contributor
Posts: 370
Joined: Sat Apr 27, 2002 11:39 am
Location: Istanbul

Post by dethron »

He he, finally i found the exact problem.
However I just specify the problem. Solution still seems to be a mystery.

I uploaded a file to Server 3 which is as follows;


//****an.php*****

Code: Select all

<?php

    echo $mVar;
?>
And send the following request
http://Server3/an.php
as we expected, nothing happened.
When i send the following request, what I see as an output is very interesting.
http://Server3/an.php?mVar=testvalue
Then the output is nothing.

Gentelmen, I'm sure many of you faced with such a problem,
I'm expecting your solutions ;)

Kind Regards.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

well.. if register_globals is off.. that won't say anything.. $_GET['mVar'] would, however.
User avatar
dethron
Forum Contributor
Posts: 370
Joined: Sat Apr 27, 2002 11:39 am
Location: Istanbul

Post by dethron »

Hmmm, yes it is worked, thank you all.
But now, a new problem occured.

Since $mVar is sent by both post and get method, in the script I can't know the way that variable sent (Am I right, I'm not sure.)
What if I use $_GET['mVar'] when the variable sent by a form?

Should I enable the register_globals?
User avatar
markl999
DevNet Resident
Posts: 1972
Joined: Thu Oct 16, 2003 5:49 pm
Location: Manchester (UK)

Post by markl999 »

Use $_REQUEST['mVar']; then it won't matter if it's sent by get or post.
User avatar
dethron
Forum Contributor
Posts: 370
Joined: Sat Apr 27, 2002 11:39 am
Location: Istanbul

Post by dethron »

He he, finally it solved.
Thx for everyone.
Post Reply