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 Link to comment https://forums.phpfreaks.com/topic/171937-solved-uninitialized-string-offset-issue/ 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)]; Link to comment https://forums.phpfreaks.com/topic/171937-solved-uninitialized-string-offset-issue/#findComment-906603 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 ) Link to comment https://forums.phpfreaks.com/topic/171937-solved-uninitialized-string-offset-issue/#findComment-906605 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. Link to comment https://forums.phpfreaks.com/topic/171937-solved-uninitialized-string-offset-issue/#findComment-906607 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 Link to comment https://forums.phpfreaks.com/topic/171937-solved-uninitialized-string-offset-issue/#findComment-906608 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. Link to comment https://forums.phpfreaks.com/topic/171937-solved-uninitialized-string-offset-issue/#findComment-906612 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.