Cutting out redundancy

2012-10-07  Source: Original Site  Category:PHP  Views:0 

Advertisement

Alright, I've got this code right here:

<?php
session_start();
$str1 = str_shuffle(md5(microtime() * mktime()));
sleep(.5);
$str2 = str_shuffle(md5(microtime() * mktime()));
$str = substr($str1,0,5);
$xtra1 = substr($str2,0,5);
$xtra2 = substr($str2,5,10);
$xtra3 = substr($str2,10,15);
$xtra4 = substr($str2,15,20);
$xtra5 = substr($str2,20,25);
$captcha = imagecreatefrompng("./captcha.png");
$color = imagecolorallocate($captcha,255,0,0);
$linecolor = imagecolorallocate($captcha,rand(0,255),rand(0,255),rand(0,255));
$textcolor = imagecolorallocatealpha($captcha,0,0,0,100);
imageline($captcha,rand(0,50),rand(0,100),rand(0,200),rand(0,200),$linecolor);
imageline($captcha,rand(0,50),rand(0,100),rand(0,200),rand(0,200),$linecolor);
imageline($captcha,rand(0,50),rand(0,100),rand(0,200),rand(0,200),$linecolor);
imageline($captcha,rand(0,50),rand(0,100),rand(0,200),rand(0,200),$linecolor);
imageline($captcha,rand(0,50),rand(0,100),rand(0,200),rand(0,200),$linecolor);
imageline($captcha,rand(0,50),rand(0,100),rand(0,200),rand(0,200),$linecolor);
imageline($captcha,rand(50,200),rand(0,100),rand(50,200),rand(80,200),$linecolor);
imageline($captcha,rand(50,250),rand(0,100),rand(0,200),rand(50,200),$linecolor);
imageline($captcha,rand(70,150),rand(0,100),rand(50,200),rand(0,200),$linecolor);
imageline($captcha,rand(20,150),rand(0,100),rand(20,150),rand(35,200),$linecolor);
imageline($captcha,rand(80,200),rand(0,100),rand(50,200),rand(85,200),$linecolor);
imageline($captcha,rand(0,50),rand(0,100),rand(0,200),rand(0,200),$linecolor);
imagestring($captcha,3,rand(0,100),rand(0,50),$str,$color);
imagestring($captcha,rand(1,5),rand(0,200),rand(0,70),$xtra1,$textcolor);
imagestring($captcha,rand(1,5),rand(0,200),rand(0,70),$xtra2,$textcolor);
imagestring($captcha,rand(1,5),rand(0,200),rand(0,70),$xtra3,$textcolor);
imagestring($captcha,rand(1,5),rand(0,200),rand(0,70),$xtra4,$textcolor);
imagestring($captcha,rand(1,5),rand(0,200),rand(0,70),$xtra5,$textcolor);
$_SESSION['str'] = md5($str);
header("Content-type: image/png");
imagepng($captcha);
?>

I've got no problems with the script (CAPTCHA), it's fine. I'm in the middle of modifying it anyways, but what I was wanting help with was using a loop to cut out some redundant lines like these:

imagestring($captcha,rand(1,5),rand(0,200),rand(0,70),$xtra1,$textcolor);
imagestring($captcha,rand(1,5),rand(0,200),rand(0,70),$xtra2,$textcolor);
imagestring($captcha,rand(1,5),rand(0,200),rand(0,70),$xtra3,$textcolor);
imagestring($captcha,rand(1,5),rand(0,200),rand(0,70),$xtra4,$textcolor);
imagestring($captcha,rand(1,5),rand(0,200),rand(0,70),$xtra5,$textcolor);

And these:

imageline($captcha,rand(0,50),rand(0,100),rand(0,200),rand(0,200),$linecolor);
imageline($captcha,rand(0,50),rand(0,100),rand(0,200),rand(0,200),$linecolor);
imageline($captcha,rand(0,50),rand(0,100),rand(0,200),rand(0,200),$linecolor);
imageline($captcha,rand(0,50),rand(0,100),rand(0,200),rand(0,200),$linecolor);
imageline($captcha,rand(0,50),rand(0,100),rand(0,200),rand(0,200),$linecolor);
imageline($captcha,rand(0,50),rand(0,100),rand(0,200),rand(0,200),$linecolor);

How could I use a loop to cut those out and make it look simpler? I would really appreciate it if someone could help me :D :p.

Related articles
  • Cutting out redundancy 2012-10-07

    Alright, I've got this code right here: <?php session_start(); $str1 = str_shuffle(md5(microtime() * mktime())); sleep(.5); $str2 = str_shuffle(md5(microtime() * mktime())); $str = substr($str1,0,5); $xtra1 = substr($str2,0,5); $xtra2 = substr($st

  • Ubuntu Sound cuts out occassionally..issue with pulseaudio? 2012-01-06

    Whether it be youtube, or just using banshee, it seems that my audio once in a while, cuts out for a half of a second. Happened after I downloaded a few updates, and I notice the sound cuts on my integrated monitor speakers, but find them more appare

  • Cannot install Ubuntu Studio 8.04 due to USB cutting out 2012-01-18

    I'm trying to install Ubuntu Studio 8.04 because I want to give Cinelerra a shot, and as far as I know, Ubuntu is one of the "easier" to use linux distributions. However, I'm having a problem. When I select "install" from the DVD once its booted up,

  • Ubuntu Maverick - wireless cuts out intermittently - Broadcom 2012-01-21

    My first forum post, but not my first go-round with Ubuntu... Here's some pertinent info: My system Gateway MX6027 Broadcom wireless card BCM 4311 Installed Maverick Meerkat yesterday My system worked like a charm under Karmic, no problems at all. I

  • Crt Monitor Keeps Cutting Out 2012-02-14

    my brother has a packard bell CRT monitor that is only about 6 months old for 'what i can see' no apparent reason. the problem with this monitor is that about a week ago it started cutting out (i mean totally powering off) when he tries to do anythin

  • Ubuntu Why does my internet keep cutting out? 2012-03-16

    im very inexperienced with computers....but my Internet lately cuts out and stops working towards either the end of the day or the end of the month...... i know i havent given much detail but anyone know maybe why its happening? im using firefox on u

  • Ubuntu HOWTO: Auto transcode MYTHTV recorded shows to DVD, XVID or DIVX cutting out the co 2012-03-19

    PLEASE READ POSTS 1 thru 3 to fully! How to auto transcode MYTHTV recorded shows to DVD, XVID or DIVX cutting out the commercials. This how to is assuming that MYTHTV and MYTHWEB are already installed and running correctly. Step 1: Install dependenci

  • Ubuntu Sound Cuts out in Minecraft 2012-04-21

    In Minecraft multiplayer, I have been having an issue with the sound cutting out after a period of time. I have not yet seen this in singleplayer. Here's the output: java -Xmx1024M -Xms1024M -jar minecraft.jar (<unknown>:6778): IBUS-WARNING **:

  • Ubuntu Sound get choppy and cuts out in full-screen games 2012-04-22

    I am runny Karmic on an x64 machine The sounds works perfectly in gnome, but when I run full screen applications like openarena or ufo alien invasion the sound is very choppy and then it cuts out completely. When I try to exit the game the system doe

  • Ubuntu Wireless ICS cutting out 2012-04-26

    I'm using Ubuntu 9.10 64 bit I followed this InternetConnectionSharing (https://help.ubuntu.com/community/Internet/ConnectionSharing) guide, but made a couple of changes to share through my wireless adapter. It works well, except that the Internet co

  • Sounds keeps cutting out in Ubuntu 9.10 2012-04-28

    Ok so whenever I go to play audio online like Youtube or Pandora for instance my audio will cut out after 2-5 minutes of playing. I need to know exactly how to fix this. Now I will say I am quite the noob to Ubuntu and I have the Karmac version as we

  • Ubuntu Wireless cuts out under heavy load, don't want to have to switch back to vista 2012-06-25

    Ok, I am relatively new to linux. Im a fast learner and have been power learning for the last month. However the one problem that keeps plaguing me is that my wireless cuts out on heavy loads such as streaming video or downloading a file. This is my

  • Ubuntu My audio keeps cutting out! 2012-06-28

    Help me please. Whenever I use youtube or a video site, and like watch 2-3 videos my audio cuts out completely for the whole computer. I have a crap computer so I dont know what I use. Please help me with whatever you got! :D

  • Ubuntu Wireless Cuts Out While Using Higher Bandiwidth 2012-07-22

    I connect to the network wirelessly through a college campus AP. I've been playing Tremulous for a couple months now and it's been working fine. Now, suddenly I lose connection while playing. I'm pretty sure the campus hasn't changed anything on thei

  • Ubuntu Cut out animation 2012-08-14

    Hello, I want to make cut out animations. Is Synfig Studio my best option, or would I be better learning to animate in Blender? Are there any other programs that are very well developed? Also, what is the best program to compile my pngs into a film?

  • Ubuntu Bad sound and speakers dont cut out. 2012-08-27

    Getting everything set up just right on my laptop running Hardy. Just a couple of annoying things that I havre to go back to windows for though. Main thing is playng back any forem of recorded sound, and the headphones not cutting out the speaker sou

  • Sound frequently cuts out 2012-08-28

    I'm running Suse 10.0 with integrated sound its a Intel 865PE. When I'm using amaroK, vlc or xmms to play either mp3's or dvd's the sound tends to cut out every 5-7 minutes then comes back in after several minutes. I've been running the system for ab

  • Ubuntu Broadcom Wireless keeps cutting out. 2012-09-15

    I'm running Ubuntu on my C712nr, and I just reformatted again on Hardy. I'm using the drivers installed by the OS for the Broadcom wireless, and I've noticed that my internet connection has been randomly cutting out. I'm on a stable wireless signal,

  • Ubuntu Sound cuts out on internet radio 2012-09-20

    Every time I listen to kiss online radio it cuts out every ten mins or so. I have tried both FireFox and Opera but the same thing happens in both. I have to stop then press play on the radio to get the sound back. Listening to mp3s seems to be fine w

  • need help cutting out image 2012-10-15

    I'm new here and I wanted to ask a question. How do I cut out an image in PS? I have 5.0. I have a pic of my dog I want to cut out and put on new background. I have tried the magic tool, but can't get it to work and then I did the lasso, tool and can