Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    Regular Coder
    Join Date
    Aug 2005
    Posts
    279
    Thanks
    0
    Thanked 0 Times in 0 Posts

    javascript and php

    Hi guys, is there a way I can making javascript and php mixed together? I could not get the code below to work at all.

    PHP Code:
    <script>
    var rand_value = document.entry.random.value;
        rand_value = <?php $rand_value;
        
    $img_code md5($rand_value);
        if (
    $img_code != $_SESSION['image_random_value'])?>
        {
            alert("Wrong Image Code!")
            entry.random.focus();
            return false;
        }
    </script>

  • #2
    Master Coder
    Join Date
    Jun 2003
    Location
    Cottage Grove, Minnesota
    Posts
    9,497
    Thanks
    8
    Thanked 1,089 Times in 1,080 Posts
    Try it now ... by moving the closing PHP ?>
    and an echo ... and a few other small changes.

    <script>
    var rand_value = document.entry.random.value;
    rand_value = <?=$rand_value?>;
    <?php
    $img_code = md5($rand_value);
    if ($img_code != $_SESSION['image_random_value'])
    {
    echo"
    alert(\"Wrong Image Code!\")
    entry.random.focus();
    return false;
    ";
    }
    ?>
    </script>


    .

  • #3
    Regular Coder
    Join Date
    Aug 2005
    Posts
    279
    Thanks
    0
    Thanked 0 Times in 0 Posts
    PHP Code:
    var rand_value = document.entry.random.value;
        rand_value = <?=$rand_value?>;
        <?php
        
    //session_start();
        
    $img_code md5($rand_value);
        if (
    $img_code != $_SESSION['image_random_value'])
        {
        echo
    "alert(\"Wrong Image Code!\")
             entry.random.focus();
             return false;"
    ;
        }
        
    ?>
    Still not working, the problem seems to be this line rand_value = <?=$rand_value?>;

    When I comment out it, my code executed but always gave me "wrong image code" error msg even though I typed in correct one. I tried to remove the "=" sign from it rand_value <?=$rand_value?>; or rand_value <?=$rand_value?>; still is not working.

  • #4
    Regular Coder
    Join Date
    Aug 2005
    Posts
    279
    Thanks
    0
    Thanked 0 Times in 0 Posts
    hello?

  • #5
    Regular Coder
    Join Date
    May 2006
    Location
    Wales
    Posts
    820
    Thanks
    1
    Thanked 82 Times in 79 Posts
    Tried <?php echo $rand_value; ?> ?


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •