earn easy 100 points for helping me (topic-php)

Status
Not open for further replies.

nahsorhseda

Member
Messages
116
Reaction score
0
Points
16
this topic was posted before in free hosting but no one is intrested in helping me thats why iam posting it here .


credits:100


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>

i know this error is caused because the register global is turned off
if you know how to solve it just copy the code and edit it and post it here
if you get it right ill pay you 100 credits


and if you explain/teach me how this php code works {coz this code is edited by my friend} ill pay you extra 50 credits

.............do it fast before someone else gets it right
 

Thewinator

New Member
Messages
256
Reaction score
0
Points
0
PHP:
if (!isset($page)) {$page = 0;}
Since the ?page=* is a get variable you need to set it.
PHP:
if(!isset($_GET['page'])){$page = 0;}else{$page = $_GET['page'];}

As for telling you how it works, I'll add you on msn or xfire.
Pm me with your email/username.
 
Last edited:

Slothie

New Member
Messages
1,429
Reaction score
0
Points
0
Or an even easier way to 'fix' all your pages is just to add the following code on top.

PHP:
extract($_REQUEST);

That way you do not have to modify existing code and potentially miss out anything :)
 

Thewinator

New Member
Messages
256
Reaction score
0
Points
0
Believe me my method works with the code above.
Also you might want to add one more argument to that.
For instance if I linked to the page and use ?conf=nowai
It would resolve in a blank welcome, broken links and no files will be show.

If you do want to use that I would change that to
PHP:
extract($_REQUEST, EXTR_SKIP);

Becouse we know it wont need to overide values this will work without further editing your code.
 
Last edited:

Slothie

New Member
Messages
1,429
Reaction score
0
Points
0
I didn't bother reading much except that he needs globals on.

That line of code I gave him gave him exactly that. Giving him an extra prefix somewhere might screw things up somewhere later if the author of the script had something that relied on it.




Then again, let the OP chooses what he want :)
 

Thewinator

New Member
Messages
256
Reaction score
0
Points
0
Well I read the rest of the script and it needs just the $_GET['page'].
So all three methods would work except for the not prefixed or skipped one can corrupt the variables needed.
 

nahsorhseda

Member
Messages
116
Reaction score
0
Points
16
hey thanks guys .....all the methods worked but i cant give 100 credits to all


iam givin my 100 credits to slothie because i need not have to change my coding and it worked perfectly fine

well for you thewinator ill be sending you 50 credits coz u were the first one to help me ,i really appreciate it , (no need of explaining the code to me ,my friend helped me out)


thats all......hey and also tell me how do i close this topic .............
 
Status
Not open for further replies.
Top