gamerx Posted August 26, 2009 Share Posted August 26, 2009 Hi guys, i am having this issue wheras php outputs this error: Notice: Uninitialized string offset: 36 in C:\Program Files\EasyPHP 3.0\www\register.php on line 73 now this is my code around line 73: $captchars = '0123456789abcdefghijklmnopqrstuvwxyz'; $captchalength = rand(3, 5); $characters = $captchars; //captcha string $captstring = ""; for ($p = 0; $p < $captchalength; $p++) { $captstring .= $characters[mt_rand(0, strlen($characters))]; } $captchatext = $captstring; i then have a captcha image generation scriptthat takes the variable "$captchatext" and makes it an image, now this error only happens at some times and takes one letter off the string, it can also happen twice and take 2 letters, kinda annoying thanks heaps Quote Link to comment Share on other sites More sharing options...
Mark Baker Posted August 26, 2009 Share Posted August 26, 2009 $captstring .= $characters[mt_rand(0, strlen($characters) - 1)]; Quote Link to comment Share on other sites More sharing options...
gamerx Posted August 26, 2009 Author Share Posted August 26, 2009 are you able to explain why i need to take one off it please? (this works perfectly btw thanks ) Quote Link to comment Share on other sites More sharing options...
trq Posted August 26, 2009 Share Posted August 26, 2009 Because string indexes (like arrays) start at 0. So, if a string is 10 chars in length, the last letter will be indexed as 9. Quote Link to comment Share on other sites More sharing options...
gamerx Posted August 26, 2009 Author Share Posted August 26, 2009 okay, thanks i understand now, i never throught of that before xD can you please make this resolved Quote Link to comment Share on other sites More sharing options...
trq Posted August 26, 2009 Share Posted August 26, 2009 You yourself need to mark it as resolved, the button is in the bottom left corner I believe. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.