LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 11-13-2003, 08:01 AM   #1
jogurt666
Member
 
Registered: Nov 2003
Location: Poland => Mazowieckie => Ok'a
Distribution: Gentoo
Posts: 176

Rep: Reputation: 30
problems with php


i've compiled and installed apache+php+mysql. everything seems to be fine, but...
to cut the long story short i'll show an example and describe my problem on it. so. i've written the following script:

<?php
if($a == '1')
{
echo 1;
}
if($a == '2')
{
echo 2;
}
else
{
echo 3;
}
?>

(yeah i know it is stupid, it is just and example). i've saved it under /usr/local/apache/htdocs/test.php. now i entered it with my browser (i use mozilla 1.5 [polish version]) and added ?a=1 in the url. well as most of you'd expect (well i did too), the browser shoul display 1, but instead it displayed 3! well i checked it on a few of my previous scripts, and unfortunately discovered that php server i'm running does retrieve information included in url (?name=val). how can i root out that problem? i guess i should set something in php.ini, but i haven't got the slightest idea what?
plz help me.
 
Old 11-13-2003, 08:49 AM   #2
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,417

Rep: Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974
you are trying to compare them to a string value of "1" etc. in this use, "1" is not a number, and therefore can't be compared. to actually compare strings you need to use strcmp or a similar function. to stick with numeric equality, drop the quotes.
 
Old 11-13-2003, 08:59 AM   #3
Ashkhan
Member
 
Registered: Oct 2003
Distribution: Debian, Solaris, MacOS
Posts: 39

Rep: Reputation: 16
PHP distibutions 4.1.0 and newer have register_globals set to off.
So that, you can't access your variable via $variable_name.

If you have some_script.php?variable_name=1,
you have to use a superglobal to read the variable value like so...

<?

echo $_GET['variable_name'];

?>

I hope, it solves your problem.
 
Old 11-13-2003, 09:44 AM   #4
jogurt666
Member
 
Registered: Nov 2003
Location: Poland => Mazowieckie => Ok'a
Distribution: Gentoo
Posts: 176

Original Poster
Rep: Reputation: 30
well yeah i know all that. but that is not what i mean. lets say the script'd look like this:

<?php
if($a == 'xxx')
{
echo 'bla bla bla';
}
if($a == 'zzz')
{
echo 'something';
}
else
{
echo 'whatever';
}
?>

now the problem i mean is that i should see "bla bla bla" while i enter http://localhost/test.php?a=xxx and "something" when http://localhost/test.php?a=zzz.
but instead i see "whatever" in each case. that means php does not consider name=value in url as variable, as it should do. instead it treats as if $a variable was not set, and so it displays third condition. i had a similar problem on Windows when i installed apache, and than php. but on Windows i could install PHP Traid, with apache+php+mysql already working together. therefore i think that something should be set in /usr/local/lib/php.ini however i'm not sure. now i hope my thread i more clear ^^. sorry for confusion.
 
Old 11-13-2003, 01:14 PM   #5
Ashkhan
Member
 
Registered: Oct 2003
Distribution: Debian, Solaris, MacOS
Posts: 39

Rep: Reputation: 16
So, you did try using GET

PHP Code:
$a $_GET['a'];

if(
$a == 'xxx')
{
echo 
'bla bla bla';
}
if(
$a == 'zzz')
{
echo 
'something';
}
else
{
echo 
'whatever';

It should work. Without any change of default values in PHP.ini
Your other scripts are working fine?
 
Old 11-13-2003, 01:31 PM   #6
jogurt666
Member
 
Registered: Nov 2003
Location: Poland => Mazowieckie => Ok'a
Distribution: Gentoo
Posts: 176

Original Poster
Rep: Reputation: 30
well i inserted the following code into my example:

<?php
foreach($HTTP_POST_VARS as $ind => $val)
{
eval("$" . $ind . " = '" . $val . "';");
}
foreach($HTTP_GET_VARS as $ind => $val)
{
eval("$" . $ind . " = '" . $val . "';");
}

and it worked fine, but...
my other scripts aren't working fine, that is the worst thing. they worked fine, and i'm 100% sure of their comatibility. there must be something in php server settings. it is important for me, not to change my scripts source code since i've already tested them on my (purchased) server. with positive result. have you got any ideas what else could i do?
 
Old 11-13-2003, 01:47 PM   #7
markus1982
Senior Member
 
Registered: Aug 2002
Location: Stuttgart (Germany)
Distribution: Debian/GNU Linux
Posts: 1,467

Rep: Reputation: 46
you can always use phpinfo() and compare the results... (or get the php.ini and run a diff on it)
 
Old 11-13-2003, 08:51 PM   #8
cooldog
LQ Newbie
 
Registered: Nov 2003
Location: Kenton, DE
Distribution: Fedora Core 1
Posts: 1

Rep: Reputation: 0

You should add:

$a = $_GET['a'];

at the top, which avoids the security problems of "register_globals = On".

Also, the $_POST array (or the $HTTP_POST_VARS array) is not set for a GET request.

Last edited by cooldog; 11-13-2003 at 08:53 PM.
 
Old 11-14-2003, 03:56 AM   #9
jogurt666
Member
 
Registered: Nov 2003
Location: Poland => Mazowieckie => Ok'a
Distribution: Gentoo
Posts: 176

Original Poster
Rep: Reputation: 30
yeah exactly! the problem was in php.ini in register_globals. it was turned off by default. thank you all for helping me ^^.
 
Old 11-16-2003, 05:12 AM   #10
jogurt666
Member
 
Registered: Nov 2003
Location: Poland => Mazowieckie => Ok'a
Distribution: Gentoo
Posts: 176

Original Poster
Rep: Reputation: 30
baaah i've got another problem. php fulfills both conditions! i mean if for purpose i enter localhost/test.php?a=xxx i am displayed two results:

bla bla bla (one of the IF conditions are fulfilled)

and

whatever (ELSE condition is also fulfilled!)

how is that possible?! that for sure is not due to phrase error!
 
Old 11-16-2003, 06:36 AM   #11
Cerbere
Member
 
Registered: Dec 2002
Location: California
Distribution: Slackware & LFS
Posts: 799

Rep: Reputation: 33
Quote:
Originally posted by jogurt666

<?php
if($a == 'xxx')
{
echo 'bla bla bla';
}
if($a == 'zzz')
{
echo 'something';
}
else
{
echo 'whatever';
}
?>
The problem is that this code runs the first conditional, and it is true ($a == 'xxx'), so it echo's 'bla bla bla'. Then it runs the second conditional, and it is false ($a != 'zzz'), so it executes the else, i.e. it echo's 'whatever'.

To do what (I think) you expect, you must change the second conditional to:
elseif ($a == 'zzz')

Enjoy!
--- Cerbere
 
Old 11-17-2003, 03:44 AM   #12
jogurt666
Member
 
Registered: Nov 2003
Location: Poland => Mazowieckie => Ok'a
Distribution: Gentoo
Posts: 176

Original Poster
Rep: Reputation: 30
damn you were right ^^. but what is strange, the same code worked perfectly when it was used on apache+php on windows. thank you for your help.
 
Old 11-17-2003, 06:07 AM   #13
Cerbere
Member
 
Registered: Dec 2002
Location: California
Distribution: Slackware & LFS
Posts: 799

Rep: Reputation: 33
Just goes to show, you can never tell what windows is going to do ;-)

Enjoy!
--- Cerbere
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
More PHP problems :( arichardson Linux - Software 1 11-21-2005 04:24 PM
PHP problems PLEASE HELP!! mrosati Linux - Software 2 10-15-2004 05:01 AM
slackware, apache and PHP from .tgz - problems with PHP szymon Slackware 2 09-06-2004 05:57 PM
Problems with PHP :( AMMullan Linux - Software 7 12-02-2003 11:25 AM
PHP problems Mikessu Linux - Networking 2 09-20-2003 03:35 PM


All times are GMT -5. The time now is 08:44 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration