laffin
Members-
Posts
1,200 -
Joined
-
Last visited
Everything posted by laffin
-
U shud look at using BCC in yer emails instead of emailing everyone individually. initializer code (before yer loop) $to = ""; $nmax = 100; // Max recipients per message $nthis = 0; $ntotal = 0; $cbcc=array(); $bbcc=array(); List builder (in yer loop) $cbcc[]=$selectedig->email; ++$nthis; ++$ntotal; if ($nthis == $nmax) { $bbcc[]=$cbcc; $cbcc=array(); $nthis=0; } now $bbcc contains batches of emails to send after the loop we mail everything $i=0; $errors=array(); foreach($bbcc as $bccl) { $i++; $bcc = implode(',',$bccl); $res = mail("Multiple recipients <$strFrom>",$subject,$message,"From:$strFrom\r\nReply-to: $strFrom\r\nBcc: $bcc\r\nContent-type: text/html; charset=us-ascii", "[email protected]"); if($res==false) { $errors[$i]=count($bccl); } $hm=array_sum($errors); echo number_format($ntotal-$hm). " of $ntotal emals sent."; now ya have 100 emails going out per mail usage, I dun think ya shud encounter the problem again well until ya hit (50*100=5000) distribution list
-
shud mention it shud be used on the line $wallet[] = number_format($balance);
-
Arrays work comment[' . $row['id'] .']" so that the id is stored with the comment $comments = $_REQUEST['comment']; if(isset($comments[$id])) $comment=$comments[$id]; else $comment='';
-
Usually php scripts dun have permissions to create files in a folder. Create an empty file, and allow world read/write access
-
sumfin looks fishy... maye yer infecting $i variable near the end loop. the important pieces of the left/right conditional are there, but the $i=0 right before looks like ya just threw it in, without the loop block
-
Exactly Might be a bit more code for small stuff, but when ya got forms with 10+ inputs and half are required, it just makes validating so much easier
-
You may want to look at other event calanders already out there like WebCalendar
-
there is no real need to encrypt the sessions tho, unless u give or set them from user input. Sessions main PRO is that it's server side, meaning the user dusn have access to these variables. Unlike cookies, where a user can alter/view the cookie themselves. It's the implementation of authenticating the user, which shud be looked at. I store a unique key in a cookie (md5 of some info stored in sessions) if the cookie exists, than i compare it with the md5 of the sessions, otherwise i destroy the session and cookie. $_COOKIE['key'] = md5($_SESSION['username'] . $_SESSION['user_ip']) note: using the user's ip as part of the key, so the key can only be used by one machine location. also use a expiry for session length Which you can reset on reauthentication.
-
use a session with the timeout period Upon successful login $_SESSION['timeout']=time()+15*60; // 15 minute timeout than when u load a page check this timeout if($_SESSION['timeout']<time()) { header("Location: login.php"); // If user timed out, send em back to loginpage session_destroy(); // Also remove his session variables; // remove any other Cookies or settings exit; } $_SESSION['timeout']=time()+15*60; // Give User another 15 minutes
-
Replace whitespaces with a comma only for the first few occurances.
laffin replied to l_kris06's topic in PHP Coding Help
well if ya just need 9 commas <?php $str='SIP25071 O 4.4 43 4 ERG 02/28/2008 Mike cisco2000 ptime.baseval header incorrect chk in'; $rpl=preg_replace('@([^\s]+)(\s+)@','$1,',$str,9); echo "$str<br>$rpl"; //Output //SIP25071 O 4.4 43 4 ERG 02/28/2008 Mike cisco2000 ptime.baseval header incorrect chk in //SIP25071,O,4.4,43,4,ERG,02/28/2008,Mike,cisco2000,ptime.baseval header incorrect chk in ?> -
Congrats And thanks for sharing code, pretty shure others will find it useful
-
{ } only needed when ya have more than 1 statement (a block) of code
-
if(!$siteonline && !$userloggedin) header("Location: http://my.site.com/oopsie.html"); a multiconditional works as well
-
depends how u store the switching of site on/off line.. easiest is prollly mysql, using a table for yer vars... CREATE TABLE `vars` ( `name` varchar(32) NOT NULL default '', `i` int(10) NOT NULL default '0', `u` int(10) unsigned NOT NULL default '0', `f` double NOT NULL default '0', `s` varchar(100) NOT NULL default '', PRIMARY KEY (`name`) ) ENGINE=MyISAM; than ya can add a switching system in the admin page on login, ya want to check this value, if admin or other special case users allow it, otherwise deny the user.
-
Anytime Good luck in yer coding
-
<parse $var> = eval($var);
-
Replace whitespaces with a comma only for the first few occurances.
laffin replied to l_kris06's topic in PHP Coding Help
Thats a lot more complex, what u have to figure out is a pattern system. from the looks of it, u will probably have to create a phrase list, to be kept intact. and add commas everywhere except within a phrase list or look closely at yer output and look for any type of pattern between the values, or the values sequence. -
<?php function load_vars() { return array('arg1' => 'Arg 1', 'arg2' => 'Arg 2'); } function my_sub() { extract(load_vars()); echo "$arg1<br>$arg2"; } my_sub(); ?>
-
why do u have quotes around the array keys? which are obviously a variable?
-
Replace whitespaces with a comma only for the first few occurances.
laffin replied to l_kris06's topic in PHP Coding Help
Looks like the common denominator is that the Whitespaces are between CAPS ALPHANUMS. as stated preg_replace is what ya looking for but since we know the pattern it makes it very simple <?php $str='1 A AB 2 ABC 3 ABCD 4 5 The whitespace inbetween these must not be replaced with a comma'; $rpl=preg_replace('@([A-Z0-9]+)( )@','$1,',$str); echo "$str<br>$rpl"; ?> // Output: //1 A AB 2 ABC 3 ABCD 4 5 The whitespace inbetween these must not be replaced with a comma //1,A,AB,2,ABC,3,ABCD,4,5,The whitespace inbetween these must not be replaced with a comma Taa-Daa -
I prefer sumthing like <?php $reqfields=array('username','email','password'); // Required fields $urqfields=array('formid'); // Unecessary fields foreach($_POST as $key => $val) // Grab all fields except Unecessary fields { if(array_search($urqfields,$key)===false) $args[$key]="$key=". urlencode($val); } $errors=0; foreach($reqfields as $val) // Check Required Fields { if(!isset(args[$key])) { echo "Required field ($val) missing"; $errors++; } } if($errors) exit; $arg=implode('&',$args); // Build our args line ?> using something like this avoids the possible malformed url of http://my.site.com/script.php?&arg1=x&arg2=y when building it
-
just different ways accomplishing the same thing. It's not a big issue really 1 or 10 forms, ya need an identifier of which form was sent In this sample using a hidden field to progress thru the forms <?php if($_SERVER['REQUEST_METHOD']=='POST') // Form was posted { $formid=0+$_POST['formid']; switch($formid) { case '2': // Process 2nd form $email=$_POST['email']; if(empty($email)) $showform=2 else $showform=3; case '1': // Process 1st form $username=$_POST['name']; if(empty($username)) $showform=1; elseif($showform!=3) $showform=2; // Did we process form 2 already? break; default: // Unknown form info Show 1st Form $showform=1; } } else $showform=1; // Display different forms if($showform==1) { ?> <FORM METHOD='POST'> <INPUT TYPE='HIDDEN' name='formid' value='1'> Username: <INPUT TYPE="TEXT" name='name' <?= (!empty($username)?"value=\"$username\"":'')?>><BR> <INPUT TYPE='SUBMIT'> </FORM> <? } elseif($showform=='2') { ?> <FORM METHOD='POST'> <INPUT TYPE='HIDDEN' name='formid' value='2'> <INPUT TYPE='HIDDEN' name='username' value='<?=$username?>'> Email: <INPUT TYPE="TEXT" name='email' <?= (!empty($email)?"value=\"$email\"":'')?>><BR> <INPUT TYPE='SUBMIT'> </FORM> <? } else { // Form 1 & 2 Processed already ?> <H1>Hello <?=$username?>,</H1><br> I see yer email is <?=$email?> <? } ?>
-
<?php if(isset($_POST['submit'])) { $items = array(); $itemcount = count($_POST['item']); if($itemcount >2) $itemcount=2; if($itemcount) { for($i=0;$i<$itemcount;$i++) $items[]=$_POST['item'][$i]; } if($ic=count($items)) { echo "$ic items<BR>"; foreach($items as $key => $value) echo "$key) $value<BR>"; } else echo "No Items<BR>"; } ?> <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post"> <input type="checkbox" name="item[]" value="1" /> lamp<br /> <input type="checkbox" name="item[]" value="2" /> chair<br /> <input type="checkbox" name="item[]" value="3" /> foobar<br /> <input type="submit" name="submit" value="submit" /> </form> Add some debugging info to get a better idea of whats going on the $items array will hold 0,1 or 2 items. the item id shud come from the value of a specific checkbox (not the name).