Page 1 of 2
fsockopen
Posted: Mon Feb 12, 2007 5:32 am
by BachgenCymreig
Ok, I so hope you guys understand what I am trying to do here lol
Ok I have a script that connects to an IRC server just to get some info using the following code:
$server['SOCKET'] = @fsockopen($server_host, $server_port, $errno, $errstr, 2);
Now, my personal server, the script runs absolutely fine with. However when I upload this to a friends server (where it needs to be hosted), all I get is a blank page with no results.
I'm thinking it's a setting on the friends server preventing this??
Any light you can shed would be greatly appreciated.
Thanks.
Posted: Mon Feb 12, 2007 5:57 am
by BachgenCymreig
Also another problem I get on my friends server is echoing the IP address of a user; works fine on mine...
UGH it's playing on my nerves lol
<? $ip = Get HostByName($REMOTE_ADDR); echo $ip; ?>
^^ that just doesnt work???
Posted: Mon Feb 12, 2007 9:48 am
by feyd
Run the following in a new file on both servers and tell us the results please.
Code: Select all
<?php
$neg = array('off', 0, false, '', null);
$flags = array(
'Register Globals' => 'register_globals',
'Short Tags' => 'short_open_tag',
'Display Errors' => 'display_errors',
'Magic Quotes GPC' => 'magic_quotes_gpc',
'Magic Quotes Runtime' => 'magic_quotes_runtime',
'Magic Quotes Sybase' => 'magic_quotes_sybase',
);
$ve = phpversion();
$os = PHP_OS;
$er = intval(error_reporting());
foreach ($flags as $n => $v)
{
$flags[$n] = (in_array(strtolower(ini_get($v)), $neg) ? 'Off' : 'On');
}
$flags['Config file'] = get_cfg_var('cfg_file_path');
if (empty($flags['Config file']))
{
$flags['Config file'] = '-';
}
$cli = (php_sapi_name() == 'cli');
$eol = "
";
$gle = get_loaded_extensions();
$rows = array();
$le = '';
$wide = 4;
$j = count($gle);
$pad = $wide - $j % $wide;
$len = max(array_map('strlen', $gle));
$func = create_function('$a', 'return str_pad($a, ' . intval($len) . ');');
$gle = array_map($func, $gle);
for($i = 0; $i < $j; $i += $wide)
{
$le .= ' ' . implode(' ', array_slice($gle, $i, $wide)) . $eol;
}
$ec = array(
'E_STRICT' => 2048, 'E_ALL' => 2047, 'E_USER_NOTICE' => 1024,
'E_USER_WARNING' => 512, 'E_USER_ERROR' => 256, 'E_COMPILE_WARNING' => 128,
'E_COMPILE_ERROR' => 64, 'E_CORE_WARNING' => 32, 'E_CORE_ERROR' => 16,
'E_NOTICE' => 8, 'E_PARSE' => 4, 'E_WARNING' => 2, 'E_ERROR' => 1,
);
$e = array();
$t = $er;
foreach ($ec as $n => $v)
{
if (($t & $v) == $v)
{
$e[] = $n;
$t ^= $v;
}
}
if (ceil(count($ec) / 2) + 1 < count($e))
{
$e2 = array();
foreach ($ec as $n => $v)
{
if (!in_array($n, $e) and $n != 'E_ALL')
{
$e2[] = $n;
}
}
$er = $er . ' ((E_ALL | E_STRICT) ^ ' . implode(' ^ ', $e2) . '))';
}
else
{
$er = $er . ' (' . implode(' | ', $e) . ')';
}
if (!$cli)
{
echo '<html><head><title>quick info</title></head><body><pre>', $eol;
}
echo 'PHP Version: ', $ve, $eol;
echo 'PHP OS: ', $os, $eol;
echo 'Error Reporting: ', $er, $eol;
foreach ($flags as $n => $v)
{
echo $n, ': ', $v, $eol;
}
echo 'Loaded Extensions:', $eol, $le, $eol;
if (!$cli)
{
echo '</pre></body></html>', $eol;
}
?>
Posted: Mon Feb 12, 2007 10:01 am
by Mordred
My guess is that your friend's server has disabled fsockopen and error display, so you get an error about the function being banned, but you can't see it.
Try function_exists() and/or get_defined_functions(), also phpinfo() should list the forbidden functions IIRC.
Posted: Mon Feb 12, 2007 10:20 am
by Kieran Huggins
First rule of debugging: Turn off all mutes.
Posted: Tue Feb 13, 2007 5:31 am
by BachgenCymreig
Ok, sorry for delay in reply.
MY server which it runs ok on gave this output:
PHP Version: 4.4.1
PHP OS: Linux
Error Reporting: 2039 ((E_ALL | E_STRICT) ^ E_STRICT ^ E_NOTICE))
Register Globals: On
Short Tags: On
Display Errors: On
Magic Quotes GPC: On
Magic Quotes Runtime: Off
Magic Quotes Sybase: Off
Config file: /usr/local/Zend/etc/php.ini
Loaded Extensions:
xml tokenizer swf standard
sockets session pspell posix
pgsql pcre overload mysql
ming mhash mcrypt mbstring
imap gettext gd ftp
curl ctype calendar bcmath
zlib openssl Zend Optimizer
My friends server that it does not work on and needs to work on gave this:
PHP Version: 4.4.4
PHP OS: Linux
Error Reporting: 2039 ((E_ALL | E_STRICT) ^ E_STRICT ^ E_NOTICE))
Register Globals: Off
Short Tags: On
Display Errors: On
Magic Quotes GPC: On
Magic Quotes Runtime: Off
Magic Quotes Sybase: Off
Config file: /usr/local/Zend/etc/php.ini
Loaded Extensions:
xml tokenizer standard sockets
session posix overload mysql
mhash mcrypt mbstring imap
gettext gd ftp curl
ctype calendar bcmath zlib
pcre openssl apache Zend Optimizer
Posted: Tue Feb 13, 2007 5:37 am
by Chris Corbyn
I'll put money (ok, pretend money!) on it being this:
Register Globals: On
Hint - php.ini & register_globals
Posted: Tue Feb 13, 2007 5:46 am
by BachgenCymreig
lol thanks, I shall try...
I know you'll probably think this is a stupid question, but how would my friend do that using cPanel? He won't give me access to cPanel to get it changed lol.
Posted: Tue Feb 13, 2007 6:17 am
by Chris Corbyn
Don't "fix" the ini, fix your code
It's a case of using $_POST['foo'], $_SERVER['foo'], $_GET['foo'] etc rather than just using $foo. Lazy programmers can use $_REQUEST['foo']

Posted: Tue Feb 13, 2007 6:37 am
by BachgenCymreig
But I do that to set all my variables anyway (I think)???
So I mean here's the connection of the socket, what would you recommend I do to it??
Code: Select all
$server = array();
$server['SOCKET'] = @fsockopen($server_host, $server_port, $errno, $errstr, 2);
I mean on my friend's server I can't even echo a user's IP address using
Code: Select all
<? $ip = Get HostByName($REMOTE_ADDR); echo $ip; ?>
OR
Code: Select all
<? $ip = $_Get HostByName($REMOTE_ADDR); echo $ip; ?>
UGH so confusing!!!
Posted: Tue Feb 13, 2007 8:29 am
by feyd
$REMOTE_ADDR won't exist. $_SERVER['REMOTE_ADDR'] will far more often.
Posted: Tue Feb 13, 2007 12:40 pm
by BachgenCymreig
Anyone got any more thoughts on the fsockopen problem?? pleassssssse
EDIT: btw, the $_SERVER['REMOTE_ADDR'] worked - thanks a lot

Posted: Tue Feb 13, 2007 12:59 pm
by Kieran Huggins
Isn't it obvious? He's using a GOOD server and his friend is using a EVIL server!
Posted: Tue Feb 13, 2007 3:20 pm
by BachgenCymreig
lol that about sums it up, but I still need a solution!!!!!!!

Posted: Tue Feb 13, 2007 4:13 pm
by feyd
I'm pretty sure we're going to need more information then a single line from your code to help more, especially since you used to @ operator.