php next page error

Status
Not open for further replies.

nahsorhseda

Member
Messages
116
Reaction score
0
Points
16
i have a php script whrein it shows all my files in the particular folder{similar to wapbuddy}

files per page is set to 10,so when i click the next button the page just refrehes and shows me the same page where i was before

for example: if i was in this page http;//xyz.com/abc.php?page=1
when i click the next button i land in this page http;//xyz.com/abc.php?page=2 but the content remains the same

i had the same problem before when i was using php basic ,but i solved it by adding a php.ini file with "register_globals = on" in the same directory

but now i have upgraded to php intermediate and the problem appeared again now it doesnt get solved by even the php.ini file


here the php code that i used
PHP:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>





<title>my personal pics</title><body>
<?
// SETTTINGS
$conf["site_name"] = "NAHSORHSEDA"; // the name of your site
$conf["welcome_message"] = "hi check my pictures"; // default greeting

$conf["items_per_page"] = 10;



?>

<?php
if (!isset($page)) {$page = 0;}
$total = 0;

if(!($dp = opendir("./"))) die ("Cannot open ./");
$file_array = array(); 
while ($file = readdir ($dp))
{
if(substr($file,0,1) != '.' and $file != "index.php" and $file != "search.php")
{
$file_array[] = $file;
}
}
$file_count = count ($file_array);
sort ($file_array);
?>
</head>
<body bgcolor="#000000" text="#00FF00" link="#FFFFFF" vlink="#FF0000" alink="#FFFFFF">

<img src='http://c.wen.ru/256908.wbmp?Nahsorhsed' alt='Создай сайт! Create site!'/><br/>
<big>NAHSORHSEDA</big><br/>



<?

echo "<small>";

echo "<b><u>MY PERSONAL PICTURES</u></b><br/>";

if ($file_count > 0)
{
$first_record = $page * $conf["items_per_page"];
$last_record = $first_record + $conf["items_per_page"];

while (list($fileIndexValue, $file_name) = each ($file_array))
{

if (($fileIndexValue >= $first_record) AND ($fileIndexValue < $last_record))
{

echo "<a href=\"$file_name\">$file_name</a> (". round(filesize($file_name)/1024,1) . "kb)<br/>------<br/>";
$total = $total + filesize($file_name);
}
}

if (($file_count > 0) AND ($page != 0))
{
// previous button
$prev_page = $page -1;
echo "<br/><a href=\"".$_SERVER["PHP_SELF"]."?page=$prev_page\">Prev Page</a><br/>";
}


if (($file_count > 0) AND ($last_record < $file_count))
{
// next button
$next_page = $page + 1;
echo "<br/><a href=\"".$_SERVER["PHP_SELF"]."?page=$next_page\">Next Page</a><br/>";
}
echo "<br/>Total Files:<br/>$file_count ";
if ($file_count == 1)
{echo "file";}
else
{echo "files";}

echo " (" . round($total/1024,1) . "kb)";
}
closedir($dp);
echo "</small>";
?>
<br/>
<?
echo '<form action="process.php" method="post">'
          .'search file: <input name="q" title="search:" size="5" maxlength="99999999999"/><br/>'
          .'<input type="submit" value="go"/></form>' ?>


<small>page:<? echo"$page"; ?></small><br/>
<?
echo '<form action="'.$_SERVER["PHP_SELF"].'" method="get">'
          .'Jump to Page: <input name="page" title="Jump to Page:" size="3" maxlength="3"/><br/>'
          .'<input type="submit" value="Jump"/></form>' ?>


</p>
</body>
</html>
and thnks in advance
 

Bryon

I Fix Things
Messages
8,149
Reaction score
101
Points
48
PHP has register globals turned off. You're having this problem because of this.

More information regarding register globals: http://us.php.net/register_globals

Instead of relying on register_globals, you will need to use the GET/POST/Cookie/Server/Environment super global variables.

http://us.php.net/manual/en/reserved.variables.php#reserved.variables.get
http://us.php.net/manual/en/reserved.variables.php#reserved.variables.post

For example:

If you were doing something like calling
Code:
site.com/script.php?page=2
and then using $page in your script, you need to now use $_GET['page']. If you're unsure of what I mean or need further help, let us know.
 

nahsorhseda

Member
Messages
116
Reaction score
0
Points
16
i really did not understand what you meant ,coz iam just a beginner
could you please tell me what do i have to do with my code ,i mean what changes should i bring, please make me understand in a lay mans language ,coz i really know nothing about php

and thnks for replying
 

Corey

I Break Things
Staff member
Messages
34,551
Reaction score
204
Points
63
Where did you get your script from?

If you created it yourself you should start learning how to code without the need for register_globals. It is not being included in PHP6 because of the security risks that it has.
 

nahsorhseda

Member
Messages
116
Reaction score
0
Points
16
i did not create the script ,it was one of my friend ,it was working fine before and there fore i relied on register globals ,but since i change the php version the error started to occur.


if you cold only tell me what should i change in my script ill highly appreciate it ,
 
Status
Not open for further replies.
Top