PHP script stopped working

software development

#1

Was there a recent change, say in the last few months, that would have caused my scripts to stop working? When I viewed my web site today, I saw an error related to $this. I modified it based on a Google search, but the rest of my script is still failing. The script basically retrieves, sorts, and then displays images from a directory. It appears to fail right after the part of the script that writes the number of images, but there is no error on the screen. I haven’t touched this code in ages, so I am having troubles figuring it out. Any tips would be much appreciated!

Sample link that should have images showing up: http://www.stripedwall.com/gallery.php?page=trailers/AeonFlux

Scroll about halfway down to my comment “Changed my code to …”

[code]<?php

//global values?

// page variable
if (isset($_GET[‘page’])) {
$page = $_GET[‘page’];
}

// page variable
if (isset($_GET[‘dir’])) {
$dir = $_GET[‘dir’];
}

// check for valid request
function valid_request() {
global $valid_pages;
global $page;
global $dir;

 if (!in_array($page,$valid_pages)) {
// Abort the script
// You should probably write a log message here too

die("Invalid request");
 }

}// end of valid request function

// write out the thumbnail pages

function write_out($page) {

$path = "http://www.stripedwall.com";

$myDirectory = opendir("$page");

//this is a function I wrote to sort out the contents of the directory date wise for display.

$content_array = array();

$i=0;
while (false !== ($file = readdir($myDirectory)))
//while ($file = readdir($myDirectory))
if ($file != “.” && $file != “…” && $file != “th”)
{
$content_array[$i] = $file;
$i++;
}

//close the directory handle
closedir($handle);

//sort them
sort($content_array, SORT_STRING);

// count elements in array
$indexCount = count($content_array);
Print ("

$indexCount files


\n");

// set some number variables copied from the paging navigation function below
if (isset($_GET[‘start’])) {
$start = $_GET[‘start’]; }
else { $start = 0; }

$eu = ($start - 0);
$limit=24;
// Changed my code to the two lines below to avoid fatal error for $this
$ref = getRef($this);
$ref = $eu + $limit;

// My code used to be this one line below.
//$this = $eu + $limit;
$back = $eu - $limit;
$next = $eu + $limit;

$p_limit=500;

if (isset($_GET[‘p_f’])) {
$p_f = $_GET[‘p_f’]; }
else { $p_f = 0; }

$p_fwd=$p_f+$p_limit;
$p_back=$p_f-$p_limit;

// print 'em

for ($index=$start; $index<=$ref && $index<$indexCount; $index++) { //Changed $this to $ref due to fatal error

if($index != $eu) {
	$index2=$index+$p_f; }

//for($index=0; $index< $indexCount; $index++)
//{
//$number = $index + 1;

     $mystring = $content_array[$index];
     //$mystring = $content_array[$index][0];
     //$mydate = $content_array[$index][1];


$style = "margin: 3px; padding: 2px; border: 2px solid #CCC;";

Print("<a href=\"?image=/$page/$mystring&mode=fullsize\" title=\"Click to view image.\">");
Print("<img style=\"$style\" src=\"/$page/th/thumb_$mystring\" border=\"0\" alt=\"$mystring\" /> ");
Print("</a>");
           

}

} //end of print thumbnails page function

// write out the fullsize image

function write_out_image($image) {

if (isset($_GET[‘image’])) {
$image = $_GET[‘image’];

} else {
if (!isset($_GET[$image])) {
// Abort the script
// You should probably write a log message here too
die(“Invalid request”);
}
}

$size = getimagesize(".$image");
$xwidth = $size[0];
$xheight = $size[1];
if ($xwidth > 900) {
$width = “900px”;
$text = “Click to view full-size ($xwidth x $xheight) in a new window/tab.”; }
else {
$width = $xwidth;
$text = “Click to view in a new window/tab.”; }

// print the image
print("<a target="#new" href="$image" title="$text">");
print("<img style="$style" src="$image" border=“0” alt="$mystring" width="$width" /> “);
print(”");

} // end of the fullsize image function

if ($mode ==“fullsize”) {
//print (“Working?”);
@write_out_image($image); }
else {
if ($page != “” ) {
@valid_request($page);
@write_out($page); }
else {
print (“

Please choose a category to view the images.

”);
}
}

?>[/code]


#2

Anything in your site logs?


#3

Unfortunately, not that I can see. In FTP, I went the root and navigated down to the logs folder for my domain and checked the error and access logs. I hit the gallery and went back to today’s logs and didn’t see anything new.