Jump to content

Tandem

Members
  • Posts

    251
  • Joined

  • Last visited

    Never

Posts posted by Tandem

  1. Just out of interest, I was wondering if anyone knows of any alternatives to the image using captcha's?

    I have a form on my website, where the more a person submits a form the more credits they get for there account. They can only submit it every 2 minutes, but i had to introduce a captcha to stop people scripting and auto-reloading.

    I was thinking of a system where every 5-10 minutes, instead of the form, a checkbox appears, and they have to check it and submit that before they can do the form, but if any of the post data is being sent when it isn't needed, such as would be done by an auto-reload, then the form doesn't process. But a could scripter could get around it quite easily however.

    Anyway, yeah. As the first question says, anyone know any alternatives to captchas that display an image that you have to write into the box etc?
  2. [code]<?php
    ob_start();
    header('Content-type: image/png');
    header('Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0');
    header('Pragma: no-cache');

    $img = array();

    //////////
    // Image settings...
    //////////
    # Image width in pixels:
    $img['width'] = 65;
    # Image height in pixels:
    $img['height'] = 30;

    # Use TTF?
    $img['use_ttf'] = true;
    # Link to image true type font (only if above value is true):
    $img['ttf_font'] = "verdana";
    # TTF pt size?
    $img['ttf_size'] = 12;
    # Not using TTF? Still need a font size. (1-5)
    $img['normal_font_size'] = 4;

    # Image handle:
    $img['handle'] = imagecreatetruecolor($img['width'],
    $img['height']);

    //////////
    // Colors...
    //////////
    # Black:
    $colors['black'] = imagecolorallocate($img['handle'],
    0, 0, 0);
    # White:
    $colors['white'] = imagecolorallocate($img['handle'],
    255, 255,
    255);
    # Gray:
    $colors['gray'] = imagecolorallocate($img['handle'],
    (255 / 2), (255 / 2),
    (255 / 2));
    # Red:
    $colors['red'] = imagecolorallocate($img['handle'],
    255, 0, 0);
    # Transparent:
    $colors['transparent'] = imagecolorallocate
    ($img['handle'], 1, 1, 1);
    $colors['transparent'] = imagecolortransparent
    ($img['handle'], $colors['transparent']);

    //////////
    // Time to get drawing!
    //////////
    # Background:
    imagefilledrectangle($img['handle'], 0, 0,
    $img['width'], $img['width'], $colors['black']);
    # Left border:
    imageline($img['handle'], 0, 0, 0,
    $img['height'], $colors['gray']);
    # Top border:
    imageline($img['handle'], 0, 0,
    $img['width'], 0, $colors['gray']);
    # Bottom border:
    imageline($img['handle'], 0, $img['height'] - 1,
    $img['width'], $img['height'] - 1, $colors['gray']);
    # Right border:
    imageline($img['handle'], $img['width'] - 1, 0,
    $img['width'] - 1, $img['height'] - 1, $colors['gray']);

    //////////
    // Create the string and draw it.
    //////////
    $img['random_string'] =
    strtoupper(substr(md5(uniqid(rand(),true)),0,6));

    if($img['use_ttf'] ==
    true && file_exists($img['ttf_font'].".ttf"))
    {
    $img['random_angle'] = rand(-45/4, 45/4);
    imagettftext($img['handle'],$img['ttf_size'],$img['random_angle'],
    (($img['width'] / 2) - (imagefontwidth($img['ttf_font'])
    * strlen($img['random_string']))) + 2,($img['height'] / 2)
    + 2,$colors['gray'],$img['ttf_font'], $img['random_string']);
    imagettftext($img['handle'],$img['ttf_size'],
    $img['random_angle'],($img['width'] / 2) -
    (imagefontwidth($img['ttf_font'])
    * strlen($img['random_string'])),$img['height'] / 2,
    $colors['white'],$img['ttf_font'],$img['random_string']);  
    } else {
    imagestring($img['handle'],$img['normal_font_size'],(
    $img['width'] / 2) - $img['normal_font_size']
    * strlen($img['random_string']),$img['height'] /
    2.5,$img['random_string'],$colors['white']);
    }

    //////////
    // Finish up...
    //////////
    imagepng($img['handle']);
    imagedestroy($img['handle']);
    ?>[/code]
    Just save the code into a new file, and then use:

    <img src="filename.php">

    Should work.

    Note: It produces an alphanumeric string, so you may need to change it to suit your needs.
  3. Is it possible to get the HTML code of a remote page into a variable? Or is it only the textual output that you can get?

    I've used file_get_contents() before to get the contents of remote pages but i've only ever used it for pages with only text in them

    Thanks in advance for any replies.
  4. The problem with that is that i echo some other messages to go at the top of the included page if the validation is successful.

    I don't think it is possible for me to keep the message due to the structure of my script, was just asking on the off chance that there was a magic function that would solve my problems :P

    Thanks for the replies.
  5. Sorry, it's not as simple as that.

    The original echo needs to be done before the validation begins, but if the validation is successful then i include a different page (can't use headers in this instance) and exit the script before anything else but the text is output, but then i am left with an obscure output at the top of the included page. I'm asking if there is any sort of function or way that stops anything that has already been told to output, from actually being output so that i'm not left with the obscure message at the top of the included page.
  6. Is there a way to stop things that you've already told php to output from actually being output?

    For example if i needed to echo something out before a form validation process, but under certain results of the validation i no longer want that to be echoed at the beginning, is there a way of making it not be echoed? Sort of like making your script not echo things that you have already told php to echo further up the script.

    Sorry if that makes no sense but i'm having trouble finding explaining it properly.

    Thanks in advance for any replies.
  7. Quick question about arrays that i'm sure i've done lots of times but can't test it right now.

    If i have an array full or values, and then i set the array to false, would it empty the entire array?

    For example:
    [code]
    $blah[0] = 1;
    $blah[1] = 9;
    $blah[2] = 4;
    $blah[3] = 45;

    $blah = false;
    [/code]

    Thanks in advance.
  8. I'm having some problems trying to use PEAR packages. Whenever i try to use anything from the pear directory i get an error about an open_basedir restriction.

    Here is the error:
    Warning: require_once() [function.require-once]: open_basedir restriction in effect. File(/HTML/BBCodeParser.php) is not within the allowed path(s): (/tmp:/home/***) in /home/***/testbb.php on line 7

    The pear directory is one of my include paths so it's no that.

    I am the root user so i have access to everything, could anyone suggest anything i could try to get it to work?

    Thanks in advance.
  9. Another thing, if $rec_num is more than 0 you don't need the further check. Try this:

    [code]<?php session_start(); session_register("session");
    error_reporting(E_ALL);
    ?>

    <?php require("includes/connect/members.php"); ?>

    <?php
    $username = $_POST['username'];
    $password = md5($_POST['password']);
    $rec_check = mysql_query("SELECT * FROM profile WHERE userid='$username' AND password = '$password'");
    $rec_num = mysql_numrows($rec_check);
    if($rec_num > 0)  {
        $_SESSION['id']=session_id();
        $_SESSION['username']=$username;
        echo "<meta http-equiv='refresh' content='0;url(http://www.eliteguards.us/index.php)'>";
        header("Location: index.php");
    }
    else  {
    session_unset();
        echo "<meta http-equiv='refresh' content='0;url(http://www.eliteguards.us/login_false.php'>";
        header("Location: login_false.php");
    }
    ?>[/code]

    I also set error reporting to E_ALL so you should get some errors if something is wrong.
  10. That code is defining functions, not calling them. And since those functions are already reserved by php i don't think that can be done anyway.

    Do this:

    [code]$conn = mysql_connect("localhost", "user", "password") or die(mysql_error());
    mysql_select_db('db_name', $conn) or die(mysql_error());[/code]

    but of course replace the information with your own.
  11. You don't need quotes for the number, and parentheses for the include.

    [code]<?php
    if ($result == 1){
    include "result.php";
    }
    ?>
      <a href="<? echo $PHP_SELF?>?result=1">Click here to see page 2[/url][/code]

    There is nothing "hackable" about it though.
×
×
  • 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.