Jump to content

laffin

Members
  • Posts

    1,200
  • Joined

  • Last visited

Everything posted by laffin

  1. exactly why it wont work otherwise. to get what group affilation a user belongs to, u need to pass both requirements. user_id and group_id SELECT * FROM Users WHERE Group_ID = '2' this just returns all users in group 2. so either you check each row to see if u find the users id or u put both in the query
  2. than use the date_default_timezone functions. to just affect that one function U wud do something like function addItem( $item ){ $oldtz=date_default_timezone_get(); date_default_timezone_set ('Etc/GMT-8'); // $date = date( "j M Y H:i", time() ); $date = date( "j M Y g:i a", time() ); date_default_timezone_set ($oldtz); $item['date'] = $date; $this->news[] = $item; } but to affect your whole script, place date_default_timezone_set at the beginning of your script
  3. if(!mysql_num_rows(mysql_query("SELECT * From Users WHERE id={$userid} and Group_id=2"))) { die('Restricted Page"); } ?> Admin Page
  4. from the table, its 26 fields (1 for each letter of the alphabet) randomize the alphabet, than you have a new code using strpos, you can verify the index
  5. Weighted Probability, isnt that simple. Weighted probablity, you assign a weight to each item. in how common it is <?php $items = array( array('lint',100), array('copper coin',75), array('silver coin',50), array('gold coin',10) ); $item_count=count($items); // Find the total weight of all items $total_weight=0; foreach($items as $val) { $total_weight+=$val[1]; } // add in percentage markers foreach($items as $key=>$val) { // we want to keep percentage markers as int // so multiplying the marker by 10,000, gives us 2 extra digits, a bit finer resolution $weight=(int)(($val[1]/$total_weight)*10000); $item_perc[]=$weight; $item_perc_index[$weight]=$key; } // sort our percentage markers sort($item_perc); // initialize our stat counter foreach($item_perc_index as $val) $stat[$val]=0; for($loop=0;$loop<500;$loop++) { $chance=rand(0,10000); // Check Against Item Percent Markers $marker=0; while($chance>$item_perc[$marker] && ($marker+1)<count($item_perc)) $marker++; // Get our item index from the marker $found=$item_perc_index[$item_perc[$marker]]; // Statistics $stat[$found]++; } // Display Found stats for each item header('Content-Type: text/plain'); echo "Loop of {$loop}\n"; foreach($stat as $key=>$val) { echo "{$items[$key][0]} found {$val} times (%". (($val/$loop)*100) .")\n"; } /* Output Loop of 500 lint found 335 times (%67) copper coin found 60 times (%12) silver coin found 83 times (%16.6) gold coin found 22 times (%4.4) */ ?>
  6. it really depends on your system You can use nl2br before insertion, so its ready to display, problem is that if u update the msg you have to process it to show original message after a SELECT, its in its orginal form, you have to make it ready for display, but makes updates easier
  7. Only problem I foresee in that is that you don't actually get the userid. without the userid to send to, ya end up doing 2 more queries. But I dont think you need the count, (unless for some displaty purposes before the actual msg sending) use 2 queries like <?php $fromid=7; $msg='Sample test'; $res=mysql_query("SELECT id FROM users WHERE NOT id={$fromid}"); while($arr=mysql_fetch_row($res)) { $to[]=$arr[0); } $count=count($to); foreach($to as $toid) { mysql_query('INSERT INTO msgs (fromid,toid,msg) VALUES({$fromid},{$toid},'". mysql_real_escape_string($msg) ."')"); } well that is off the top of my head. }
  8. if u use explode, than ABC, Hey There, What's Up? Wont work. either use strpos of preg_match
  9. You must be doing something wrong, cuz i get the right output <?php function delim_explode($delim,$string) { if(in_array($delim,array('/','\\','[',']','(',')'))) $delim="\\{$delim}"; $pattern="((?<=$delim).*?(?=$delim))+"; if(preg_match_all("/{$pattern}/",$string,$matches)) { $matches=$matches[1]; } else $matches=array(); return $matches; } function sasa_explode($delim,$string) { $out = explode($delim, $string); array_shift($out); array_pop($out); return($out); } header('Content-Type: text/plain'); var_dump(delim_explode('#','#username1#username2#')); var_dump(delim_explode('#','username1#usrname2#')); var_dump(delim_explode('#','#username#usrname2# wasup guys !')); var_dump(delim_explode('#','no delimeter')); var_dump(sasa_explode('#','#username1#username2#')); var_dump(sasa_explode('#','username1#usrname2#')); var_dump(sasa_explode('#','#username#usrname2# wasup guys !')); var_dump(sasa_explode('#','no delimeter')); ?> I do like sasa's method, simple
  10. if your using php date/time functions date_default_timezone_set if your using mysql date/time functions: putenv('TZ=EST5EDT'); use both if unsure/using both
  11. You got the column count wrong, you had an extra in their somewhere. instead of trying to figure out the code, just made a new routine, to do this It was quite a challenge trying to figure it out, but it looks like from your code that you already know the sub-delimiters of a column. so that made pretty easy work afterwards <?php $columns = 'VID|VENDOR|| > TID > SID|ISBN|COLUMN1|LAST|FIRST|SSID->|COLUMN2'; $delims = array(',','\t','|',' > ','->','~','/','\\',); $sdels= array( array(null,2), // apply to whole, seperate by delimeter '|' (2) array(3,3), // apply to column 3, delimter ' > ' (3) array(8,4) // apply to column 8, delimiter '->' (4) ); foreach($sdels as $dinfo) { if($dinfo[0]==null) { $cols=explode($delims[$dinfo[1]],$columns); } else { $cols[$dinfo[0]]=explode($delims[$dinfo[1]],$cols[$dinfo[0]]); } } header('Content-Type: text/plain'); var_dump($cols); $b = 'COL 0|COL 1|COL 2|COL 3 SUB 1 > COL 3 SUB 2 > COL 3 SUB 3|COL 4|COL 5|COL 6|COL 7|COL 8 SUB 1->COL 8 SUB 2|COL 9'; foreach($sdels as $dinfo) { if($dinfo[0]==null) { $vars=explode($delims[$dinfo[1]],$b); } else { $vars[$dinfo[0]]=explode($delims[$dinfo[1]],$vars[$dinfo[0]]); } } $idx=0; foreach($vars as $var) { if(is_string($var)) { $vals[$idx++]=$var; } else { foreach($var as $val) $vals[$idx++]=$val; } } var_dump($vals) ?>
  12. Easiest way, is use a gui interface (phpmyadmin/mysqlcc/mysql workbench). I prefer mysqlcc (but if used on remote server, you have to give your ip access to the db). Most will export the database schema as well as the entries
  13. This is an apache error, best bet is to start with the apache error log file. and see if you can gather more information. than check your php error log. Its kinda pointless, to change things when you dont know how you got the error.
  14. 1) You should not use $_REQUEST, as this can take values from $_POST/$_GET/$_COOKIE, if you use a form, use the proper $_POST. Using $_REQUEST just invites trouble 2) You never check the session value so a empty string is taken, if no $_POST is sent $strZipCode = isset($_POST['frmSearch']['zipcode'])?$_SESSION['zipcode']= mysql_real_escape_string($_POST['frmSearch']['zipcode']):(isset($_SESSION['zipcode'])?$_SESSION['zipcode']:''); check the POST, check the SESSION, otherwise, leave as ''
  15. I took it as if he's working with a file, rather than arrays. <?php $file=<<<EOT Notorious Fox Searchlight Pictures Dir., George Tillman Jr.; Cast, Jamal Woolard, Angela Bassett, Derek Luke, Antonique Smith, Anthony Mackie, Naturi Naughton, Sean Ringgold, Marc Jon Jefferies Paul Blart: Mall Cop Columbia Dir., Steve Carr; Cast, Kevin James, Jayma Mays, Shirley Knight EOT; file_put_contents('sample.lst',$file); $fr=fopen('sample.lst','rt'); $fw=fopen('sample.2.lst','wt'); while($line=fgets($fr)) { if(strlen(trim($line))) { fputs($fw,"Movie: {$line}"); fputs($fw,'Studio: '. fgets($fr)); fputs($fw,'Cast: '. fgets($fr)); } else { fputs($fw,$line); } } fclose($fr); fclose($fw); header('Content-Type: text/plain'); readfile('sample.2.lst'); unlink('sample.lst'); unlink('sample.2.lst'); ?>
  16. $valid=preg_match('/^[\w\x20_]+$/',$username); this is prolly the easiest way, regex via preg_match..... but I think I wud set up some more rules like like alpha 1st, and at a range of 3-20 characters, for some fields $valid=preg_match('/^[a-z][\w\x20_]{2,19}$/i',$username);
  17. uhm whats the difference in using a random generated password and a real password? instead of a password, just give them a link with a token and give it like 12 hr expiration period. but ta will have to create a new table of these tokens and expiration period. just keep it simple
  18. sounds like ya got the walmart brand, if u go to best buy, they got a selection of sharks sharks with laser eyes, land sharks, pet sharks (kid friendly, burglar chewed)
  19. u can also use : <pre> which is simpler to use imho
  20. By anychance is this php 5.3.0?
  21. intval has one meaning, makes a numeric into a integer. wheather it be a string/real number. the date function returns date information according to a format string Y - 4 digit year m - 2 digit month d - 2 digit day filemtime - returns a integer, representing the date, of the file last modified time so you add all them together, get files modified date, convert to a string in Ymd format (notice no - or /, which is for the next step), converting the string into an integer.
  22. Its would be much better preferred, if u used http://php.net/manual/en/ to look up functions you dont know offhand. Just because it provides so much more detail about the functions I used in the script. because general comments, doesnt mean you will understand the code any better. The script isnt that hard to figure out, once you know what functions it uses, and how it uses them
  23. problem code while ($ev = mysqli_fetch_array($chkEvent_res)) { $event_title = stripslashes($ev["event_title"])."<br/>"; } Reason: your reassigning $event_title so only the last event is shown. Solution: use concatenation $event_title .= stripslashes($ev["event_title"])."<br/>";
  24. Without a binary encryptor/decryptor, its kinda pointless. Binary as in php modules (.so or .dll) which are written in C/C++ Why is it pointless? well if your writing your encryptor in php, that means you have to have a decryptor for it, if its done in php, guess what? a quick rewrite and they got the code. Obfusciating is ok, but its still executable, a good programmer, with a good set of tools, may not reproduce the code exactly. But they will get the code. Best bet is to use those encryptors (Zend Gaurd), IonCube or whatever that your server can install (Zend Guard is popular, and many already have it installed).
  25. U should really consider using a db for hitcounters. but if its not a site that gets a lot of hits in first place, it shouldnt matter <?php $hitcounter='hitcounter.txt'; $ftime=intval(date('Ymd',filemtime($hitcounter))); $ctime=intval(date('Ymd')); $counter=intval(file_get_contents($hitcounter)); if($ctime>$ftime) { $fh=fopen('hitcounter.log','at'); fputs($fh,"{$ftime} - {$counter}\n"); fclose($fh); $counter=1; } else { $counter++; } file_put_contents($hitcounter,$counter); echo "Visits Today: {$counter}"; ?>
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.