Jump to content

rhodesa

Staff Alumni
  • Posts

    5,253
  • Joined

  • Last visited

Posts posted by rhodesa

  1. whenever you are debugging mysql_query() you should do it in the form of:

          $results = mysql_query($query, $link) or die(mysql_erryr($link));

    it will provide useful info on what you are doing wrong.

     

    on that note, UPDATEs are not the same as INSERTs:

    http://dev.mysql.com/doc/refman/5.1/en/update.html

          $query = "UPDATE castack SET ";
          $query .= "`name` = '$name', `username` = '$username1', `imagelocation` = '$imagelocation' WHERE id=$id";

  2. if the site is a dynamic cms, where all URLs are are mod_rewrite to an index.php file, you can probably add something there. but if they are static pages, you will want to use .htaccess to setup a custom 404 page that is a php script...and in that script you can send an email to an admin

     

    Custom 404:

    http://www.pageresource.com/zine/custom404.htm

     

    But have the page it points to be a PHP script...in that script you can use mail() to send you the values of $_SERVER['REQUEST_URI'] and $_SERVER['HTTP_REFERER']

  3. if you update this line:

                         $result = @mysql_query ($query) or die ("MySQL Error: ".mysql_error());

    it will give you info on what is wrong...to fix the problem, i think this is what you need:

                         $query = "SELECT * FROM hunt_info WHERE huntStatus = '$key' AND
                                username = '$username'
                                ORDER BY date_of_hunt DESC";

  4. the lock is released as soon as the script ends...even if the user cancels the download

     

    ...one other note...you will end up with a folder FULL of lock files (one for every IP that has ever downloaded). you may want to write a script that goes through and cleans up those files (although, they are empty...so they won't take up much space at all)

  5. so sessions are used for tracking information while a user is visiting your site...great for logins, etc. but what if you want a URL someone can use to uniquely identify a user's profile? enter GET...it would look like so:

     

    <?php
    if(!$_GET['user']){
      die("User not found");
    
    mysql_connect("***","***","***") or die ("Couldn't connect");
    mysql_select_db("***") or die ("Couldn't find db");
    
    $user = mysql_real_escape_string($_GET['user']);
    mysql_query("SELECT image FROM profile WHERE username='$user'");
    
    ?>

    and the url for this profile would be something like:

    http://www.yourserver.com/profile.php?user=someusername

  6. well...if you are using placeholders like described above, you can just use str_replace() to find/replace the values. personally, i would use Smarty though...which is a PHP Templating engine...but it might be a little bit more then you want to get into.

     

    for str_replace()...you first need to collect all your data and have that ready...then load up the template (either from a form or from something in your db)...then it's just str_replace() on the template code for each of the placeholders

     

  7. yup, you can read it from the session...but a user will only be able to see their own profile that way. for the ability to see other people's profiles, you will need to use GET

     

    so, the template is as dynamic as you want it to be. if you have info for a background color for that user stored in the database, you can select it from the db then do:

    <div style="background:<?php echo $color;?>;">

    and so on....

  8. Is the HTML file they are uploading the template and you will insert data into it? Or is the person uploading an HTML file with data in it that you will extract and put into a template that is already on your server?

  9. $_COOKIE get's set when the script initiates...so after using setcookie(), $_COOKIE doesn't update (until the page reloads). after you set the cookie, just set a variable like $safe and then use:

    if(isset($_COOKIE['username']) || $safe)

  10. write a wrapper script for downloading files...let's call it download.php...and have all downloaded files go through there (this is a pretty common thing, let me know if that part is confusing)

     

    then, in your download script, before you give them the file, open a read handle on their IP address in some temp folder:

    $lck = fopen($_SERVER['REMOTE_ADDR'],'r+');

    then, open an exclusive lock on that file:

    flock($lck, LOCK_EX);

    next, serve up the file

    finally, close the file handle to free up the lock

    fclose($lck);

    with the exclusive lock, any subsequent requests from the same IP (aka trying to lock the same file) will wait for the first request to finish. obviously, the person could still spoof their IP though

  11. you will learn soon that parsing HTML is not an easy task. if everything was perfectly coded, you could use XML libraries to do exactly what you want...but as soon as someone forgets to close a tag or has something out of order at all...the entire block of HTML is unreadable.

     

    for that reason, most people end up parsing it with commands like preg_match(). this allows you to set a matching pattern to look for. finding a single item like a <a> tag is pretty straight forward...but it gets complicated when you have nested elements

  12. the code should be like this:

     

    <?php
    function getEmails() {
    global $host,$username,$password,$db_name,$tbl_name;
    $tbl_name="emails"; // Table name
    
    ob_start();
    // Connect to server and select databse.
    mysql_connect("$host", "$username", "$password")or die("cannot connect");
    mysql_select_db("$db_name")or die("cannot select DB");
    
    $emails = array();
    $sql="SELECT * FROM $tbl_name";
    $result=mysql_query($sql);
    while($row = mysql_fetch_array($result)){
      $emails[] = $row[0];
    }
    mysql_close();
    
    return $emails;
    }
    ?>

     

    <?php
    include_once('functions.php');
    
    foreach(getEmails() as $email){
    echo $email;
    echo "<br />";
    }
    ?>

     

    what is the name of the column in the emails table that you are trying to extract from...i assumed it was called 'email'

  13. you can't force it to have leading zeros in the DB...cus it's an integer and integers don't have leading zeros. but you can add the leading zeros when you display the number:

     

    <?php
      $id = 5;
      print str_pad($id,5,'0',STR_PAD_LEFT);
      //or
      printf('%05d',$id);
    ?>

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