[SOLVED] Random String Verification help

This is a discussion on "[SOLVED] Random String Verification help" within the PHP Forum section. This forum, and the thread "[SOLVED] Random String Verification help are both part of the Program Your Website category.



Go Back   Webforumz.com > Main Forums > Program Your Website > PHP Forum

Notices


Reply
 
LinkBack Thread Tools
  #1 (permalink)  
Old Mar 18th, 2008, 19:09
Junior Member
Join Date: Feb 2008
Location: England
Age: 21
Posts: 21
Thanks: 0
Thanked 0 Times in 0 Posts
[SOLVED] Random String Verification help

Hello. In a form I've made I have tried to create a random string variable that is displayed on the form and for the users to copy into another text box for comparison and validation, however it doesn't seem to work as it doesn't display anything in the table beyond the Verification Required: text.

Here is the Javascript function I am using to create the random string:

Code: Select all
function random_string($len=5, $str='')
{
   For($i=1; $i<=$len; $i++)
   {
      $ord=rand(48, 90);
      if((($ord >= 48) && ($ord <= 57)) || (($ord >= 65) && ($ord<= 90))) 
      {
         $str.=chr($ord);
      }
      else
      {
         $str.=random_string(1);
      }                                           
   }
   return $str;
}
Here is the section of the form where the random string gets placed:
Code: Select all
   <tr><td><span class="errmsg">* </span><span class="head4">Verify Registration <br />(Copy the text exactly):</span>
   </td><td><?php $rand_str=random_string(5);?> 
   <span class"head2"><?php echo $rand_str?></span> 
   <?php $_SESSION['Rand_str']= $rand_str?></td></tr>
   <tr><td></td><td width="300"><label><input type="text" maxlength="5" name="Verify"/></label> <?php unset($rand_str)?></td></tr>
Now I also get an error message saying: missing ) after formal parameters
function random_string($len=5, $str='')\n

Can anyone help?

Last edited by psycho wolvesbane; Mar 18th, 2008 at 19:11.
Reply With Quote

  #2 (permalink)  
Old Mar 18th, 2008, 22:01
CloudedVision's Avatar
Nerdy Moderator
Join Date: Feb 2008
Location: In My Own Little World
Age: 14
Posts: 942
Blog Entries: 8
Thanks: 2
Thanked 21 Times in 21 Posts
Send a message via AIM to CloudedVision Send a message via MSN to CloudedVision Send a message via Skype™ to CloudedVision
Re: Random String Verification help

Moved to PHP forum

Quote:
Here is the Javascript function I am using to create the random string:
It's PHP, not javascript, so i think thats where your error is coming from. Instead of using <script></script> use <?php ?> That'll make the server execute it as PHP.
__________________
echo "Take it easy, ".$CloudedVision;
.links { site: other-road-design; blog: only-nerds-allowed; project: resource-fish; organization: ARMIES6; }
<quote>&quot;I think it's wrong that only one company makes the game Monopoly&quot; - <name>Steven Wright</name></quote>
Last Blog Entry: More Cheat Sheets (Jul 12th, 2008)
Reply With Quote
  #3 (permalink)  
Old Mar 19th, 2008, 06:18
alexgeek's Avatar
Technical Administrator

SuperMember
Join Date: Jul 2007
Location: Webforumz 24/7
Age: 15
Posts: 3,772
Blog Entries: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to alexgeek
Re: Random String Verification help

It helps to put a space between code and the closing tags, instead of:
PHP: Select all

<?php $rand_str=random_string(5);?> 
<?php echo $rand_str?>
Use:
PHP: Select all

<?php $rand_str=random_string(5); ?> 
<?php echo $rand_str?>
Cloud is right though,this is not javascript so there error is probably caused by mixing html and php incorrectly.
Last Blog Entry: 3D Chess in your browser! (Mar 14th, 2008)
Reply With Quote
  #4 (permalink)  
Old Mar 19th, 2008, 09:57
Junior Member
Join Date: Feb 2008
Location: England
Age: 21
Posts: 21
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Random String Verification help

Quote:
Originally Posted by alexgeek View Post
It helps to put a space between code and the closing tags, instead of:
PHP: Select all

<?php $rand_str=random_string(5);?> 
<?php echo $rand_str?>
Use:
PHP: Select all

<?php $rand_str=random_string(5); ?> 
<?php echo $rand_str?>
Cloud is right though,this is not javascript so there error is probably caused by mixing html and php incorrectly.
I've never noticed any problem with not having spaces when it's a single variable being echo'ed. Anyway it worked fine once I moved it into some php tags. The place I got the original script wasn't very clear on if it was PHP or Javascript and since it mostly looked the same way as JS functions do I couldn't tell the difference. Thanks for the help!
Reply With Quote
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Extracting filename without extension from variable string. frankenscarf JavaScript Forum 3 Jan 11th, 2008 16:54
[SOLVED] Connection string for password protected databases alexgeek Classic ASP 6 Oct 31st, 2007 15:59
Random .swf on refresh jtyoungs JavaScript Forum 2 Sep 19th, 2007 12:48
random benbramz Classic ASP 5 Jul 18th, 2005 05:01
Image verification humair Classic ASP 4 Jul 21st, 2004 04:17


All times are GMT. The time now is 08:34.


Powered by vBulletin®
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC8
© 2003-2008 Webforumz.com : All Rights Reserved

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43