Jump to content

rythemton

Members
  • Posts

    107
  • Joined

  • Last visited

Posts posted by rythemton

  1. I second ginerjm, if only one selection is allowed, you want a radio button or drop-down list. Also, you should use JavaScript for validation. Using PHP means that the person has to submit the form before they know that what they submit was invalid, unless you use Ajax (which uses JavaScript) which is going to require more work than just using JavaScript in the first place. Your PHP should also validate the information in case the user has JavaScript disabled, but you shouldn't make people wait to know they've input invalid information if at all possible.

     

    You don't need to use Java. Java is not JavaScript.

  2. For hashing, I've started using the php password script that's mentioned by trq. http://us2.php.net/password The biggest benifit is that the hash will update with the PHP versions. No reason to reinvent the wheel.

    if( password_verify( $password, $hashedpassword ) ) {
      // user logged in
      if( password_needs_rehash( $hashedpassword, PASSWORD_DEFAULT ) ) {
        $updatedhash = password_hash( $password, PASSWORD_DEFAULT );
        // insert updated hash into database
      }
    }
    

    The only problem is that it wasn't introduced til PHP 5.5.

  3.  

    Just for fun.  links.txt needs to be writable by the webserver:

    $file = 'links.txt';
    $links = file($file);
    
    if(filemtime($file) <= strtotime('-1 month')) {
        array_push($links, array_shift($links));
        file_put_contents($file, implode('', $links), LOCK_EX);
    } 
    header('Location: ' . trim($links[0]));
    exit;
    

    This solution should work for what you want, because it rotates the links in the file itself, rather than keeping a counter.

  4. The problem is that you are using a COOKIE. Cookies are unique per computer and per browser, so when someone new gets on, or a new browser is used, their system has no 'link_index' cookie, and the count starts over. You need to save the 'link_index' on the server in some way that is not computer or browser specific. A Session won't work either, because it is also unique per computer and per browser, just stored on the server instead of the client machine.

  5. Let me verify a few things:

     

    $clones is an array, correct?

    $clones[2] is an object of some type, correct?

    Are $clones[0] and $clones[1] the same type of object?

     

    If $clones[0] and/or $clones[1] are not the same type of object as $clones[2] then trying to assign something to $clones[0 or 1]->attackGroup will throw an error and stop the script, and it will never get to $clones[2].

     

    We difinetely need more information.

  6. There is something missing. Both cases should work.

     

    Are there any error messages?

     

    Does this code work?

    foreach($clones as $key => &$value) {
            $value->attackGroup = $_POST['type'][$key];
    }

    Without seeing more code, it's nearly imposible to figure out what's wrong.

  7. The first error is caused because mysql_query() returns a FALSE if there is something wrong with the query.

     

    The second error is saying the the $CURUSER variable has not been set. Variable names are case sensitive. Also, check for mispellings.

     

    The next error can be resolved by checking to see if the $_GET and $_POST variables are set with isset() as suggested by PaulRyan.

     

    The last error, as PaulRyan states, is because the sqlerr() function doesn't exist. As with variable names, functions are case sensitive.

  8. To be honest, it's really hard to tell how the images are stored. They could be stored as files that are directly accessed, or they could be stored as files that are indirectly accessed through a script, or they could be stored in a database as a 'blob' (binary large object) and accessed through a script. Your browser can't tell the difference, so it's hard to tell what process was used.

     

    If you have done everything correctly, it shouldn't matter how you have stored the images. I usually store the files in a locked directory so that they can't be accessed directly, then I use a PHP script to fetch the files. The only thing I store in the database is details about the file (height, width, original file name, etc.) and I don't store the files by their original name, that way I can guarantee that each file is uniquely named and doesn't overwrite other files.

  9. So, you would suggest the following code:

    $stmt = $database->stmt_init();
    
    $query = "UPDATE table SET group = (?), username = (?)";
    $types = 'is';
    $vars = "".$vbulletin->GPC['user']['usergroupid']."", "".$vbulletin->GPC['user']['username'].", ";
    
    $query .= " WHERE userid = (?)";
    $types .= 'i';
    $vars .= "".$vbulletin->GPC['userid']."";
    
    //Debugging
    echo 'Query: '.$query.'<br />';
    echo 'Types: '.$types.'<br />';
    echo 'Types - DATA TYPE: '.gettype($types).'<br />';
    echo 'Vars: '.$vars.'<br />';
    echo 'Vars - DATA TYPE: '.gettype($vars);
    
    $stmt->prepare($query);
    $stmt->bind_param($types, $vars);
    $stmt->execute();
    
    $stmt->close();
    
    $database->close();
    

     

    No. I'm suggesting the following:

    $stmt = $database->stmt_init();
    
    $query = "UPDATE table SET group = (?), username = (?)";
    $types = 'is';
    
    $query .= " WHERE userid = (?)";
    $types .= 'i';
    
    //Debugging
    echo 'Query: '.$query.'<br />';
    echo 'Types: '.$types.'<br />';
    echo 'Types - DATA TYPE: '.gettype($types).'<br />';
    
    $stmt->prepare($query);
    $stmt->bind_param($types, $vbulletin->GPC['user']['usergroupid'], $vbulletin->GPC['user']['username'], $vbulletin->GPC['userid']);
    $stmt->execute();
    
    $stmt->close();
    
    $database->close();

     

    And now that I've looked at the manual, I don't think mysqli will allow arrays in bind statements.

  10. Your second bit of code doesn't work the way you think it does:

    if (substr($foobar, 0, 2) === 'ab' or 'ba') // This won't work right

    This is going to check if the first two characters is 'ab', then it's going to check to see if 'ba' is TRUE or FALSE, which will be always TRUE because a nonempty string is considered TRUE in PHP. So you can see this better, here is your code again using parenthesis to show order of precedence:

    if ( ( substr($foobar, 0, 2) === 'ab' ) or ( 'ba' ) ) 

    You'll need to do the comparison twice for it to work right:

    if (substr($foobar, 0, 2) === 'ab' or substr($foobar, 0, 2) === 'ba') 

     

    As for checking variation in Caps, there are many ways you could go. One of the easiest in this case would be to force the results to be lowercase:

    if (strtolower(substr($foobar, 0, 2)) === 'ab' or strtolower(substr($foobar, 0, 2)) === 'ba') 

     

    You can see more of PHP order of precedence at http://php.net/manual/en/language.operators.precedence.php

     

    For more complicated checks, you can also use regular expressions, which can shorten your code.

  11. Putting the directory name as a variable should work, as long as the directory actually exists. If each user will have a different directory for their files, then you need to either create the directory when the username is created, or check to see if the directory exists when a file is uploaded, and create it if the directory does not exist.

     

    If the directory does exist but you still can't upload, then it may be a permissions issue.

  12. As for speed, the closer the server is to the user the faster the site will be.

     

    That depends on a lot of factors... but, yeah, in theory you're correct.

    Closer to the server will lower latency, but speeds will be dictated by bandwidth.

     

    A server very close with a DSL line will have much slower max speeds than a OC-48 server thousands of miles away. Someone connecting with a Dialup line (are these even still in use?) will see faster speeds from the DSL, only because the dialup line will be the bottleneck. Someone with a DSL line the same speed as the server's DSL line may see faster speeds from the DSL, unless the server is responding to multiple requests. Someone with a T4 will see much better rates from the OC-48 server.

     

    There are a lot of factors involved: number of hops, bottlenecks (sections with slower speeds), server load, etc. Location doesn't matter for SEO. I'd suggest choosing based on your customers. If using a cheaper server that is further away saves you and/or your customers money, it may be worth it.

  13. The MySQL fetch functions have an internal pointer that advances each time you fetch a row. If you need to parse the data again, you'll have to move the pointer back to the beginning using the mysql_data_seek function:

    mysql_data_seek( $result_user_votes, 0 );

  14. Yeah, I'm really taken aback when people don't understand what timezones are. Didn't elementary school teach that stuff?

    The problem is that everything is automating the timezones, so it has become more transparent. Email programs convert the time for you. Cell phones update themselves based on the cell towers as you travel, and convert the time messages were sent.

     

    Even computers update themselves for Daylight Savings time, without any user intervention.

     

    I haven't set my alarm clock time for over 7 years, since I use my cell phone as my alarm clock now. I can set it for multiple alarms that can be set to go off only on certain days.

     

    Without this real world experience, what was taught in school gets quickly forgotten. (Goes the same place as grammar does, I think :P )

  15. GMT is often used because that time zone is opposite the International Date Line, allowing you to express your time zone as GMT +/- up to 12. GMT is also not affected by Daylight Savings Time.

     

    For your information:

    Pacific Standard Time (PST) is GMT-8

    Pacific Daylight Time (PDT) is GMT-7

    Eastern Standard Time (EST) is GMT-5

    Eastern Daylight Time (EDT) is GMT-4

     

    So to figure out what time in your time zone, it was sent at GMT-8, so you add 8 to get GMT, or 9:33:22 PM, then you modify by your GMT value, or GMT-4 because it's EDT, so you subtract 4 to get 5:33:22 EDT.

     

    Most email software actually sends the email in GMT format, then relies on the recipient's email software to convert it to the local time.

     

    Hope that wasn't too confusing.

  16. 1 - Static pages use less resources on the web site, but that doesn't make them better.

     

    2 - Search Engines can't tell if the page is Static or Dynamic. All they can tell is if the page is updated regularly. Since Dynamic pages can be set to automatically update, they are actually better for SEO. Use Dynamic pages to do the work for you.

     

    3 - In some cases URL rewriting can help your SEO. You'll have to research this to decide exactly what you want.

     

    4 - They are most definitely using Dynamic Pages.

     

    5 - Yes it can be done, but it will be just as much work (or possibly more) than just creating the pages Dynamic in the first place.

     

    SEO is constantly changing. Google is getting so that it will penalize you if try to cheat your rating. Links from other web sites can help your rating, but links from 'Link Farms' will kill you. Your best bet is to make a legitimate web site that people want to visit and link.

  17. Anyone else have experience of Programmer+Designer cooperation? Any tips or suggestions appreciated.

    It's the Designer's job to create the CSS, the programmer's job to create the PHP, and you work together to decide what the HTML code needs to look like. The Programmer may also have to program any JavaScript that may be requested. That's usually how I've done it.

     

    The designer may create the whole HTML template with the programmer filling in marked sections. It really doesn't matter, as long as both parties agree as to what jobs they will be performing.

  18. isn't xhtml dead now they have moved away from it and back to html?

    I use XHTML convention when I create HTML 5 pages. I find that my web page coding is cleaner. There is also XHTML 5, which is just HTML 5 with XHTML rules added, but I don't use it because I don't know how supported it is.

     

    I personally like XHTML. It makes code much cleaner, which makes it easier to troubleshoot other people's code. I think it was a mistake for HTML 5 to allow sloppy coding!

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