Jump to content

remove register globals


izlik

Recommended Posts

Hey there.

 

im a beginner at php and started trying to make a tag script, and i got told i almost got it to work, i just need to make it so $pagenum and $tag wont register globals and i right now have no clue how to do that.

 

i wonder if anyone could help me make it so $pagenum and $tag wont register globals in the code bwllow?

 

<?php

$con = mysql_connect("localhost","asd","das") OR die('Could not connect: ' . mysql_error());
mysql_select_db("asd", $con);

//This checks to see if there is a page number. If not, it will set it to page 1
if (!(isset($pagenum)))
{
$pagenum = 1;
}

$result = mysql_query("
    SELECT *
    FROM `images`
    WHERE `tags`
    LIKE '%" . mysql_real_escape_string($_GET['tag']) . "%'
    ORDER BY views
    $max
")
OR die(mysql_error());
$rows = mysql_num_rows($result);

//This is the number of results displayed per page
$page_rows = 30;

$last = ceil($rows/$page_rows);

if ($pagenum < 1)
{
$pagenum = 1;
}
elseif ($pagenum > $last)
{
$pagenum = $last;
}

$max = 'limit ' .($pagenum - 1) * $page_rows .',' .$page_rows;

while($row = mysql_fetch_array($result))
{
    
    echo '<div style="float:left;width:25%"><a href="http://mydomain.net/show.php/' .$row['id'].'_' .$row['name'].'"><img src="http://www.mydomain.net/out.php/t' .$row['id'].'_' .$row['name'].'"></a></div>';
    echo "<br>\n";

}   

?>
<div style="clear:both"></div>
<?  

    echo " --Page $pagenum of $last-- <p>";
   
    if ($pagenum == 1)
{
}
else
{
echo " <a href='{$_SERVER['PHP_SELF']}?pagenum=1&tag={$_GET['tag']}'> <<-First</a> ";
echo " ";
$previous = $pagenum-1;
echo " <a href='{$_SERVER['PHP_SELF']}?pagenum=$previous&tag={$_GET['tag']}'> <-Previous</a> ";
}

//just a spacer
echo " ---- ";

if ($pagenum == $last)
{
}
else {
$next = $pagenum+1;
echo " <a href='{$_SERVER['PHP_SELF']}?pagenum=$next&tag={$_GET['tag']}'>Next -></a> ";
echo " ";
echo " <a href='{$_SERVER['PHP_SELF']}?pagenum=$last&tag={$_GET['tag']}'>Last ->></a> ";
}
?> 

Link to comment
https://forums.phpfreaks.com/topic/78015-remove-register-globals/
Share on other sites

$pagenum is coming from a URL using GET or POST. We can't tell without looking at the relevant code. At any rate, with register_globals ON, these values are automatically converted to $pagenum. With register_globals OFF, you have to access these values with $_GET['pagenum'] or $_POST['pagenum'], whichever is appropriate. You can convert them like so:

 

<?php
$pagenum = $_GET['pagenum'] // or $_POST if applicable
?>

 

Then you can use $pagenum as desired and turn OFF register_globals in php.ini

 

PhREEEk

$pagenum is coming from a URL using GET or POST. We can't tell without looking at the relevant code. At any rate, with register_globals ON, these values are automatically converted to $pagenum. With register_globals OFF, you have to access these values with $_GET['pagenum'] or $_POST['pagenum'], whichever is appropriate. You can convert them like so:

 

<?php
$pagenum = $_GET['pagenum'] // or $_POST if applicable
?>

 

Then you can use $pagenum as desired and turn OFF register_globals in php.ini

 

PhREEEk

 

hey there.

 

register_globals is turned of in my php.ini and the code above is te only code i have, and if you go to http://filefrog.net/new.php?&s=300 and press the tag "games" (has enouff pictures to show the problem) and then go to the bottom of the page and press "next" you can se the URL

 

with this information, do you think you could help me to make it work? i would be eternely thankfull as im going crazy on that i cant fix it myself! :(

 

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.