Jump to content

md5 ->hash issue


cirma

Recommended Posts

Hi,

 

I'm trying to make a form where a surfer can enter a list of words in a text box, then the script spits out the words and their corresponding md5 value in a table.  But I end up with it just doing the first letter of the first word they entered.

 

Here's my code:

 

<?php 
$data=''; 
if (isset($_POST['data']) && strlen($_POST['data'])>0) { 
    $data=$_POST['data']; 
} 
if (isset($_POST['submit'])) 
{ 
    if (strlen($data)>0) 
    { 
        
        $newarr = explode("\n\r", $data);
        print '<b>Results</b><br><br>'; 
        print '<table width = "800" columns = "2" border = "2">'; 
        foreach($newarr as $line) 
        { 
            print '<tr>';
            print '<td>';
            print $newarr{$line};
            print '</td>';
            print '<td>';
            print md5($newarr{$line});
            print '</td>';
            print '</tr>';
            } 
        
        print '</table><br><br>'; 
    } 
    else 
        print '<b>You need to enter some data</b><br><br>'; 
} 
?> 
<b>Enter data here</b><br><br> 
<form method="POST" action="<?php echo $_SERVER['PHP_SELF']; ?>"> 
<textarea name="data" rows="15" cols="100"> 
<?php echo $data; ?> 
</textarea> 
<input type="submit" value="Submit" name="submit"> 
</form> 

 

I've tried diff combinations of \n\r but I think what's happening is I'm not getting to the next line?  Any ideas?

 

thanks

Link to comment
Share on other sites

<?php

foreach($newarr as $line) 
{
    print '<tr>';
    print '<td>';
    print $line;
    print '</td>';
    print '<td>';
    print md5($line);
    print '</td>';
    print '</tr>';
}

?>

Link to comment
Share on other sites

Thanks thorpe...but that gives me the md5 for everything they put in the box.  I want to md5 each individual line in the box.

 

???

 

edit: so they enter like:

 

word1

blah

meh

 

and then the script spits out

 

word1 fkgjdfkgjf98454b

blah  rRmfgTlfm459839t

meh  j453fjvBEmtltjk

 

etc.

Link to comment
Share on other sites

Try this. I would do it this way.

<?php 
$data=''; 
if (isset($_POST['data']) && strlen($_POST['data'])>0) { 
    $data=$_POST['data']; 
} 
if (isset($_POST['submit'])) 
{ 
    if (strlen($data)>0) 
    { 
        
        $newarr = explode("\r", trim($data));
        print '<b>Results</b><br><br>'; 
        print '<table width = "800" columns = "2" border = "2">'; 
        for($i=0;$i<count($newarr);$i++)
        { 
            print '<tr>';
            print '<td>';
            print $newarr[$i];
            print '</td>';
            print '<td>';
            print md5($newarr[$i]);
            print '</td>';
            print '</tr>';
            } 
        
        print '</table><br><br>'; 
    } 
    else 
        print '<b>You need to enter some data</b><br><br>'; 
} 
?> 
<b>Enter data here</b><br><br> 
<form method="POST" action="<?php echo $_SERVER['PHP_SELF']; ?>"> 
<textarea name="data" rows="15" cols="100">
</textarea> 
<input type="submit" value="Submit" name="submit"> 
</form> 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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