[ask] bingung di imageantispam.php?

Discussion in 'Desain Web dan Programming' started by jojosketch, 6 Jan 2011.

Thread Status:
Not open for further replies.
  1. jojosketch

    jojosketch New Member

    Messages:
    2
    Likes Received:
    0
    Trophy Points:
    1
    all bro & sista...

    :confused: lagi bingung bgt nih...
    file imageantispam.php ku berikut ga berjalan sebagaimana mestinya.
    yg muncul di browser kek gini:

    [​IMG]

    setelah diisi kode yg sesuai random image, yg muncul di url kek gini:

    [​IMG]

    padahal filenya kek gini:

    <?php

    //Start session

    session_start();

    //karakter alpha numerik untuk kode
    $str = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';

    //mengenerate 5 karakter kode secara random, dg str-shuffle()
    $rand = substr(str_shuffle($str), 0, 5);

    //random background image min.1 max.3
    $no = rand(1,3);
    $image = imagecreatefromjpeg("./img/bg$no.jpg");

    $font = 5;
    $black = imagecolorallocate($image, 0, 0, 0);
    $y = (imagesy($image)-imagefontheight($font))/2;

    //menulis kode verifikasi di background
    imagestring($image, $font, 8, $y, $rand, $black);
    //hash hasil random, dan simpan di seesion
    $_SESSION['RandVal'] = md5($rand);

    header('Content-type image/jpeg');
    imagejpeg($image);
    imagedestroy($image);
    ?>

    <form action="<?$_SERVER['PHP_SELF']?>" method="post">

    <img src="imageantispam.php" border="1"> <br />
    Kode <input type="text" name="kode"> <br />
    <input type="submit" name="ok" value="value">
    </form>

    <?php
    //start session
    session_start();
    if(isset($_POST['ok']) && isset($_POST['kode'])) {

    $kode = trim($_POST['kode']);
    if(md5($kode) === $_SESSION['RandVal']) {
    echo 'OK, you are verified...';
    //Letakkan kode proses lain di sini
    } else {
    echo 'Sorry, invalid code.';
    }
    if(!isset($_SESSION['RandVal'])) {
    //re-generate id session
    if(function_exists('session_regenerate_id')) {
    session_regenerate_id(true);
    }
    }
    }
    ?>


    ------ mohon bgt bantuanny ni. Salahnya dimana ya?

    Trimskali. :o:o
     
  2. ngalam

    ngalam Apprentice 1.0

    Messages:
    285
    Likes Received:
    5
    Trophy Points:
    18
  3. dpnux

    dpnux Expert 1.0

    Messages:
    455
    Likes Received:
    28
    Trophy Points:
    28
    Sederhananya, mas membuat file gambar dan di campur dengan HTML. Pisahkan file di atas menjadi per masing - masing tugas:
    1. Untuk membentuk session dan captcha (mycaptcha.php)
    2. Untuk menampilkan gambar captcha (form.php)

    dalam bentuk di atas, pemanggilan untuk file gambar bisa dilakukan dengan memasukan

    Code:
    <img src="mycaptcha.php" alt="captcha">
    
    selamat mencoba :)
     
  4. jojosketch

    jojosketch New Member

    Messages:
    2
    Likes Received:
    0
    Trophy Points:
    1
    thank you

    :) thank you replynya mas2.
     
Loading...
Thread Status:
Not open for further replies.

Share This Page

Loading...