Page 1 of 2

Global's work in http but not in ssh....

Posted: Tue Apr 11, 2006 1:25 am
by Deseree
hi guys, mabye someone here can explain this to me...

my script works fine when I call it from http but when i call the script using /usr/bin/php /path/to/script.php and it doesn't work....


I did some debugging and found out that $SCRIPT_NAME and $SCRIPT_FILENAME are not working when I call the script via ssh, but when i call via http it works just fine.... $_SERVER["SCRIPT_FILENAME"] / $_SERVER["SCRIPT_NAME"] worked in http but not ssh also....

anyone can help because this is REALLY anonying.... lol

Posted: Tue Apr 11, 2006 5:34 am
by Grim...
The Apache server tells PHP to compile, and you don't use the Apache server when you SSH.
I'm not so hot at this stuff so I might be very wrong...

Posted: Tue Apr 11, 2006 12:32 pm
by Deseree
Grim... wrote:The Apache server tells PHP to compile, and you don't use the Apache server when you SSH.
I'm not so hot at this stuff so I might be very wrong...
I have no idea what your saying.... are you saying that ssh uses a different php and that php.ini might have register globals off?

Let me chek.

Posted: Tue Apr 11, 2006 12:37 pm
by Deseree
ok, PHP_SELF is empty, _SERVER["PWD"] shows the directory i THINK?

$SCRIPT_NAME and $SCRIPT_FILENAME are empty, register globals is ON .

All the above is from running phpinfo() in shell....

how can I get $SCRIPT_FILENAME to work?

Posted: Tue Apr 11, 2006 7:18 pm
by Deseree
nobody? it's a really interesting thing...... i would have thought more people have used php with ssh....

Posted: Tue Apr 11, 2006 7:22 pm
by Benjamin
Well I'm really not sure how your posting data or populating $_GET $_SESSION or $_COOKIE globals via ssh. Globals don't cross scripts either unless it's an inlcude.

Posted: Tue Apr 11, 2006 7:49 pm
by Deseree
agtlewis wrote:Well I'm really not sure how your posting data or populating $_GET $_SESSION or $_COOKIE globals via ssh. Globals don't cross scripts either unless it's an inlcude.
maybe i am confusing you guys when I call $SCRIPT_NAME, $SCRIPT_FILENAME, PHP_SELF global var(s) what are they properly called? SERVER vars?

Then that's what I'm having a problem with....

Posted: Tue Apr 11, 2006 8:25 pm
by Benjamin
There is a good chance that some if not all of the $_SERVER vars are provided by the webserver, in which case they won't be available via SSH.

Posted: Tue Apr 11, 2006 8:44 pm
by Christopher
Do you mean SSH or HTTPS? If you are talking about SSH then PHP would not "work" because there is no webserver serving up SSH sessions. If you are saying that something works in HTTP but not in HTTPS then you should check you webserver configuration.

Posted: Tue Apr 11, 2006 9:10 pm
by Deseree
arborint wrote:Do you mean SSH or HTTPS? If you are talking about SSH then PHP would not "work" because there is no webserver serving up SSH sessions. If you are saying that something works in HTTP but not in HTTPS then you should check you webserver configuration.
I mean via SSH 100%, how can i get the script NAME of the .php from SHELL ? anyone know?

Posted: Tue Apr 11, 2006 11:33 pm
by Christopher
What does that mean "how can i get the script NAME of the .php from SHELL"? If you are in the shell you would need to know the name of the script to execute it. If the script is running then $_SERVER['SCRIPT_NAME'] will give the script name. If you write a test script that calls phpinfo() it will dump all the globals that are available. That's ususally the first thing PHP programmers do on a system.

Posted: Wed Apr 12, 2006 8:34 am
by Deseree
arborint wrote:What does that mean "how can i get the script NAME of the .php from SHELL"? If you are in the shell you would need to know the name of the script to execute it. If the script is running then $_SERVER['SCRIPT_NAME'] will give the script name. If you write a test script that calls phpinfo() it will dump all the globals that are available. That's ususally the first thing PHP programmers do on a system.
yea, see i did that phpinfo already in ssh.... and i didn't see the SCRIPT_NAME var, i see it in http but not in ssh...... that is the whole weird thing about this, why doesn't $_SERVER[''SCRIPT_NAME] show up?

and the REASON I want the FILENAME and FILE PATH, is I automate the crud outta things, I like to rename my scripts say script_1.php or script_2.php and then my script will AUTOMATICALLY grab the number after _ in the script name? got it? good :)

anyways, since I can't figure this out , i am just using

script.php 'run=whatever&file_num=1'
script.php 'run=whatever&file_num=2'

that wasn't what i wanted, but i guess it might work out better.

Posted: Wed Apr 12, 2006 10:36 am
by timvw
Since there isn't really a $_SERVER at work.. You might want to look at the contents of $_ENV.

Posted: Wed Apr 12, 2006 10:49 am
by sheila
What does this show?

Code: Select all

print_r($_SERVER['argv']);

Posted: Wed Apr 12, 2006 11:13 am
by timvw

Code: Select all

#!/usr/bin/php
<?php
ini_set('error_reporting', E_ALL);
ini_set('display_errors', TRUE);

print_r($_SERVER);
echo "\n\n";
print_r($_ENV);

?>

timvw@madoka:~$ php test.php
Array
(
[TERM] => xterm
[SHELL] => /bin/bash
[HISTSIZE] => 300
[SSH_CLIENT] => ::ffff:62.235.234.49 32957 22
[CVSROOT] => /home/users/timvw/services/cvs
[SSH_TTY] => /dev/pts/29
[USER] => timvw
[LS_COLORS] => no=00:fi=00:di=01;34:ln=01;36:pi=40;33:so=01;35:do=01;35:bd=40;33;01:cd=40;33;01:or=40;31;01:ex=01;32:*.tar=01;31:*.tgz=01;31:*.arj=01;31:*.taz=01;31:*.lzh=01;31:*.zip=01;31:*.z=01;31:*.Z=01;31:*.gz=01;31:*.bz2=01;31:*.deb=01;31:*.rpm=01;31:*.jar=01;31:*.jpg=01;35:*.jpeg=01;35:*.gif=01;35:*.bmp=01;35:*.pbm=01;35:*.pgm=01;35:*.ppm=01;35:*.tga=01;35:*.xbm=01;35:*.xpm=01;35:*.tif=01;35:*.tiff=01;35:*.png=01;35:*.mov=01;35:*.mpg=01;35:*.mpeg=01;35:*.avi=01;35:*.fli=01;35:*.gl=01;35:*.dl=01;35:*.xcf=01;35:*.xwd=01;35:*.ogg=01;35:*.mp3=01;35:*.wav=01;35:
[TMOUT] => 259200
[MAIL] => /home/users/timvw/Maildir
[PATH] => /home/users/timvw/bin:/usr/local/bin:/usr/bin:/bin:/usr/bin/X11:/usr/games:/usr/lib/j2sdk1.5-sun/bin
[PWD] => /home/users/timvw
[PS1] => \\u@\\h:\\w\\$
[SHLVL] => 1
[HOME] => /home/users/timvw
[LOGNAME] => timvw
[CLASSPATH] =>
[SSH_CONNECTION] => ::ffff:62.235.234.49 32957 ::ffff:193.190.138.70 22
[_] => /usr/bin/php
[PHP_SELF] => test.php
[SCRIPT_NAME] => test.php
[SCRIPT_FILENAME] => test.php
[PATH_TRANSLATED] => test.php
[DOCUMENT_ROOT] =>
[argv] => Array
(
[0] => test.php
)

[argc] => 1
)


Array
(
[TERM] => xterm
[SHELL] => /bin/bash
[HISTSIZE] => 300
[SSH_CLIENT] => ::ffff:62.235.234.49 32957 22
[CVSROOT] => /home/users/timvw/services/cvs
[SSH_TTY] => /dev/pts/29
[USER] => timvw
[LS_COLORS] => no=00:fi=00:di=01;34:ln=01;36:pi=40;33:so=01;35:do=01;35:bd=40;33;01:cd=40;33;01:or=40;31;01:ex=01;32:*.tar=01;31:*.tgz=01;31:*.arj=01;31:*.taz=01;31:*.lzh=01;31:*.zip=01;31:*.z=01;31:*.Z=01;31:*.gz=01;31:*.bz2=01;31:*.deb=01;31:*.rpm=01;31:*.jar=01;31:*.jpg=01;35:*.jpeg=01;35:*.gif=01;35:*.bmp=01;35:*.pbm=01;35:*.pgm=01;35:*.ppm=01;35:*.tga=01;35:*.xbm=01;35:*.xpm=01;35:*.tif=01;35:*.tiff=01;35:*.png=01;35:*.mov=01;35:*.mpg=01;35:*.mpeg=01;35:*.avi=01;35:*.fli=01;35:*.gl=01;35:*.dl=01;35:*.xcf=01;35:*.xwd=01;35:*.ogg=01;35:*.mp3=01;35:*.wav=01;35:
[TMOUT] => 259200
[MAIL] => /home/users/timvw/Maildir
[PATH] => /home/users/timvw/bin:/usr/local/bin:/usr/bin:/bin:/usr/bin/X11:/usr/games:/usr/lib/j2sdk1.5-sun/bin
[PWD] => /home/users/timvw
[PS1] => \\u@\\h:\\w\\$
[SHLVL] => 1
[HOME] => /home/users/timvw
[LOGNAME] => timvw
[CLASSPATH] =>
[SSH_CONNECTION] => ::ffff:62.235.234.49 32957 ::ffff:193.190.138.70 22
[_] => /usr/bin/php
)