Jump to content


  • Posts

  • Joined

  • Last visited


Posts posted by john010117

  1. Since I have very little experience in working with GD library, I need advice on how to improve this simple CAPTCHA code (don't worry, I have other security precautions in place, since CAPTHA aren't that secure). I've only included the page that actually displays the image.


    $RandomStr = md5(microtime());// md5 to generate the random string
    $ResultStr = substr($RandomStr,0,5);//trim 5 digit
    // Select a random background image
    while($imgfile=readdir($dir)) {
       if ($imgfile != "." && $imgfile!="..") {
    if($rand >= 0) {
       $RandomImage = $imgarray[$rand];
    $NewImage =imagecreatefrompng("./images/captcha/$RandomImage");//image create by existing image and as background
    $randcolR = rand(100,230);
    $randcolG = rand(100,230);
    $randcolB = rand(100,230);
    $LineColor = imagecolorallocate($NewImage,233,239,239);//line color 
    $TextColor = imagecolorallocate($NewImage, ($randcolR - 20), ($randcolG - 20), ($randcolB - 20));
    imageline($NewImage,1,1,40,40,$LineColor);//create line 1 on image 
    imageline($NewImage,1,100,60,0,$LineColor);//create line 2 on image 
    imagestring($NewImage, 5, 20, 10, $ResultStr, $TextColor);// Draw a random string horizontally 
    $_SESSION['key'] = $ResultStr;// carry the data through session
    header("Content-type: image/png");// out out the image 
    imagepng($NewImage);//Output image to browser


    Before you suggest any suggestions, please not that I only have GD library available on my server (that means no FreeType). Ok, now, any suggestions please? :D

  2. Put the form on one page (ex: form.html). Then put all of the processing stuff in another (ex: process.php).


    Your form.html will have something like this:

    <form action="process.php" method="POST">
    ...form code goes here


    And your process.php will have the PHP code in there.

  3. Warning: main(EDIRECTORY_ROOT/layout/header.php) [function.main]: failed to open stream: No such file or directory in


    Warning: main() [function.include]: Failed opening 'EDIRECTORY_ROOT/layout/header.php' for inclusion (include_path='.:/usr/lib/php:/usr/local/lib/php') in


    Fatal error: Call to undefined function: html_selectbox() in


    Make sure you've moved ALL of the files from your old site to new (to the correct directories). That's what the error messages are about.

  4. Sure thing.


    $upload_dir = "images/";
    $upload_file = $upload_dir . pathinfo($_FILES['comicfile']['tmp_name']);
    $filename = $_FILES['comicfile']['name'];
    //This is our size condition
    foreach ($_FILES['comicfile']['size'] as $filesize){
    $comicfile_size = $filesize;
    if ($comicfile_size > 100000000)
      echo "<font color=\"#FF0000\">Failed</font>: Your file is too large.";
    //This is our limit file type condition
    foreach ($_FILES['comicfile']['type'] as $filetype){
    $comicfile_type = $filetype;
      if ($comicfile_type =="text/php")
      echo "<font color=\"#FF0000\">Failed</font>: No PHP files.";
    //Here we check that $ok was not set to 0 by an error
    if ($ok==0)
    Echo "  Sorry your file was not uploaded";
    //If everything is ok we try to upload it
    foreach ($_FILES['comicfile']['error'] as $key => $error){
      if ($error == UPLOAD_ERR_OK) {
      $tmp_name = $_FILES['comicfile']['tmp_name'][$key];
      $name = $_FILES['comicfile']['name'][$key];
      move_uploaded_file($tmp_name, "images/$name");
    echo "<br />";
    echo "<a href=\"index.php\">Comic Index</a><br />";
    echo "<a href=\"http://rvb.allaroundhalo.org/index.php\">RvB Index</a><br />";
    echo "<a href=\"http://www.allaroundhalo.org/index.php\">AAH Index</a>";

  5. I've retrieved a multiple file upload code sample from php.net and extended/modified it to suit my needs (that uses arrays). For some reason, it uploads and moves the file from the temp directory to the folder I specified, but I get this error:

    Warning: basename() expects parameter 1 to be string, array given in...


    And here's the part of the code that I'm having trouble with.


    $upload_dir = "images/";
    $upload_file = $upload_dir . basename($_FILES['comicfile']['tmp_name']);
    $filename = $_FILES['comicfile']['name'];

    (I just put the PHP tags in to help others be able to read the code clearly)


    I've also tried pathinfo(), but to no avail. Can anybody help please?

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