Jump to content

marcus

Members
  • Posts

    1,842
  • Joined

  • Last visited

Posts posted by marcus


  1. I am creating pagination for forums, to limit 20 rows per page. I have the limiting correct, but when it comes to echoing the "Previous PAGENUMBERS Next" part it shows:

     

    Previous 1 Next

     

    It shows this even when there should be 5 pages. Also, the Previous 1 and Next are not linked, Previous and 1 are only linked when page > 1.

     

    $limit          = 20;               
    $query_count    = "SELECT count(*) FROM `replies` WHERE `topic` =$id";    
    $result_count   = mysql_query($query_count);    
    $totalrows      = mysql_num_rows($result_count); 
    $pie = $_GET

    ;
    intval($pie);
    if(!$pie){
    $pie=1;
    }
    if($pie != 1){ 
            $pageprev = $pie-1;
            
            echo "<a href=\"?act=topic&id=$id&page=$pageprev\">Previous </a> "; 
        }else{
            echo "Previous ";
        }
    $limit          = 20;               
        	$query_count    = "SELECT count(*) FROM `replies` WHERE `topic` =$id";    
        	$result_count   = mysql_query($query_count);    
        	$totalrows      = mysql_num_rows($result_count); 
        $pageamt = $totalrows/$limit;
        
        for($pid = 1; $pid <= $pageamt; $pid++){
            if($i == $pie){
                echo "$pid ";
            }else{
                echo "<a href=\"?act=topic&id=$id&page=$pid\">$pid</a> ";
            }
        }
    
    $giv = $totalrows%$limit;
        if($giv != 0){
            if($pid == $pie){
                echo "$pid ";
            }else{
                echo "<a href=\"?act=topic&id=$id&page=$pid\">$pid</a> ";
            }
        }
    $give = $totalrows-($limit*$pie);
        if($give > 0){
            $pagenext = $pie+1;
             
            echo "<a href=\"?act=topic&id=$id&page=$pagenext\">Next</a>"; 
        }else{
            echo "Next";
        } 
    

  2. <?php
    
    function protect($input)
    {
    $escaped_input = mysql_real_escape_string(urldecode($_POST['input']));
    // $sql = "INSERT INTO table VALUES ('$escaped_input')";
    $input = mysql_real_escape_string($input);
    $input = eregi_replace("%","",$input);
    $input = eregi_replace("--","",$input);
    $input = htmlspecialchars(mysql_real_escape_string($input));
    
    return $input;
    }
    $username = $_GET['username'];
    protect($username);
    $font = $_GET['font'];
    protect($font);
    $color = $_GET['color'];
    protect($color);
    $sql = "SELECT * FROM `users` WHERE `username` ='$username'";
    $res = mysql_query($sql) or die(mysql_error());
    if(mysql_num_rows($res) == 0){
    $text = "This user does not exist!";
    }else {
    $row = mysql_fetch_assoc($res);
    $text = "Username: $username // Forum Posts: $row[post_count]";
    }
    // create a 100*30 image
    $im = imagecreate(500, 98);
    
    // white background and blue text
    $bg = imagecolorallocate($im, 255, 255, 255);
    $array2 = array('black','red','blue','green','purple','grey');
    if(in_array($color,$array2)){
    
    switch($color){
    case black:
    $textcolor = imagecolorallocate($im, 0, 0, 0);
    break;
    case red:
    $textcolor = imagecolorallocate($im, 255, 0, 0);
    break;
    case blue:
    $textcolor = imagecolorallocate($im, 0, 0, 255);
    break;
    case green:
    $textcolor = imagecolorallocate($im, 0, 128, 0);
    break;
    case purple:
    $textcolor = imagecolorallocate($im, 128, 0, 128);
    break;
    case grey:
    $textcolor = imagecolorallocate($im, 128,128,128);
    break;
    }
    }else {
    $textcolor = imagecolorallocate($im,0,0,0);
    }
    
    // write the string at the top left
    $array = array(1,2,3,4,5);
    if(in_array($font,$array)){
    switch($font){
    case 1:
    $font = imageloadfont("andale12.gdf");
    break;
    case 2:
    $font = imageloadfont("bmreceipt.gdf");
    break;
    case 3:
    $font = imageloadfont("8x13iso.gdf");
    break;
    case 4:
    $font = imageloadfont("bmcorrode.gdf");
    break;
    case 5:
    $font = imageloadfont("bettynoir.gdf");
    break;
    }
    }else {
    $font = imageloadfont("andale12.gdf");
    }
    imagestring($im,$font, 5, 10, $text, $textcolor);
    
    // output the image
    header("Content-type: image/png");
    imagepng($im);
    ?> 
    

     

    This is my current file.

     

    How would I be able to put a break in the text?

  3. ALTER TABLE `TABLENAME`  AUTO_INCREMENT =1000
    

     

    If you don't want to use that SQL query you can go into your PHPMyAdmin, select the database, select the table, hit the Operations tab on the top, scroll down a little, and change AUTO INCREMENT to 1000

  4. In terms of advertising a website using a banner and referral link.

     

    I've written the mod rewrite for this.

     

    My problem is: How would I go about using a premade banner and printing unique text on it for each users banner.

     

    So:

     

    http://website.org/userpics/marcus.png

     

    Say I had: 800 forum posts

    I wanted it to say: Username: marcus // Forum Posts: 800

     

    Doing this by a SQL query.

     

    $username = $_GET['username'];
    protect($username); //pre-made function to protect variable
    $sql = "SELECT * FROM `users` WHERE `username` ='$username'"; //username being marcus, atm
    $res = mysql_query($sql) or die(mysql_error());
    
    if(mysql_num_rows($res) == 0){
    $text = "This user does not exist!";
    }else {
    $sql2 = "SELECT * FROM `replies` WHERE `username` ='$username'";
    $res2 = mysql_query($sql2) or die(mysql_error());
    $num = mysql_num_rows($res2);
    $text = "Username: $username // Forum Posts: $num";
    }
    

     

    RewriteRule ^userpic/([^/]*)\.png$ /userpics.php?username=$1 [L]

     

    How would I go about (probably using GD) to make the text ($text) print on the image?

  5. If you want, you can do:

     

    1. Add a time field in your users table and update it each time a logged in user goes to a new page

    2. Then:

     

    $count_time = time();
    $count_time = $count_time-900; //a difference of 15 minutes
    $online_count = mysql_query("SELECT * FROM `users` WHERE `time`>=$count_time ORDER BY `page` DESC");
    echo "<center><table cellspacing=3 cellpadding=3 width=300><tr><td class=bar><center><font class=barfont>Online List</td></tr>";
    
    while($row = mysql_fetch_array($online_count)) {
    $username = $row['username'];
    echo "<tr><td><center> <a href=/user/$username> $username </a> </td></tr> ";
    
    
    }
    echo "</table>";
    

     

    This should produce a list like:

     

    Online List

    marcus

    yasuragi

    Charlie

    hxcChaos

    Jakobo

    ulitrexx

    Caress

    Ryan

    sadie_bledsoe

    angela

    peachiekeen

    Decco

    cyllarus

    ninjacore_xxlily

    Jen

    lynne

    kim

  6. If a variable is defined again in single quotes it will be as written as the variable name, not the definition of the variable.

     

    $email = "admin@neoblob.com";
    echo '$email';
    //this would produce $email, instead of admin@neoblob.com
    //in your case $to actually is defined as $semail, not the email you specified
    

  7. This is a function I've been using for quite some time to ensure all $_GET variables I'm using in SQL queries are safe from injection attacks:

     

    // Quote variable to make safe for use in MySQL queries
    function quoteSmart($value)
    {
       // Trim whitespace
       $value = trim($value);
    
       // Stripslashes
       if (get_magic_quotes_gpc()) {
           $value = stripslashes($value);
       }
       // Quote if not a number or a numeric string
       if (!is_numeric($value)) {
       $value = mysql_real_escape_string($value);
       }
       return $value;
    }

     

    So to make your $_GET['userid'] variable safe just do:

     

    $userid =  quoteSmarty($_GET['userid']);

     

    You should't do that, for the most part it won't work.

     

    $userid = $_GET['userid'];
    quoteSmarty($userid);
    

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