Jump to content

problem with tags code.


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 bellow?

 

register_globals is turned of in my php.ini, 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 for the query.

 

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 :(

 

<?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
Share on other sites

Register globals is basically getting something from the URL and then using it in a script. It's a pretty simple problem.

 

EG: if I visit mypage.php?variable=foo

Then I do: echo $variable;

It will say "foo".

 

So what I think you are talking about is this section for example:

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

 

 

So, (I might be wrong I've never used a server with globals turned off) I think that with your global settings turned off, just saying $pagenum won't help. You'll have to use $_GET.

 

(Same for $tag)

 

Summary: just use $_GET.

Link to comment
Share on other sites

Register Globals means that the post and get argument names get turned into $var for you. It is controversial and Im on the side that believes it is dangerous and should be turned off by default.

 

all it means now is that you need to use the super globals PHP provides to turn the args into vars.

 

there are three that deal with arguments passed to then next page.

$_GET = value passed thru the URL

$_POST = value passed via post data

$_REQUEST = contains them both, I use this one the most

 

so to bring in the argument for pagenum you do the following

$pagenum = $_REQUEST['pagenum'];

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.