PDA

View Full Version : Need Help With My php signature,


Bry Man
12-16-2004, 01:19 AM
Hey,

First off I have one of them Ip, os, browser telling signatures and all that I made myself and all the sudden it stopped working right around the time my host moved to php 5, I have checked to see if maybe they had disabled the GD library and they havent, if you wanna c for youself here is the link to the php settings, http://www.trio.5gigs.com/includes/area51.php.

When I try to access it I get a Internal Server error, here is the link to the actual signature, http://www.trio.5gigs.com/signature/signature.jpg I dont really know php all that well and this is my biggest php accomplishment to date and it wasnt an easy one so any help In fixing the problem would be great.

Here is a zip containing everything needed.

dniwebdesign
12-16-2004, 03:08 AM
My server just shows the code so I changed it to a .php file. The file won't even open on my server now.

Bry Man
12-16-2004, 03:15 AM
O I almost forgot, you need a .htaccess file that forces the server to parse the jpg files within its directory into a php file, let me see if I can get it, that may be my problem?


EDIT: It wasnt My Problem, I couldnt download the htaccess file but here is the contents.

<Files signature.jpg>
ForceType application/x-httpd-php
</Files>

<Files signature.php>
ForceType application/x-httpd-php
</Files>

<Files monkey.jpg>
ForceType application/x-httpd-php
</Files>

Just make sure its in a .htaccess file within the same directory as the signature.jpg file is, maybe that will get it to work, also when you changed it to a php file did you include a png graphic to have it print on, thats probably why it wouldnt work, also what version of php are you running?

dniwebdesign
12-16-2004, 03:35 AM
<br />
<b>Warning</b>: imagecreatefrompng(darknight.png): failed to open stream: No such file or directory in <b>c:\server\htdocs\signature.jpg</b> on line <b>8</b><br />
<br />
<b>Warning</b>: imagecolorallocate(): supplied argument is not a valid Image resource in <b>c:\server\htdocs\signature.jpg</b> on line <b>11</b><br />
<br />
<b>Warning</b>: imagecolorallocate(): supplied argument is not a valid Image resource in <b>c:\server\htdocs\signature.jpg</b> on line <b>12</b><br />
<br />
<b>Warning</b>: imagecolorallocate(): supplied argument is not a valid Image resource in <b>c:\server\htdocs\signature.jpg</b> on line <b>13</b><br />
<br />
<b>Warning</b>: imagecolorallocate(): supplied argument is not a valid Image resource in <b>c:\server\htdocs\signature.jpg</b> on line <b>14</b><br />
<br />
<b>Warning</b>: imagecolorallocate(): supplied argument is not a valid Image resource in <b>c:\server\htdocs\signature.jpg</b> on line <b>15</b><br />
<br />
<b>Warning</b>: imagecolorallocate(): supplied argument is not a valid Image resource in <b>c:\server\htdocs\signature.jpg</b> on line <b>16</b><br />
<br />
<b>Warning</b>: imagecolorallocate(): supplied argument is not a valid Image resource in <b>c:\server\htdocs\signature.jpg</b> on line <b>17</b><br />
<br />
<b>Warning</b>: imagecolorallocate(): supplied argument is not a valid Image resource in <b>c:\server\htdocs\signature.jpg</b> on line <b>18</b><br />
<br />
<b>Warning</b>: imagecolorallocate(): supplied argument is not a valid Image resource in <b>c:\server\htdocs\signature.jpg</b> on line <b>19</b><br />
<br />
<b>Warning</b>: imagettftext(): supplied argument is not a valid Image resource in <b>c:\server\htdocs\signature.jpg</b> on line <b>121</b><br />
<br />
<b>Warning</b>: imagettftext(): supplied argument is not a valid Image resource in <b>c:\server\htdocs\signature.jpg</b> on line <b>122</b><br />
<br />
<b>Warning</b>: imagettftext(): supplied argument is not a valid Image resource in <b>c:\server\htdocs\signature.jpg</b> on line <b>123</b><br />
<br />
<b>Warning</b>: imagettftext(): supplied argument is not a valid Image resource in <b>c:\server\htdocs\signature.jpg</b> on line <b>124</b><br />
<br />
<b>Warning</b>: imagettftext(): supplied argument is not a valid Image resource in <b>c:\server\htdocs\signature.jpg</b> on line <b>125</b><br />
<br />
<b>Warning</b>: imagepng(): supplied argument is not a valid Image resource in <b>c:\server\htdocs\signature.jpg</b> on line <b>128</b><br />
<br />
<b>Warning</b>: imagedestroy(): supplied argument is not a valid Image resource in <b>c:\server\htdocs\signature.jpg</b> on line <b>129</b><br />

Bry Man
12-16-2004, 05:02 AM
Well from what I noticed, your still trying to use my png, and you dont have the font file either, id send it but its too big, same with the png.

For the font if your on windows get it from your fonts directory, the font is Arial. As for the Png I think I can send it alone all by itself. As for the color allocation I dunno what its going off on with that. I guess its not valid anymore? perhaps someone knows if there is a valid way to do this now?


EDIT: Sorry I cant send it, jsut make a black or white png thats around 300x300 px and name is darknight and place it in the directory

dniwebdesign
12-16-2004, 04:13 PM
Alright,
I added PNG, Font... works fine.

http://www.dni-server.no-ip.com/signature.jpg

Download .zip (http://www.dni-server.no-ip.com/sig.zip)

Bry Man
12-16-2004, 10:10 PM
What version of php are you using? Because It worked fine on my site until one day we changed over to php 5 and I changed nothing and all the sudden it stoped working and as you can see you have EXACTLY what I have but yours works and mine doesnt

dniwebdesign
12-16-2004, 10:25 PM
PHP Version 4.3.4

and if you look at your image, you spelt browser wrong ;)

Bry Man
12-16-2004, 10:27 PM
hmmm lol I thought I had fixed that =) thanks for pointing it out tho, thats probably why it doesnt work, we are using different versions of php. Perhaps someone with php5+ could try it out for me or help with the code changes becuase I really have no idea about what was changed and the correct way to fix the problem =S

Kurashu
12-16-2004, 10:45 PM
Instead of getting the MIME type by checking the extension, you should check it by using: mime_content_type().

Bry Man
12-16-2004, 10:48 PM
What, I dont know what you mean by

Instead of getting the MIME type by checking the extension,

firepages
12-16-2004, 10:58 PM
a register_globals issue ? , if its not this go through every php function and check for PHP5 compatibility issues in the manual ... try changing

$HTTP_USER_AGENT;
to
$_SERVER['HTTP_USER_AGENT'];
& $REMOTE_ADDR to $_SERVER['REMOTE_ADDR'] etc

not that that should cause a server error more likely just the image to fail ?

Kurashu
12-16-2004, 11:09 PM
What, I dont know what you mean by

In the code last posted, there is a MIME type checking that uses the extensions to get the MIME type. That could lead to problems. Usings mime_content_type is a much better idea. =D

Bry Man
12-16-2004, 11:12 PM
I changed all the stuff I could find and its still acting up, also I guess what I meant was where did I use a MIME type to check extensions, as far as i remember I did no such thing or no what a MIME type is?

AaronW
12-17-2004, 12:23 AM
I thought internal server errors were caused by Apache tripping up? PHP errors would just output the usual PHP error?

Rather than using ForceType, try naming it <imagename>.php, and use "header ('Content-type: image/jpeg');" at the top of your script to tell browsers to handle the output as a JPEG.

Unless you had some other reason for using ForceType.

Bry Man
12-17-2004, 01:13 AM
I was forcing it Because I thought that was the only way to handel it because I wanted to be able to call it with the [img] tags where you cant do that when its got a .php extension, well it is saying its an internal server error, error 500 I believe, much more than that I dont know because I dont have my own server or have studied all the errors and such

AaronW
12-17-2004, 01:19 AM
You can call .php files with the <img> tag... The SRC attribute just takes a relative or absolute path to any file. If the file isn't of type image/*, it'll be a broken image, but the request is still made.

Bry Man
12-17-2004, 01:23 AM
Hmm, I was referring to the phpbb forum's [img] [/ img] tag, I think I tried calling it as php with that and it didnt do anything

AaronW
12-17-2004, 01:28 AM
That's pretty dumb... Not sure what sort of security risks they're trying to patch by not allowing *.php...

http://www.trio.5gigs.com/signature/signature.php - Try commenting your call to header () in that script, and see which errors it gives you. Or are those the ones dniwebdesign posted?

Bry Man
12-17-2004, 01:30 AM
That particular script is outdated and I believe thats the one I tried using for the <img> tag but I didnt have the header comment in it, but its basiclly whats inside the .jpg files so I dont know if adding the header info will do much to it but ill try

EDIT: It didnt do anything

AaronW
12-17-2004, 01:32 AM
When a .php file gives an error that the image can't be displayed due to errors, you're calling header ('Content-type: image/...') somewhere in that script ;) Otherwise it'd be a PHP error.

Bry Man
12-17-2004, 01:36 AM
I am using header ('Content-type: image/png');

AaronW
12-17-2004, 01:37 AM
Right... So comment it out and re-run the page and see which PHP errors are being echoed in the image. If your script isn't flawless, errors will be printed into the binary output of your image's source and the browser will not render it (because it's corrupted.)

Bry Man
12-17-2004, 01:41 AM
What do you mena by 'comment it out', sorry for sounding stupid lol but I gotta know, why not cut it out completely

AaronW
12-17-2004, 01:42 AM
// header (...)

Comments ;)

Don't cut it out, because when you've fixed the errors, you'll want to put it back in so your script turns into an image again.

Bry Man
12-17-2004, 01:46 AM
Ah, it must be one of the technical terms I was unaware of, that doesnt work either im afraid....

AaronW
12-17-2004, 01:53 AM
Open up the .php file, and paste its contents in your next reply please. I'll look it over.

Bry Man
12-17-2004, 02:05 AM
Here you go, but as I said this is outdated and I think its missing info compared to the .jpg one, Ill assume you already have the .jpg one and just put the php script

<?php
// header ('Content-type: image/jpeg');
header ('Content-type: image/png');
header('Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0');
header('Expires: Thu, 19 Nov 1981 08:52:00 GMT');
header('Pragma: no-cache');

// create the image
$image = imagecreatefrompng("sig2bg.png");

// set the colours
$cool = imagecolorallocate($image, 81, 86, 96);
$black = imagecolorallocate($image, 0, 0, 0);
$white = imagecolorallocate($image, 255, 255, 255);
$red = imagecolorallocate($image, 255, 0, 0);
$grey = imagecolorallocate($image, 204, 204, 204);
$green = imagecolorallocate($image, 206, 129, 18);
$blue = imagecolorallocate($image, 0, 0, 255);

//browser type
if ( strstr($agent, "MSIE 5") ){
$browser = "using IE 5";
} elseif ( strstr($agent, "MSIE 6") ){
$browser = "using IE 6";
} elseif ( strstr($agent, "MSIE 4") ){
$browser = "using IE 4";
} elseif ( strstr($agent, "Firebird") ){
$browser = "using Firebird";
} elseif ( strstr($agent, "Safari") ){
$browser = "using Safari";
} elseif ( strstr($agent, "Mozilla/5") ){
$browser = "using Mozilla/Netscape 5";
} elseif ( strstr($agent, "Mozilla/6") ){
$browser = "using Netscape 6";
} elseif ( strstr($agent, "Mozilla/4") ){
$browser = "using Netscape 4";
} elseif ( strstr($agent, "Opera") ){
$browser = "using Opera";
} else {
$browser = "";
}


// get IP and resolve IP
$ip = $REMOTE_ADDR;
$resolved = gethostbyaddr ($REMOTE_ADDR);



// check for non resolve of IP and rip domain if resolved
if ($resolved == $ip) {
$isp = ".. Can't Resolve IP";
}
else
{
$str = preg_split("/\./", $resolved);
$i = count($str);
$x = $i - 1;
$n = $i - 2;
$isp = $str[$n] . "." . $str[$x];
}

// Simple OS Detection

$os = $HTTP_USER_AGENT;
$oslist = Array (

// Windows
"Win|Windows",
"Win16|Windows",
"Win95|Windows 95",
"Win98|Windows 98",
"WinME|Windows ME",
"Win32|Windows",
"WinNT|Windows NT",
"Windows 3.1|Windows 3.1",
"Windows 95|Windows 95",
"Windows CE|Windows CE",
"Windows 98|Windows 98",
"Windows ME|Windows ME",
"Windows NT|Windows NT",
"Windows NT 5.0|Windows 2000",
"Windows NT 5.1|Windows XP",

// Macintosh
"Mac_68000|MacOS m68K",
"Mac_68K|MacOS m68K",
"Mac_PowerPC|MacOS PPC",
"Mac_PPC|MacOS PPC",
"Macintosh|MacOS",

// Unices
"X11|UNIX",
"BSD|BSD",
"SunOS|SunOS",
"IRIX|IRIX",
"HP-UX|HP-UX",
"AIX|AIX",
"QNX|QNX",
"SCO_SV|SCO UNIX",
"FreeBSD|FreeBSD",
"NetBSD|NetBSD",

// Linux
"Linux|Linux",
"Debian|Debian GNU/Linux",

// Other
"BeOS|BeOS",
"OS/2|OS/2",
"AmigaOS|AmigaOS",

);

foreach ($oslist as $osnow) {
$osnow = explode ("|", $osnow);
if (eregi ($osnow[0], $os)) {
$endos = $osnow[1];
$check = "No";
} elseif ($check != "No") {
$endos = "Unknown";
}
}

// Retrieve random quote from text file
$quote_array = file("quotes.txt");
srand((double) microtime() * 10000000);
$quote = array_rand($quote_array);

// set the font and print text
$font = '"/Signature/arial.ttf"';

imagettftext ($image, 8, 0, 10, 15, $white, $font, 'Your Ip '.$ip);
imagettftext ($image, 8, 0, 10, 30, $white, $font, 'Your ISP '.$isp);
imagettftext ($image, 8, 0, 10, 45, $white, $font, 'Your OS '.$os);
imagettftext ($image, 8, 0, 10, 60, $white, $font, 'Your Borwser '.$browser);
imagettftext ($image, 8, 0, 10, 75, $white, $font, $quote_array[$quote]);

// output and destroy
imagepng($image);
imagedestroy($image);

?>

AaronW
12-17-2004, 02:11 AM
Hmm. Instead of $REMOTE_ADDR (and $HTTP_... etc) use the new superglobals... $_SERVER['REMOTE_ADDR'], etc.

Has this been suggested? Heh. You can find out which variables you have at your disposal by querying the manual for "Predefined Variables" and "Predefined Constants".

Bry Man
12-17-2004, 02:46 AM
Yes it has but I didnt changed the .php file, hecnce the reason its outdated, here is my jpg script

<?php
// header ('Content-type: image/png');
header('Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0');
header('Expires: Thu, 19 Nov 1981 08:52:00 GMT');
header('Pragma: no-cache');

// create the image
$image = ImageCreateFromPNG("darknight.png");

// set the colours
$mblue = ImageColorAllocate($image, 196, 100, 100);
$orange = ImageColorAllocate($image, 255, 150, 0);
$cool = ImageColorAllocate($image, 81, 86, 96);
$black = ImageColorAllocate($image, 0, 0, 0);
$white = ImageColorAllocate($image, 255, 255, 255);
$red = ImageColorAllocate($image, 255, 0, 0);
$grey = ImageColorAllocate($image, 204, 204, 204);
$green = ImageColorAllocate($image, 206, 129, 18);
$blue = ImageColorAllocate($image, 0, 0, 255);

//browser type
$agent = $_SERVER['HTTP_USER_AGENT'];
if ( strstr($agent, "MSIE 5") ) $browser = "Internet Explorer 5";
elseif ( strstr($agent, "MSIE 6") ) $browser = "Internet Explore 6";
elseif ( strstr($agent, "MSIE 4") ) $browser = "Internet Explorer 4";
elseif ( strstr($agent, "Firebird") ) $browser = "Firebird";
elseif ( strstr($agent, "Safari") ) $browser = "Safari";
elseif ( strstr($agent, "Mozilla/5") ) $browser = "Mozilla/Netscape 5";
elseif ( strstr($agent, "Mozilla/6") ) $browser = "Netscape 6";
elseif ( strstr($agent, "Mozilla/4") ) $browser = "Netscape 4";
elseif ( strstr($agent, "Opera") ) $browser = "Opera";
else $browser = "";

// get IP and resolve IP
$ip = $_SERVER['REMOTE_ADDR'];
$resolved = gethostbyaddr($_SERVER['REMOTE_ADDR']);



// check for non resolve of IP and rip domain if resolved
if ($resolved == $ip) {
$isp = ".. Can't Resolve IP";
}
else
{
$str = preg_split("/\./", $resolved);
$i = count($str);
$x = $i - 1;
$n = $i - 2;
$isp = $str[$n] . "." . $str[$x];
}

// Simple OS Detection

$os = $_SERVER['HTTP_USER_AGENT'];

$oslist = Array (

// Windows
"Win|Windows",
"Win16|Windows",
"Win95|Windows 95",
"Win98|Windows 98",
"WinME|Windows ME",
"Win32|Windows",
"WinNT|Windows NT",
"Windows 3.1|Windows 3.1",
"Windows 95|Windows 95",
"Windows CE|Windows CE",
"Windows 98|Windows 98",
"Windows ME|Windows ME",
"Windows NT|Windows NT",
"Windows NT 5.0|Windows 2000",
"Windows NT 5.1|Windows XP",

// Macintosh
"Mac_68000|MacOS m68K",
"Mac_68K|MacOS m68K",
"Mac_PowerPC|MacOS PPC",
"Mac_PPC|MacOS PPC",
"Macintosh|MacOS",

// Unices
"X11|UNIX",
"BSD|BSD",
"SunOS|SunOS",
"IRIX|IRIX",
"HP-UX|HP-UX",
"AIX|AIX",
"QNX|QNX",
"SCO_SV|SCO UNIX",
"FreeBSD|FreeBSD",
"NetBSD|NetBSD",

// Linux
"Linux|Linux",
"Debian|Debian GNU/Linux",

// Other
"BeOS|BeOS",
"OS/2|OS/2",
"AmigaOS|AmigaOS",

);

foreach ($oslist as $osnow) {
$osnow = explode ("|", $osnow);
if (eregi ($osnow[0], $os)) {
$operating = $osnow[1];
$check = "No";
} elseif ($check != "No") {
$operating = "Unknown";
}
}

// Retrieve random quote from text file
$quote_array = file("quotes.txt");
srand((double) microtime() * 10000000);
$quote = array_rand($quote_array);

// set the font and print text
ImageTTFText ($image, 10, 0, 20, 25, $black, "arial.ttf", 'Your Ip is : '.$ip);
ImageTTFText ($image, 10, 0, 20, 40, $black, "arial.ttf", 'Your Isp is : www.'.$isp);
ImageTTFText ($image, 10, 0, 20, 55, $black, "arial.ttf", 'Your Os is : '.$operating);
ImageTTFText ($image, 10, 0, 20, 70, $black, "arial.ttf", 'Your Borwser is : '.$browser);
ImageTTFText ($image, 10, 0, 20, 85, $black, "arial.ttf", $quote_array[$quote]);

// output and destroy
ImagePNG($image);
ImageDestroy($image);

?>

AaronW
12-17-2004, 03:14 AM
Odd. So you don't get any PHP errors when you run that?

Rename the script and just run it (so .htaccess doesn't interfere).

Otherwise, try using image/jpeg and imageJPEG () rather than PNGs, because your script ends in .jpg.

Bry Man
12-17-2004, 04:10 AM
Ill do that tommorow because its kinda getting late, the only error im getting is the internal error 500 when I try to access the file and jibberish when I access the php file. I dont want to use a jpeg because it would have a dramatic loss of quality as it would be recompressed twice instead of once when it passes thru the script to the browser.

firepages
12-17-2004, 07:13 AM
HI I just ran your last code (but with the png header) locally on 5.0.1 (with register_globals=Off with no issues , saved a copy ...

http://www.firepages.org/public/sig.php.png

so it must be apache server-config/dodgy .htaccess issue , it is not PHP5 itself

dniwebdesign
12-17-2004, 09:34 AM
Ill do that tommorow because its kinda getting late, the only error im getting is the internal error 500 when I try to access the file and jibberish when I access the php file. I dont want to use a jpeg because it would have a dramatic loss of quality as it would be recompressed twice instead of once when it passes thru the script to the browser.

At the current time it is 3:30 AM here...

Bry Man
12-17-2004, 03:27 PM
When I posted that It was getting near 8 at night and I had homework and stuff to do to get ready for the X-mas break.


So you didnt use the .htaccess at all? Maybe I should get a hold of my host Then.

Bry Man
12-18-2004, 11:57 PM
When I try to run it locally on php 4.2.3 it wont work either, im getting the same thing as im getting online. When I use the .htaccess file it gives me jibberish, when i view the php file it gives me jibberish I wonder why I cant get it working =S

Bry Man
12-19-2004, 07:00 PM
I am close to getting it working, I think, When I remove the part that 'draws' the information to the png it works fine by showing the image, but when I put it back in its saying it cant find the font file even tho its in the same directory, why it cint find it is beyond me, also how it worked for everyone else.