fsockopen

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

BachgenCymreig
Forum Newbie
Posts: 12
Joined: Fri Sep 22, 2006 3:57 pm

fsockopen

Post 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.
BachgenCymreig
Forum Newbie
Posts: 12
Joined: Fri Sep 22, 2006 3:57 pm

Post 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???
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post 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;
}

?>
User avatar
Mordred
DevNet Resident
Posts: 1579
Joined: Sun Sep 03, 2006 5:19 am
Location: Sofia, Bulgaria

Post 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.
User avatar
Kieran Huggins
DevNet Master
Posts: 3635
Joined: Wed Dec 06, 2006 4:14 pm
Location: Toronto, Canada
Contact:

Post by Kieran Huggins »

First rule of debugging: Turn off all mutes.
BachgenCymreig
Forum Newbie
Posts: 12
Joined: Fri Sep 22, 2006 3:57 pm

Post 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
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post by Chris Corbyn »

I'll put money (ok, pretend money!) on it being this:

Register Globals: On

Hint - php.ini & register_globals
BachgenCymreig
Forum Newbie
Posts: 12
Joined: Fri Sep 22, 2006 3:57 pm

Post 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.
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post 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'] ;)
BachgenCymreig
Forum Newbie
Posts: 12
Joined: Fri Sep 22, 2006 3:57 pm

Post 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!!!
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

$REMOTE_ADDR won't exist. $_SERVER['REMOTE_ADDR'] will far more often.
BachgenCymreig
Forum Newbie
Posts: 12
Joined: Fri Sep 22, 2006 3:57 pm

Post by BachgenCymreig »

Anyone got any more thoughts on the fsockopen problem?? pleassssssse :(

EDIT: btw, the $_SERVER['REMOTE_ADDR'] worked - thanks a lot :lol:
User avatar
Kieran Huggins
DevNet Master
Posts: 3635
Joined: Wed Dec 06, 2006 4:14 pm
Location: Toronto, Canada
Contact:

Post by Kieran Huggins »

Isn't it obvious? He's using a GOOD server and his friend is using a EVIL server!
BachgenCymreig
Forum Newbie
Posts: 12
Joined: Fri Sep 22, 2006 3:57 pm

Post by BachgenCymreig »

lol that about sums it up, but I still need a solution!!!!!!! :nono:
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

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