Need help with this code
Moderator: General Moderators
Need help with this code
Not sure why this code stopped working it throws no errors. Register_globals is on and the PHP version is 4.4.9 It searches a folder for images then sorts them and displays links to cycle through them Any suggestions I'm guessing is some setting and not the code cuz the code worked up until like a month or 2 ago.
<?php session_start();?>
<p align="center"><img src="topbannerfinal.jpg"></p>
<?php
session_register ("fileIndex");
$dir = "images";
$dh = opendir($dir);
while (false !== ($filename = readdir($dh))) {
$files[] = $filename;
}
if($p == ""){
$HTTP_SESSION_VARS["fileIndex"] = 0;
}
sort($files);
$img = array_slice($files, 2);
$p = $_GET['p'];
$lastFile = "last";
$nextFile = "next";
$prevLink = "<a href=\"" . $_SERVER['PHP_SELF'] . "?p=" . $lastFile . "\" title=\"show previous image\">«</a>";
$nextLink = "<a href=\"" . $_SERVER['PHP_SELF'] . "?p=" . $nextFile . "\" title=\"show next image\">»</a>";
?>
<?php session_start();?>
<p align="center"><img src="topbannerfinal.jpg"></p>
<?php
session_register ("fileIndex");
$dir = "images";
$dh = opendir($dir);
while (false !== ($filename = readdir($dh))) {
$files[] = $filename;
}
if($p == ""){
$HTTP_SESSION_VARS["fileIndex"] = 0;
}
sort($files);
$img = array_slice($files, 2);
$p = $_GET['p'];
$lastFile = "last";
$nextFile = "next";
$prevLink = "<a href=\"" . $_SERVER['PHP_SELF'] . "?p=" . $lastFile . "\" title=\"show previous image\">«</a>";
$nextLink = "<a href=\"" . $_SERVER['PHP_SELF'] . "?p=" . $nextFile . "\" title=\"show next image\">»</a>";
?>
Re: Need help with this code
Not sure why you say this code stopped working you gave no explanation.chalee wrote:Not sure why this code stopped working it throws no errors.
Re: Need help with this code
Well the code was working fine then it just stopped working. I'm guessing that the hosting company may have upgraded to a different version of PHP. But everthing I've tried still does not get the code to work is there something different I have to do to get the globals to work?tasairis wrote:Not sure why you say this code stopped working you gave no explanation.chalee wrote:Not sure why this code stopped working it throws no errors.
Other than adding this to PHP.INI
register_globals = on
Re: Need help with this code
And still: no explanation of what that means...chalee wrote:Well the code was working fine then it just stopped working.
Re: Need help with this code
chalee, you must understand that we are not mind readers here. You will have to say more than "it stopped working." That means nothing. You must say exactly what happens. Does it produce any output? Do you get a blank screen? What?
And please, in the future, enclose your PHP code with [syntax=php]...[/syntax] tags in your post, so we can read the code without going blind.
And please, in the future, enclose your PHP code with [syntax=php]...[/syntax] tags in your post, so we can read the code without going blind.
Re: Need help with this code
Sorry first time in this forum here's the code with the tags. It produces absolutely no output whatsoever. Code doesn't do a darn thing. It should and did show pictures from a directory. I'll put some comments in the code as well to help you along
wait in looking at this it seems someone else was on my server and modified somethings here cuz there is not output for the images or links
Code: Select all
<?php session_start();?>
<p align="center"><img src="topbannerfinal.jpg"></p>
<?php
//declare a session variable for the
session_register ("fileIndex");
$dir = "images";
$dh = opendir($dir);
while (false !== ($filename = readdir($dh))) {
$files[] = $filename;
}
if($p == ""){
$HTTP_SESSION_VARS["fileIndex"] = 0;
}
sort($files);
$img = array_slice($files, 2);
$p = $_GET['p'];
$lastFile = "last";
$nextFile = "next";
$prevLink = "<a href=\"" . $_SERVER['PHP_SELF'] . "?p=" . $lastFile . "\" title=\"show previous image\">«</a>";
$nextLink = "<a href=\"" . $_SERVER['PHP_SELF'] . "?p=" . $nextFile . "\" title=\"show next image\">»</a>";
?>Re: Need help with this code
Thank you for following our rules. And good for you, examining your own script and discovering a clue to your own problem. If you need further help, you have now learned how to present your questions and code. Good luck.
Re: Need help with this code
No output at all? No topbannerfinal.jpg? What if you view the HTML source of the page?
A blank page typically means a parse/syntax error. Check your code for typos or missing {}s or other small flaws.
Besides that,
If that's how it really is in your file (and you didn't add those blank lines just in this post) then you need to get rid of everything before the opening <?php. To use session_start you can't have outputted anything yet and blank lines count.
Also, your code is a bit out of date so it's possible that has something to do with it (though it's less than likely). I'd suggest how to fix it but you only posted a small part.
A blank page typically means a parse/syntax error. Check your code for typos or missing {}s or other small flaws.
Besides that,
Code: Select all
<?php session_start();?>Also, your code is a bit out of date so it's possible that has something to do with it (though it's less than likely). I'd suggest how to fix it but you only posted a small part.
Re: Need help with this code
Thanks for all your help I did this for a friend of mine along time ago. So long I forgot what to even look for A few lines modified and it's okay. Here is the final script in case anyone want's to use it for a cheapo gallery.
Also the session start is the very first thing it's just the way it printed out here.
thanks for all the quick responses. Yes this code is dated I did this back in oh 2005 or so. It worked up until last week not sure how this code got modified I haven't touched it since then.
Also the session start is the very first thing it's just the way it printed out here.
Code: Select all
<?php session_start();?>
<p align="center"><img src="topbannerfinal.jpg">
<?php
//register our index for the array that holds the image name
session_register ("fileIndex");
//declare some variables for our directory
$dir = "images";
$dh = opendir($dir);
//loop through our directory gathering file names for our array
while (false !== ($filename = readdir($dh))) {
$files[] = $filename;
}
//set our index to 0 if it's our first visit to the page
if($p == ""){
$HTTP_SESSION_VARS ["fileIndex"] = 0;
}
//sort our files and clean up our array
sort($files);
$img = array_slice($files, 2);
//determine if we are moving next or back and adjust the array index accordingly to display the proper picture these get set in the link
$p = $_GET['p'];
$lastFile = "last";
$nextFile = "next";
$prevLink = "<a href=\"" . $_SERVER['PHP_SELF'] . "?p=" . $lastFile . "\" title=\"show previous image\">«</a>";
$nextLink = "<a href=\"" . $_SERVER['PHP_SELF'] . "?p=" . $nextFile . "\" title=\"show next image\">»</a>";
if($p == "next" && $HTTP_SESSION_VARS["fileIndex"] != count($img)-1){
$HTTP_SESSION_VARS ["fileIndex"]++ ;
}
if($p == "last" && $HTTP_SESSION_VARS["fileIndex"] != 0 ){
$HTTP_SESSION_VARS ["fileIndex"]-- ;
}
// and finaly below print our links and picture
?>
<table border="0" align="center">
<tr>
<td align="right">
<font size="+2"><? echo $prevLink;?></font>
</td>
<td align="left">
<font size="+2"><?echo $nextLink;?></font>
</td>
</tr>
<tr>
<td align="center" colspan="2"><? print '<img src="images/';
echo $img[$HTTP_SESSION_VARS ["fileIndex"]];
print '">';?>
</td>
</tr>
</table>
</p>Re: Need help with this code
It could be that they disabled short_open_tags. Meaning no <? or <?= - you have to use the full <?php.
Try replacing each <? with <?php.
Try replacing each <? with <?php.
Re: Need help with this code
The code does work now.