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

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

Deseree
Forum Commoner
Posts: 84
Joined: Mon Feb 13, 2006 11:35 pm

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

Post 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
Grim...
DevNet Resident
Posts: 1445
Joined: Tue May 18, 2004 5:32 am
Location: London, UK

Post 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...
Deseree
Forum Commoner
Posts: 84
Joined: Mon Feb 13, 2006 11:35 pm

Post 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.
Deseree
Forum Commoner
Posts: 84
Joined: Mon Feb 13, 2006 11:35 pm

Post 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?
Deseree
Forum Commoner
Posts: 84
Joined: Mon Feb 13, 2006 11:35 pm

Post by Deseree »

nobody? it's a really interesting thing...... i would have thought more people have used php with ssh....
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Post 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.
Deseree
Forum Commoner
Posts: 84
Joined: Mon Feb 13, 2006 11:35 pm

Post 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....
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Post 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.
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Post 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.
(#10850)
Deseree
Forum Commoner
Posts: 84
Joined: Mon Feb 13, 2006 11:35 pm

Post 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?
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Post 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.
(#10850)
Deseree
Forum Commoner
Posts: 84
Joined: Mon Feb 13, 2006 11:35 pm

Post 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.
timvw
DevNet Master
Posts: 4897
Joined: Mon Jan 19, 2004 11:11 pm
Location: Leuven, Belgium

Post by timvw »

Since there isn't really a $_SERVER at work.. You might want to look at the contents of $_ENV.
sheila
Forum Commoner
Posts: 98
Joined: Mon Sep 05, 2005 9:52 pm
Location: Texas

Post by sheila »

What does this show?

Code: Select all

print_r($_SERVER['argv']);
timvw
DevNet Master
Posts: 4897
Joined: Mon Jan 19, 2004 11:11 pm
Location: Leuven, Belgium

Post 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
)
Post Reply