Script not working, no errors, no access

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

Post Reply
User avatar
vigge89
Forum Regular
Posts: 875
Joined: Wed Jul 30, 2003 3:29 am
Location: Sweden

Script not working, no errors, no access

Post by vigge89 »

My signature image generation script stopped working some time ago. It works perfectly on my own local server, but I don't get any output at all on my remote server, it doesn't even show up in the access nor error logs generated by PHP. I've tried to find the problem which prevented it from working, but I don't have a clue after 2 hours of debugging. I've only found out what line it breaks on (tested every line by putting echoes).

Code: Select all

<?php

########## settings ##########
## note: both the template and the randomly selected mini-images must be saved as png-24

// filenames (and if needed, paths) for count- and templatefile
$template = 'net_tpl_square.png';
$count_file = 'count';

// location of randomly selected mini-images ( set it to '.' to have same directory)
$folder = 'img/';

// mini-images to randomly output (if you want to have all pngs in the folder, just use 'all'
$files = array (
'all'
#'pic1.png','pic2.png','pic3.png'
);

// font settings (use the absolute path, ie: C:\Windows\Fonts\Arial.ttf
$font = realpath ('./KROE0553.TTF');
$fsize = 6; // font size (width)
########## /settings ##########


########## read & update views ##########
// read from counter-file
$count = @file ($count_file);# or die ('could not load file');

// views-text
$views = ++$count[0];

// update views
$c_file = @fopen ($count_file, 'w');# or die ('could not open file for writing');
if ($c_file):
	@fwrite ($c_file, $views);# or die ('could not update file');
	@fclose ($c_file);
endif;
########## /read & update views ##########


########## /choose mini-image ##########
// should all pngs in the folder be used?
if ($files[0] == 'all') {
	$files = array (); // empty files
	if ($f_folder = opendir ($folder)): // open folder
		while ($ofile = readdir ($f_folder)):
			if ($ofile == '..' || $ofile == '.') continue;
			$img_info = getimagesize ($folder.$ofile);
			if ($img_info['mime'] == 'image/png')
				$files[] = $folder.$ofile; // add to files
		endwhile;
	endif;
}

// pick a filename from list for displaying
$rnd_file = array_rand ($files);
########## /choose mini-image ##########


########## output final image ##########

// create images for template and mini
$output = imagecreatefrompng ($template);# or die ('could not load template-image'); ##<<<<< BREAKS HERE
$insert = imagecreatefrompng ($files[$rnd_file]);# or die ('could not load mini-image');

// merge the images together
imagecopy ($output,$insert,4,12,0,0,260,62);# or die ('could not insert mini-image');

// colors
$fc = imagecolorallocate ($output, 95, 97, 100); // foreground color
$bc = imagecolorallocate ($output, 250, 250, 250); // shadow color

// output views-string
imagettftext ($output, $fsize, 0, 229, 10, $bc, $font, $views);
imagettftext ($output, $fsize, 0, 228, 9, $fc, $font, $views);# or die ('could not echo views');

#### create the image ####
	header ("Content-type: image/png");
	#header ("Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0");
	#header ("Expires: ".gmdate("D, d M Y H:i:s", time() + 60*3)." GMT");
	#header ("Pragma: no-cache");
	imagepng ($output) or die ('could not create the image');
#### /create the image ####

########## /output final image ##########

?>
Does anyone have a clue on why it wouldn't be working? $template is set to 'net_tpl_square.png' in the first lines, and the file exists and is located in the same folder as the script.

A huge thanks in advance.
User avatar
JAM
DevNet Resident
Posts: 2101
Joined: Fri Aug 08, 2003 6:53 pm
Location: Sweden
Contact:

Post by JAM »

Remove the

Code: Select all

header ("Content-type: image/png");
aswell as the @function(s) (so errors during execution will display and add

Code: Select all

error_reporting(E_ALL)
somewhere...
Then run it again, and see what happens.

Continue debuging the script by echo'ing out vars you set here and there and see if something is giving away something that just shoulndt be that way.
User avatar
vigge89
Forum Regular
Posts: 875
Joined: Wed Jul 30, 2003 3:29 am
Location: Sweden

Post by vigge89 »

Already tried all that, but of course you couldn't know that (must remember to point everything out next time ><), no errors at all, the file is only accessible if i comment everything below the output final image comment.
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

Sorry I'm confused?

There is nothing under that comment.. am I wrong?

Edit | Oops My Bad :roll:
Last edited by John Cartwright on Sat May 28, 2005 11:42 am, edited 1 time in total.
User avatar
JAM
DevNet Resident
Posts: 2101
Joined: Fri Aug 08, 2003 6:53 pm
Location: Sweden
Contact:

Post by JAM »

He means

Code: Select all

########## output final image ##########
and not

Code: Select all

########## /output final image ##########
Testing this locally and remotely too, but there is some things that needs editing to get it to work here.

Update: It works here. It looks like crap as I do not have your images nor font installed, but I do get an image and another (the same?) over that one.
No errors whatsoever. Tested on PHP Version 5.0.4 on Win32 and PHP Version 4.3.11 on slackware.
User avatar
vigge89
Forum Regular
Posts: 875
Joined: Wed Jul 30, 2003 3:29 am
Location: Sweden

Post by vigge89 »

Hmm, must be server related then, I'll go ask my host for any recent updates on the PHP core :?

Thanks for your replies :)
User avatar
JAM
DevNet Resident
Posts: 2101
Joined: Fri Aug 08, 2003 6:53 pm
Location: Sweden
Contact:

Post by JAM »

You could also try to trim down that script so thats it's extremely basic and small and see if it still fubars. I thought of the idea to narrow it down to (perhaps) just on function that doesn't behave as it should and go from threre.

There might be prerequsites thats not in order for GD or whatever. I'd start with loosing the call to the TTF font for starters, using only the internal font(s).

Up to you tho. :wink:
User avatar
vigge89
Forum Regular
Posts: 875
Joined: Wed Jul 30, 2003 3:29 am
Location: Sweden

Post by vigge89 »

Yeah, I guess I'll try something like that, thanks for the tip :)

Edit: After trying commenting the imagecreatefrompng() calls, it works. So, the problem lies in that the imagecreatefrompng-function doesn't seem to work on the remote server. I'll try contacting my host to see if he has done anything with the PHP core or GD.

Edit2: He has updated PHP to 4.3.11-7, I'll have a look for any changes realting to this. Does anyone of you have any clues?

Edit3: Nothing in the changelog related to this.

If you want to test the script out with the right images, they can be found here:
$template: http://vigge.net/img/sig/net_tpl_square.png
$random: http://vigge.net/img/sig/img/jaws30s1.png
User avatar
JAM
DevNet Resident
Posts: 2101
Joined: Fri Aug 08, 2003 6:53 pm
Location: Sweden
Contact:

Post by JAM »

Not sure about the relevance, but this bugreport and some others report various of errors.

Neverless, http://bugs.php.net/ is probably better to use instead of changelogs.
vigge89 wrote:If you want to test the script out with the right images, they can be found here:
$template: http://vigge.net/img/sig/net_tpl_square.png
$random: http://vigge.net/img/sig/img/jaws30s1.png
http://vigge.jam.nu/ :lol:
User avatar
vigge89
Forum Regular
Posts: 875
Joined: Wed Jul 30, 2003 3:29 am
Location: Sweden

Post by vigge89 »

JAM wrote:Not sure about the relevance, but this bugreport and some others report various of errors.

Neverless, http://bugs.php.net/ is probably better to use instead of changelogs.
vigge89 wrote:If you want to test the script out with the right images, they can be found here:
$template: http://vigge.net/img/sig/net_tpl_square.png
$random: http://vigge.net/img/sig/img/jaws30s1.png
http://vigge.jam.nu/ :lol:
I looked trough the bugreports before, but couldn't find anything relevant to this problem, as all of the bugreport issues still produce something, my script won't even want to run it seems.

Your copy of the script doesn't update the views it seems :P
User avatar
JAM
DevNet Resident
Posts: 2101
Joined: Fri Aug 08, 2003 6:53 pm
Location: Sweden
Contact:

Post by JAM »

Code: Select all

&#1111;15:11:36] &#1111;R] SITE CHMOD 777 count
&#1111;15:11:36] &#1111;R] 200 Permissions changed on count
:wink:
Post Reply