Viser koder av ZtigO

Det ble i alt funnet 14 koder i databasen

Sorter etter:

Legg inn en helt ny kode

Valgmuligheter

ZtigO sendte inn denne php-koden 01.12.2011 kl. 11:14.

  1. <?php
  2. /**
  3.  * @author Stig M. Halvorsen (ZtigO)
  4.  * @version 1.0.0 (01.12.2011)
  5.  *
  6.  * @description: A class for reading and writing to file, Java style!
  7.  * Throws exceptions on errors.
  8.  */
  9.  
  10. // Define custom exceptions
  11. class FileNotFoundException extends Exception { }
  12. class FileNotReadableException extends Exception { }
  13. class FileNotWriteableException extends Exception { }
  14.  
  15. class fileHandler
  16. {
  17. /** Class variables */
  18. protected $fileName; // to hold the file name
  19.  
  20. // P U B L I C F U N C T I O N S
  21.  
  22. /**
  23. * public Constructor, sets path to file (optional)
  24. *
  25. * @param string $filename = NULL
  26. */
  27. public function __construct($filename = NULL)
  28. {
  29. // Try to store the file name
  30. $this->setFile($filename);
  31. }
  32.  
  33. /**
  34. * public setFile, sets path to file. No exceptions thrown here.
  35. * If you're opening a URI with special characters, such as spaces,
  36. * you need to encode the URI/filename with urlencode().
  37. *
  38. * @param string &$filename (& == pass by reference)
  39. * @return boolean
  40. */
  41. public function setFile(&$filename)
  42. {
  43. // Make sure it's a valid file name (string w/length)
  44. if (is_string($filename) && (strlen($filename) > 0))
  45. {
  46. // Set the filename
  47. $this->fileName = $filename;
  48. return true; // success
  49. }
  50.  
  51. // Invalid file name
  52. return false;
  53. }
  54.  
  55. /**
  56. * public getFileName, returns the file name.
  57. *
  58. * @return string $filename
  59. */
  60. public function getFileName()
  61. {
  62. return $this->fileName;
  63. }
  64.  
  65. /**
  66. * public getFileContents, returns the contents of the file.
  67. * Throws exceptions if file isn't set, doesn't exist or can't be read.
  68. * The function returns the read data or FALSE on failure.
  69. *
  70. * @return string || boolean
  71. */
  72. public function getFileContents()
  73. {
  74. // Make sure we can read from the file. Throw eventual exceptions.
  75. $this->verifyFile();
  76.  
  77. // Return file contents, "@" to supress potential warnings.
  78. return @file_get_contents($this->fileName);
  79. }
  80.  
  81. /**
  82. * public write, writes data to the file.
  83. * Throws exceptions if file isn't set, doesn't exist, can't be read
  84. * or if it can't write to file. If filename does not exist, the file
  85. * is created. Otherwise, the existing file is overwritten, unless the
  86. * FILE_APPEND flag is set. The function returns the number of bytes
  87. * that were written to the file, or FALSE on failure.
  88. *
  89. * The optional value flags can be any combination of the following flags,
  90. * joined with the binary OR (|) operator: FILE_USE_INCLUDE_PATH, FILE_APPEND,
  91. * LOCK_EX. For details, see flag section on http://php.net/file_put_contents.
  92. *
  93. * $param string $data
  94. * $param int $flags = 0
  95. * @return int || boolean
  96. */
  97. public function write($data, $flags = 0)
  98. {
  99. // Make sure we can write to the file. Throw eventual exceptions.
  100. $this->verifyFile(true);
  101.  
  102. // Return the save result, FALSE on failure. Use the === operator
  103. // to verify the return data of this function.
  104. return file_put_contents($this->fileName, $data, $flags);
  105. }
  106.  
  107. // P R O T E C T E D F U N C T I O N S
  108.  
  109. /**
  110. * protected verifyFile, helper function that checks that
  111. * the file can be used for our purpose. Throws exceptions
  112. * if something's wrong with the file.
  113. *
  114. * Optional parameter, $write, is if it should check for
  115. * write permissions or not. Default is false.
  116. *
  117. * @param boolean $write = false
  118. */
  119. protected function verifyFile($write = false)
  120. {
  121. // Make sure the file path variable is set
  122. if (isset($this->fileName))
  123. {
  124. // Check if the file exists
  125. if (!file_exists($this->fileName))
  126. {
  127. // It does not, throw exception.
  128. throw new FileNotFoundException('File "'.htmlentities($this->fileName).'" doesn\'t exists.');
  129. }
  130.  
  131. // Check if file is readable
  132. if (!is_readable($this->fileName))
  133. {
  134. // It is not, throw exception
  135. throw new FileNotReadableException('File "'.htmlentities($this->fileName).'" can\'t be read, check file permissions.');
  136. }
  137.  
  138. // Optional ($write == true): Check if file is writeable
  139. if ($write && !is_writable($this->fileName))
  140. {
  141. // It is not, throw exception
  142. throw new FileNotWriteableException('Can\'t write to file "'.htmlentities($this->fileName).'", check file permissions.');
  143. }
  144. }
  145. else
  146. {
  147. // File path isn't set, throw exception
  148. throw new FileNotFoundException('Undefined file name.');
  149. }
  150. }
  151. }
  152. ?>

Tilbake til toppen ^

Emneord (tags): Fil, fillesing, exceptions

Legg inn en helt ny kode

Valgmuligheter

ZtigO sendte inn denne php-koden 23.07.2009 kl. 11:02.

  1. <?php
  2. /**
  3.  * nerdMail class
  4.  * @author Stig Magnus Halvorsen (ZtigO)
  5.  * @version 1.0.2
  6.  *
  7.  * http://nerdvar.com/
  8.  *
  9.  * A class using PHPs mail() function to send
  10.  * emails as text and/or HTML with or without
  11.  * attachments. Highly customizeable headers
  12.  * and with a emailadress validator and anti
  13.  * email injection function.
  14. */
  15. class nerdMail {
  16. /**
  17.   * define the required variables
  18.   */
  19. public $text;
  20. public $html;
  21. public $subject;
  22. public $sender;
  23. public $returnPath;
  24. protected $receivers = array();
  25. protected $Cc = array();
  26. protected $Bcc = array();
  27. protected $headers = array("keys" => array(), "values" => array());
  28. protected $headerKeys = array();
  29. protected $attachments = array();
  30.  
  31. /**
  32.   * The list of accepted encoding of attachments
  33.   * default is BASE64
  34.   * Must be uppercase!
  35.   */
  36. protected $enctypes = array("OCTET", "BASE64", "TEXT", "BIT7");
  37.  
  38. /**
  39.   * The list of not overrideable headers
  40.   * To prevent different unwanted results
  41.   * The standards shouldn't be removed
  42.   * Must be uppercase!
  43.   */
  44. protected $protectedHeaders = array("TO", "CC", "BCC", "FROM", "SUBJECT", "CONTENT-TYPE");
  45.  
  46. /**
  47.   * function $this->parseMail() or nerdMail::parseMail()
  48.   * Based upon Hellkeepa's Val_email() function
  49.   * Validates the email with a regular expression, then
  50.   * checks if the mail server exists using checkdnsrr()
  51.   *
  52.   * @param string $email
  53.   * @return boolean
  54.  */
  55. public static function parseMail($email) {
  56. $RegExp = "/^[a-z][\\w\\pL\\.-]*[a-z0-9]@[a-z0-9][\\w\\pL\\.-]*[a-z0-9]\\.[a-z][a-z\\.]*[a-z]\\z/ui";
  57.  
  58. if (preg_match ($RegExp, $email)) {
  59. $domain = explode("@", $email);
  60. $mailserver = $domain[(count($domain) - 1)];
  61.  
  62. if (checkdnsrr($mailserver, 'MX')) {
  63. return true;
  64. }
  65. }
  66.  
  67. return false;
  68. }
  69.  
  70. /** function $this->antiInjection or nerdMail::antiInjection
  71.   * looks for email injection attempts in $field by checking
  72.   * for line breaks and horizontal tabs
  73.   *
  74.   * @param string|int $field
  75.   * @return boolean
  76.   */
  77. public static function antiInjection ($field) {
  78. if (preg_match("(\r|\n)", $field)) {
  79. return true;
  80. } else {
  81. return false;
  82. }
  83. }
  84.  
  85. /** function $this->addMail
  86.   * type: to, cc or bcc
  87.   * email: address to add
  88.   * parse: true -> validate $email
  89.   *
  90.   * Use it to populate the list of recipients
  91.   * to for regular recievers, cc for carbon copy
  92.   * and bcc for blind carbon copy
  93.   *
  94.   * @param "to"|"cc"|"bcc" $type["to"]
  95.   * @param string $email
  96.   * @param boolean $parse[false]
  97.   * @return boolean
  98.   */
  99. public function addMail($type, $email, $parse = false) {
  100. if (empty($email)) {
  101. return false;
  102. }
  103.  
  104. if ($parse) {
  105. if (!$this->parseMail($email)) {
  106. return false;
  107. }
  108. } else {
  109. if ($this->antiInjection($email)) {
  110. return $email;
  111. }
  112. }
  113.  
  114. switch ($type) {
  115. case "to":
  116. $this->receivers[] = $email;
  117. break;
  118. case "cc":
  119. $this->Cc[] = $email;
  120. break;
  121. case "bcc":
  122. $this->receivers[] = $email;
  123. break;
  124. default:
  125. $this->receivers[] = $email;
  126. }
  127. return true;
  128. }
  129.  
  130. /** function $this->addHeader
  131.   * Use it to add extra headers or to
  132.   * override the nerdMail default ones
  133.   *
  134.   * Examples:
  135.   * $this->addHeader("List-Unsubscribe", "<http://nerdvar.com/unsubscripe.php>");
  136.   * $this->addHeader("Message-Id: 123xxx@nerdvar.com");
  137.   *
  138.   * @param string $key
  139.   * @param boolean $val[false]
  140.   * @return boolean
  141.   */
  142. public function addHeader ($key, $val = false) {
  143. if (empty($key) || empty($val)) {
  144. return false;
  145. }
  146.  
  147. /** Check for injectionattempt */
  148. if ($this->antiInjection($key) or $this->antiInjection($val)) {
  149. return false;
  150. }
  151.  
  152. if ($val == false) {
  153. $val = explode(":", $key);
  154. $key = $val[0];
  155. $val = $val[1];
  156. } else {
  157. if (substr($key, -1) == ":") {
  158. $key = substr($key, 0, -1);
  159. }
  160. }
  161.  
  162. if (substr($key, -1) == ":") { $key = substr($key, 0, -1); }
  163.  
  164. $this->headers["keys"][] = $key;
  165. $this->headerKeys[] = strtolower($key);
  166. $this->headers["values"][] = $val;
  167. return true;
  168. }
  169.  
  170. /** function $this->attach
  171.   * filePath: http://example.com/myfile.jpg, myfile.txt, etc
  172.   * contenttype: image/jpeg, plain/text, etc..
  173.   * encoding: BASE64, BIT7, etc.. Must be in $enctypes array
  174.   *
  175.   * Adds and validates file to attach in the attachment list
  176.   *
  177.   * @param string $filePath
  178.   * @param string $contenttype["OCTET"]
  179.   * @param string $encoding["BASE64"]
  180.   * @return boolean
  181.   */
  182. public function attach ($filePath, $contenttype = "OCTET", $encoding = "BASE64") {
  183. if (empty($filePath)) {
  184. return false;
  185. }
  186. if (trim($contenttype) == "") {
  187. $contenttype = "OCTET";
  188. }
  189. if (trim($encoding) == "") {
  190. $encoding = "BASE64";
  191. }
  192.  
  193. $data = file_get_contents($filePath);
  194.  
  195. if ($data) {
  196. $thisEnc = strtolower($encoding);
  197. if ((strtoupper($encoding) == "BASE64") or (!in_array(strtoupper($encoding), $this->enctypes))) {
  198. $data = base64_encode($data);
  199. $thisEnc = "base64";
  200. }
  201.  
  202. $this->attachments["encoding"][] = $thisEnc;
  203. $this->attachments["data"][] = chunk_split($data);
  204. $this->attachments["name"][] = basename($filePath);
  205.  
  206. if (preg_match("!^".TEXT."!i", $contenttype) && !preg_match("!;charset=!i", $contenttype)) {
  207. $this->attachments["cType"][] = "text/plain; charset=UTF-8";
  208. }
  209. elseif ($contenttype == OCTET) {
  210. $this->attachments["cType"][] = "application/octet-stream";
  211. } else {
  212. $this->attachments["cType"][] = $contenttype;
  213. }
  214.  
  215. unset($data);
  216. return true;
  217. } else {
  218. unset($data);
  219. return false;
  220. }
  221. }
  222.  
  223. /** function $this->send
  224.   * This completes the mailing by putting it all togheter and
  225.   * sending it out. Returns false on failure and fails if it's
  226.   * missing some required vars
  227.   *
  228.   * @return mixed
  229.   */
  230. public function send() {
  231. $sendData = array();
  232. $headerKeys = array();
  233. $i = 0;
  234.  
  235. /** Define the multipart email hdr info */
  236. $boundary1 = rand(0,9)."-".rand(10000000000,999999999)."-".rand(10000000000,999999999)."=:".rand(10000,99999);
  237. $boundary2 = rand(0,9)."-".rand(10000000000,999999999)."-".rand(10000000000,999999999)."=:".rand(10000,99999);
  238.  
  239. /** Check wether it's any attachments or not and sets multitype */
  240. if (count($this->attachments["name"]) > 0) {
  241. $multiType = "mixed"; $attach = true;
  242. } else {
  243. $multiType = "alternative"; $attach = false;
  244. }
  245.  
  246. /** Verify that the required variables are set */
  247. if (empty($this->sender) or ((count($this->receivers) == 0) && (count($this->Cc) == 0) && (count($this->Bcc) == 0)) or (empty($this->text) && empty($this->html))) {
  248. return false;
  249. }
  250.  
  251. /** Validate Subject */
  252. if (empty($this->subject) or $this->antiInjection($this->subject)) {
  253. $this->subject = "(No subject)";
  254. }
  255.  
  256. /** Add the receivers */
  257. while ($i < count($this->receivers)) {
  258. $sendData["receivers"] .= $this->receivers[$i];
  259. $i++;
  260.  
  261. if ($i != count($this->receivers)) {
  262. $sendData["receivers"] .= ", ";
  263. }
  264. }
  265. $i = 0;
  266.  
  267. /** Add the Carbon Copy receivers (CC) */
  268. while ($i < count($this->Cc)) {
  269. $sendData["Cc"] .= $this->Cc[$i];
  270. $i++;
  271.  
  272. if ($i != count($this->Cc)) {
  273. $sendData["Cc"] .= ", ";
  274. }
  275. }
  276. $i = 0;
  277.  
  278. /** Add the Blind Carbon Copy receivers */
  279. while ($i < count($this->Bcc)) {
  280. $sendData["Bcc"] .= $this->Bcc[$i];
  281. $i++;
  282.  
  283. if ($i != count($this->Bcc)) {
  284. $sendData["Bcc"] .= ", ";
  285. }
  286. }
  287. $i = 0;
  288.  
  289. /** Add the Headers **/
  290. if (!in_array("mime-version", $this->headerKeys)) {
  291. $headers .= "MIME-Version: 1.0\r\n";
  292. }
  293.  
  294. $headers .= "Content-Type: multipart/$multiType; boundary=\"$boundary1\"\r\n";
  295. $headers .= "From: ".$this->sender."\r\n";
  296.  
  297. if (!in_array("reply-to", $this->headerKeys)) {
  298. $headers .= "Reply-To: ".$this->sender."\r\n";
  299. }
  300.  
  301. if (count($this->headers["keys"]) > 0) {
  302. while ($i < count($this->headers["keys"])) {
  303. /** Make sure the header isn't in the blocked list */
  304. if (!in_array(strtoupper($this->headers["keys"][$i]), $this->protectedHeaders)) {
  305. $headers .= $this->headers["keys"][$i].": ".$this->headers["values"][$i]."\r\n";
  306. }
  307. $i++;
  308. }
  309. $i = 0;
  310. }
  311.  
  312. if ($sendData["Cc"]) {
  313. $headers .= "Cc: ".$sendData["Cc"]."\r\n";
  314. }
  315. if ($sendData["Bc"]) {
  316. $headers .= "Bcc: ".$sendData["Cc"]."\r\n";
  317. }
  318.  
  319. $headers .= "\n";
  320.  
  321. /** Add the mail body */
  322. if (!$attach) {
  323. $body = "MIME-Version: 1.0\r\nContent-Type: multipart/alternative; boundary=\"$boundary1\"\r\n\r\n";
  324.  
  325. if (!empty($this->text)) {
  326. $body .= "--$boundary1\nContent-Type: text/plain; charset=UTF-8\nContent-Transfer-Encoding: 7bit\n\n".$this->text."\n\n";
  327. }
  328. if (!empty($this->html)) {
  329. $body .= "--$boundary1\nContent-Type: text/html; charset=UTF-8\nContent-Transfer-Encoding: 7bit\n\n".$this->html."\n\n";
  330. }
  331. } else {
  332. $body = "--$boundary1\nContent-Type: multipart/alternative; boundary=\"$boundary2\"\r\n\r\n";
  333.  
  334. if (!empty($this->text)) {
  335. $body .= "--$boundary2\nContent-Type: text/plain; charset=UTF-8\nContent-Transfer-Encoding: 7bit\n\n".$this->text."\n\n";
  336. }
  337. if (!empty($this->html)) {
  338. $body .= "--$boundary2\nContent-Type: text/html; charset=UTF-8\nContent-Transfer-Encoding: 7bit\n\n".$this->html."\n\n";
  339. }
  340. $body .= "--$boundary2--\n\n";
  341.  
  342. /** Add attachments */
  343. while ($i < count($this->attachments["name"])) {
  344. $body .= "--$boundary1\nContent-Type: ".$this->attachments["cType"][$i]."; name=\"".$this->attachments["name"][$i]."\"\nContent-Transfer-Encoding: ".$this->attachments["encoding"][$i]."\nContent-Disposition: attachment; filename=\"".$this->attachments["name"][$i]."\"\n\n";
  345. $body .= $this->attachments["data"][$i];
  346. $i++;
  347. }
  348. $i = 0;
  349. }
  350.  
  351. $body .= "--$boundary1--";
  352.  
  353. /** Send the final mail */
  354. if (!empty($this->returnPath) && $this->parseMail($this->returnPath)) {
  355. return mail($sendData["receivers"], $this->subject, $body, $headers, "-f".$this->returnPath);
  356. }
  357. else {
  358. return mail($sendData["receivers"], $this->subject, $body, $headers);
  359. }
  360. }
  361. }
  362.  
  363. /** checkdnsrr() FUNCTION FOR WINDOWS SERVER WITH PHP VERSIONS LOWER THAN 5.3
  364.   * Checks for existence and creates the function if it doesn't, parameter
  365.   * data is validated to avoid shell injection
  366.   *
  367.   * It's being used by the $nerdMail->pasreMail() function
  368.   *
  369.   * @param string $hostName
  370.   * @param string $recType[""]
  371.   * @return boolean
  372. */
  373. if (!function_exists('checkdnsrr')) {
  374. /** List of accepted recTypes */
  375. $accepted = array('A', 'MX', 'NS', 'SOA', 'PTR', 'CNAME', 'AAAA', 'A6', 'SRV', 'NAPTR', 'TXT', 'ANY');
  376.  
  377. function checkdnsrr($hostName, $recType = "") {
  378. global $accepted;
  379.  
  380. if(!empty($hostName)) {
  381. /** validate the recType */
  382. if(!in_array($recType, $accepted)) $recType = "MX";
  383.  
  384. /** Validate domain/host name */
  385. if (gethostbynamel($hostName) or gethostbynamel(gethostbyaddr($hostName))) {
  386. @exec("nslookup -type=$recType $hostName", $result);
  387.  
  388. foreach ($result as $line) {
  389. if(preg_match("^$hostName",$line)) {
  390. return true;
  391. }
  392. }
  393. }
  394. return false;
  395. }
  396. return false;
  397. }
  398. }
  399. ?>

Tilbake til toppen ^

Emneord (tags): php, class, mail, epost, vedlegg

Legg inn en helt ny kode

Valgmuligheter

ZtigO sendte inn denne php-koden 16.05.2009 kl. 17:20.

  1. <script>
  2. // Percent Bar - Version 1.0
  3. // Author: Brian Gosselin of http://scriptasylum.com
  4. // Script featured on http://www.dynamicdrive.com
  5. // Note: Modified by Dynamicdrive so incr/decrCount() accepts any percentage
  6.  
  7. var spanID='output' ; // ZtigO Fix
  8. var loadedcolor='navy' ; // PROGRESS BAR COLOR
  9. var unloadedcolor='lightgrey'; // BGCOLOR OF UNLOADED AREA
  10. var barheight=15; // HEIGHT OF PROGRESS BAR IN PIXELS
  11. var barwidth=350; // WIDTH OF THE BAR IN PIXELS
  12. var bordercolor='black'; // COLOR OF THE BORDER
  13.  
  14. // THE FUNCTION BELOW CONTAINS THE ACTION(S) TAKEN ONCE BAR REACHES 100%.
  15. // IF NO ACTION IS DESIRED, TAKE EVERYTHING OUT FROM BETWEEN THE CURLY BRACES ({})
  16. // BUT LEAVE THE FUNCTION NAME AND CURLY BRACES IN PLACE.
  17. // PRESENTLY, IT IS SET TO DO NOTHING, BUT CAN BE CHANGED EASILY.
  18. // TO CAUSE A REDIRECT, INSERT THE FOLLOWING LINE IN BETWEEN THE CURLY BRACES:
  19. // window.location="http://redirect_page.html";
  20. // JUST CHANGE THE ACTUAL URL IT "POINTS" TO.
  21.  
  22. //*****************************************************//
  23. //********** DO NOT EDIT BEYOND THIS POINT **********//
  24. //*****************************************************//
  25.  
  26. var w3c = (document.getElementById) ? true : false;
  27. var ns4 = (document.layers) ? true : false;
  28. var ie4 = (document.all && !w3c) ? true : false;
  29. var ie5 = (document.all && w3c) ? true : false;
  30. var ns6 = (w3c && navigator.appName.indexOf("Netscape")>=0) ? true : false;
  31. var blocksize = (barwidth-2) / 100;
  32. barheight = Math.max(4,barheight);
  33. var loaded = 0;
  34. var perouter = 0;
  35. var perdone = 0;
  36. var images = new Array();
  37. var txt='';
  38.  
  39. txt+='<div id="perouter" onmouseup="hidebar()" style="position:relative; visibility:hidden; background-color:'+bordercolor+'; width:'+barwidth+'px; height:'+barheight+'px;">';
  40. txt+='<div style="position:absolute; top:1px; left:1px; width:'+(barwidth-2)+'px; height:'+(barheight-2)+'px; background-color:'+unloadedcolor+'; z-index:100; font-size:1px;"></div>';
  41. txt+='<div id="perdone" style="position:absolute; top:1px; left:1px; width:0px; height:'+(barheight-2)+'px; background-color:'+loadedcolor+'; z-index:100; font-size:1px;"></div>';
  42. txt+='</div>';
  43.  
  44.  
  45. document.getElementById(spanID).innerHTML = txt;
  46.  
  47. function incrCount(prcnt)
  48. {
  49. loaded+=prcnt;
  50. setCount(loaded);
  51. }
  52.  
  53. function decrCount(prcnt)
  54. {
  55. loaded-=prcnt;
  56. setCount(loaded);
  57. }
  58.  
  59. function setCount(prcnt)
  60. {
  61. loaded = prcnt;
  62. if (loaded<0)
  63. {
  64. loaded = 0;
  65. }
  66. if (loaded>=100)
  67. {
  68. loaded=100;
  69. setTimeout('hidebar()', 400);
  70. }
  71.  
  72. clipid(perdone, 0, blocksize*loaded, barheight-2, 0);
  73. }
  74.  
  75. //THIS FUNCTION BY MIKE HALL OF BRAINJAR.COM
  76. function findlayer(name,doc)
  77. {
  78. var i,layer;
  79.  
  80. for(i=0;i<doc.layers.length;i++)
  81. {
  82. layer=doc.layers[i];
  83. if(layer.name==name)return layer;
  84. if(layer.document.layers.length>0)
  85. if((layer=findlayer(name,layer.document))!=null)
  86. return layer;
  87. }
  88.  
  89. return null;
  90. }
  91.  
  92. function progressBarInit()
  93. {
  94. perouter = (ns4) ? findlayer('perouter',document) : (ie4) ? document.all['perouter'] : document.getElementById('perouter');
  95. perdone = (ns4) ? perouter.document.layers['perdone'] : (ie4) ? document.all['perdone'] : document.getElementById('perdone');
  96. clipid(perdone,0,0,barheight-2,0);
  97. if (ns4)
  98. {
  99. perouter.visibility="show";
  100. }
  101. else
  102. {
  103. perouter.style.visibility="visible";
  104. }
  105. }
  106.  
  107. function hidebar()
  108. {
  109. action();
  110. //(ns4)? perouter.visibility="hide" : perouter.style.visibility="hidden";
  111. }
  112.  
  113. function clipid(id,t,r,b,l)
  114. {
  115. if(ns4)
  116. {
  117. id.clip.left=l;
  118. id.clip.top=t;
  119. id.clip.right=r;
  120. id.clip.bottom=b;
  121. }
  122. else
  123. {
  124. id.style.width=r;
  125. }
  126. }
  127.  
  128. progressBarInit();
  129.  
  130.  
  131. </script>
  132.  
  133. <script type="text/javascript">
  134. incrCount(75) //set bar to 75%
  135. </script>

Tilbake til toppen ^

Emneord (tags): JavaScript

Legg inn en helt ny kode

Valgmuligheter

ZtigO sendte inn denne php-koden 02.12.2007 kl. 17:59.

  1. <?php
  2. /* Use this function to check if another server is online, requier that your server or host use PHP5 or newer. Function by Stig M. Halvorsen */
  3.  
  4. # Example #
  5. if (isOnline("www.domain.com", 80, 1)) {
  6. // www.domain.com is Online
  7. }
  8.  
  9. # Example #
  10. if (isOnline("83.67.80.234", 80, 3)) {
  11. // The server with the IP mentioned above is online
  12. }
  13.  
  14. # Function #
  15. function isOnline($server, $port, $timeout) {
  16. if (!$timeout or !is_numeric($timeout)) {
  17. $timeout = 1;
  18. }
  19. $check = @stream_socket_client("tcp://$server:$port", $errno, $errstr, $timeout);
  20.  
  21. if ($check) {
  22. return TRUE;
  23. }
  24.  
  25. return FALSE;
  26. }
  27. ?>

Tilbake til toppen ^

Legg inn en helt ny kode

Valgmuligheter

ZtigO sendte inn denne php-koden 07.12.2011 kl. 12:16.

  1. <?php
  2.  
  3. function mimeType($file) {
  4. // Function made by Stig M. Halvorsen, list is based on DavidS' function: http://norskwebforum.no/pastebin/8208
  5. $mTypes = array("3dm" => "x-world/x-3dmf",
  6. "3dmf" => "x-world/x-3dmf",
  7. "7z" => "application/x-7z-compressed",
  8. "a" => "application/octet-stream",
  9. "aab" => "application/x-authorware-bin",
  10. "aam" => "application/x-authorware-map",
  11. "aas" => "application/x-authorware-seg",
  12. "abc" => "text/vnd.abc",
  13. "acgi" => "text/html",
  14. "afl" => "video/animaflex",
  15. "ai" =>"application/postscript",
  16. "aif" =>"audio/x-aiff",
  17. "aifc" =>"audio/x-aiff",
  18. "aiff" =>"audio/x-aiff",
  19. "as" => "text/actionscript",
  20. "asc" =>"text/plain",
  21. "atom" =>"application/atom+xml",
  22. "avi" =>"video/x-msvideo",
  23. "bcpio" =>"application/x-bcpio",
  24. "bmp" =>"image/bmp",
  25. "cdf" =>"application/x-netcdf",
  26. "cgm" =>"image/cgm",
  27. "cpio" =>"application/x-cpio",
  28. "cpt" =>"application/mac-compactpro",
  29. "crl" =>"application/x-pkcs7-crl",
  30. "crt" =>"application/x-x509-ca-cert",
  31. "csh" =>"application/x-csh",
  32. "css" =>"text/css",
  33. "dcr" =>"application/x-director",
  34. "dir" =>"application/x-director",
  35. "djv" =>"image/vnd.djvu",
  36. "djvu" =>"image/vnd.djvu",
  37. "doc" =>"application/msword",
  38. "dtd" =>"application/xml-dtd",
  39. "dvi" =>"application/x-dvi",
  40. "dxr" =>"application/x-director",
  41. "eps" =>"application/postscript",
  42. "etx" =>"text/x-setext",
  43. "ez" =>"application/andrew-inset",
  44. "fla" => "application/octet-stream",
  45. "gif" =>"image/gif",
  46. "gram" =>"application/srgs",
  47. "grxml" =>"application/srgs+xml",
  48. "gtar" =>"application/x-gtar",
  49. "hdf" =>"application/x-hdf",
  50. "hqx" =>"application/mac-binhex40",
  51. "html" =>"text/html",
  52. "html" =>"text/html",
  53. "ice" =>"x-conference/x-cooltalk",
  54. "ico" =>"image/x-icon",
  55. "ics" =>"text/calendar",
  56. "ief" =>"image/ief",
  57. "ifb" =>"text/calendar",
  58. "iges" =>"model/iges",
  59. "igs" =>"model/iges",
  60. "indd" => "application/octet-stream",
  61. "jpe" =>"image/jpeg",
  62. "jpeg" =>"image/jpeg",
  63. "jpg" =>"image/jpeg",
  64. "js" =>"application/x-javascript",
  65. "kar" =>"audio/midi",
  66. "latex" =>"application/x-latex",
  67. "m3u" =>"audio/x-mpegurl",
  68. "m4a" => "audio/x-m4a",
  69. "man" =>"application/x-troff-man",
  70. "mathml" =>"application/mathml+xml",
  71. "me" =>"application/x-troff-me",
  72. "mesh" =>"model/mesh",
  73. "mid" =>"audio/midi",
  74. "midi" =>"audio/midi",
  75. "mif" =>"application/vnd.mif",
  76. "mov" =>"video/quicktime",
  77. "movie" =>"video/x-sgi-movie",
  78. "mp2" =>"audio/mpeg",
  79. "mp3" =>"audio/mpeg",
  80. "mpe" =>"video/mpeg",
  81. "mpeg" =>"video/mpeg",
  82. "mpg" =>"video/mpeg",
  83. "mpga" =>"audio/mpeg",
  84. "ms" =>"application/x-troff-ms",
  85. "msh" =>"model/mesh",
  86. "mxu m4u" =>"video/vnd.mpegurl",
  87. "nc" =>"application/x-netcdf",
  88. "oda" =>"application/oda",
  89. "ogg" =>"application/ogg",
  90. "pbm" =>"image/x-portable-bitmap",
  91. "pdb" =>"chemical/x-pdb",
  92. "pdf" =>"application/pdf",
  93. "pgm" =>"image/x-portable-graymap",
  94. "pgn" =>"application/x-chess-pgn",
  95. "php" =>"application/x-httpd-php",
  96. "php4" =>"application/x-httpd-php",
  97. "php3" =>"application/x-httpd-php",
  98. "phtml" =>"application/x-httpd-php",
  99. "phps" =>"application/x-httpd-php-source",
  100. "png" =>"image/png",
  101. "pnm" =>"image/x-portable-anymap",
  102. "ppm" =>"image/x-portable-pixmap",
  103. "ppt" =>"application/vnd.ms-powerpoint",
  104. "ps" =>"application/postscript",
  105. "qt" =>"video/quicktime",
  106. "ra" =>"audio/x-pn-realaudio",
  107. "ram" =>"audio/x-pn-realaudio",
  108. "ras" =>"image/x-cmu-raster",
  109. "rdf" =>"application/rdf+xml",
  110. "rgb" =>"image/x-rgb",
  111. "rm" =>"application/vnd.rn-realmedia",
  112. "roff" =>"application/x-troff",
  113. "rtf" =>"text/rtf",
  114. "rtx" =>"text/richtext",
  115. "sgm" =>"text/sgml",
  116. "sgml" =>"text/sgml",
  117. "sh" =>"application/x-sh",
  118. "shar" =>"application/x-shar",
  119. "shtml" =>"text/html",
  120. "silo" =>"model/mesh",
  121. "sit" =>"application/x-stuffit",
  122. "skd" =>"application/x-koan",
  123. "skm" =>"application/x-koan",
  124. "skp" =>"application/x-koan",
  125. "skt" =>"application/x-koan",
  126. "smi" =>"application/smil",
  127. "smil" =>"application/smil",
  128. "snd" =>"audio/basic",
  129. "spl" =>"application/x-futuresplash",
  130. "src" =>"application/x-wais-source",
  131. "sv4cpio" =>"application/x-sv4cpio",
  132. "sv4crc" =>"application/x-sv4crc",
  133. "svg" =>"image/svg+xml",
  134. "swf" =>"application/x-shockwave-flash",
  135. "t" =>"application/x-troff",
  136. "tar" =>"application/x-tar",
  137. "tcl" =>"application/x-tcl",
  138. "tex" =>"application/x-tex",
  139. "texi" =>"application/x-texinfo",
  140. "texinfo" =>"application/x-texinfo",
  141. "tgz" =>"application/x-tar",
  142. "tif" =>"image/tiff",
  143. "tiff" =>"image/tiff",
  144. "tr" =>"application/x-troff",
  145. "tsv" =>"text/tab-separated-values",
  146. "txt" =>"text/plain",
  147. "ustar" =>"application/x-ustar",
  148. "vcd" =>"application/x-cdlink",
  149. "vrml" =>"model/vrml",
  150. "vxml" =>"application/voicexml+xml",
  151. "wav" =>"audio/x-wav",
  152. "wbmp" =>"image/vnd.wap.wbmp",
  153. "wbxml" =>"application/vnd.wap.wbxml",
  154. "wml" =>"text/vnd.wap.wml",
  155. "wmlc" =>"application/vnd.wap.wmlc",
  156. "wmlc" =>"application/vnd.wap.wmlc",
  157. "wmls" =>"text/vnd.wap.wmlscript",
  158. "wmlsc" =>"application/vnd.wap.wmlscriptc",
  159. "wmlsc" =>"application/vnd.wap.wmlscriptc",
  160. "wrl" =>"model/vrml",
  161. "xbm" =>"image/x-xbitmap",
  162. "xht" =>"application/xhtml+xml",
  163. "xhtml" =>"application/xhtml+xml",
  164. "xls" =>"application/vnd.ms-excel",
  165. "xml xsl" =>"application/xml",
  166. "xpm" =>"image/x-xpixmap",
  167. "xslt" =>"application/xslt+xml",
  168. "xul" =>"application/vnd.mozilla.xul+xml",
  169. "xwd" =>"image/x-xwindowdump",
  170. "xyz" =>"chemical/x-xyz",
  171. "zip" =>"application/zip"
  172. );
  173.  
  174. $fileExt = pathinfo(strtolower($file));
  175. $fileExt = $fileExt[extension];
  176.  
  177. if ($mTypes[$fileExt]) {
  178. return $mTypes[$fileExt];
  179. }
  180.  
  181. return FALSE;
  182. }
  183.  
  184. ?>

Tilbake til toppen ^

Emneord (tags): mimetype, mime, type, types

Legg inn en helt ny kode

Valgmuligheter

ZtigO sendte inn denne php-koden 02.12.2007 kl. 17:59.

  1. <?php
  2. foreach ($element as $value) {
  3. if (search($value, "æ") or search($value, "ø") or search($value, "å")) {
  4. $letters = explode("", $value);
  5. if (count($letters) <= 3) {
  6. $value = stripslashes(htmlentities($value));
  7. echo "Samtilige ord i s&oslash;kestrengen m&aring; v&aelig;re mer enn tre tegn for at det skal v&aelig;re gyldig <strong>&laquo;".$value."&raquo;</strong><br />\n";
  8. }
  9. } else {
  10. if (strlen($value) <= 3) {
  11. $value = stripslashes(htmlentities($value));
  12. echo "Samtilige ord i s&oslash;kestrengen m&aring; v&aelig;re mer enn tre tegn for at det skal v&aelig;re gyldig <strong>&laquo;".$value."&raquo;</strong><br />\n";
  13. }
  14. }
  15. }
  16.  
  17. function search($haystack, $needle) {
  18. if (strpos(strtolower($haystack), strtolower($needle) === false) {
  19. return false;
  20. } else {
  21. return true;
  22. }
  23. }
  24. ?>

Tilbake til toppen ^

Legg inn en helt ny kode

Valgmuligheter

ZtigO sendte inn denne php-koden 02.12.2007 kl. 17:59.

  1. <?php
  2. show_source('guest.php');
  3. ?>
  4. <?php
  5. $ip = $_SERVER['REMOTE_ADDR'];
  6. $dato = date("d.m.Y");
  7.  
  8. include ("config.php");
  9. $do = $_GET['do']; // Funksjonen som bestemmer hva som skal gjøres
  10. ?>
  11. <h1>Gjestebok</h1>
  12. Hva synes du om siden min? Vil du kanskje legge igjen et lite innlegg her?<br />
  13.  
  14. <?php
  15. if($do == "post") {
  16. echo "<b>NB!:</b> Din IP adresse blir logget for og forhindre spam! IP adressen som blir registrert er: <b>$ip</b><br /><br />";
  17. }
  18.  
  19. else {
  20. echo "<a href='?do=post'>Klikk her for og skrive et innlegg!</a><br /><br>";
  21. }
  22.  
  23. ?>
  24. <?php
  25. if($do == "post") {
  26. ?>
  27. <form method="post" action="?do=send">
  28. <table cellspacing="0" cellpadding="0">
  29. <tr>
  30. <td><label><b>Ditt navn</b></label>
  31. :&nbsp;</td>
  32. <td><input name="navn" type="text" id="navn" style="width: 300px;"></td>
  33. </tr>
  34. <tr>
  35. <td><label><b>Din e-post</b></label>
  36. :&nbsp;</td>
  37. <td><input name="epost" type="text" id="epost" style="width: 300px;"></td>
  38. </tr>
  39. <tr>
  40. <td valign="top"><label><b>Din melding</b></label>
  41. :&nbsp;</td>
  42. <td><textarea name="melding" id="melding" style="width: 300px; height: 75px;"></textarea></td>
  43. </tr>
  44. <tr>
  45. <td><label>
  46. <input type="submit" name="Submit" value="Send inn!">
  47. </label></td>
  48. <td><input type="reset" name="Reset" value="Visk ut!"></td>
  49. </tr>
  50. </table>
  51. </form>
  52. <?
  53. } // Slutt
  54.  
  55. $navn = $_POST['navn'];
  56. $epost = $_POST['epost'];
  57. $melding = $_POST['melding'];
  58.  
  59. if ($do == "send") {
  60. if ($navn == "" or $epost == "" or $melding == "") {
  61. $error .= "<b>Det skjedde en eller flere feil under sendingen!</b><br>";
  62. }
  63. if ($navn == "") {
  64. $error .= "<li>Du fyllte ikke ut et navn!</li><br>";
  65. }
  66. if ($melding == "") {
  67. $error .= "<li>Du fyllte ikke ut en melding!</li><br>";
  68. }
  69. if ($epost == "") {
  70. $error .= "<li>Du fyllte ikke ut en epost!</li><br>";
  71. }
  72.  
  73. if (!$error) {
  74. echo "<b><font color='#FF0000'>Ditt innlegg ble lagt til! Du kan lese ditt innlegg nedenfor her!</font></b><br><br>";
  75.  
  76. $melding = htmlspecialchars($melding);
  77. $navn = htmlspecialchars($navn);
  78. $epost = htmlspecialchars($epost);
  79. $ar = file($fil);
  80. $a = implode($ar, "");
  81.  
  82. $fp = fopen($fil, "w");
  83. fwrite($fp, $a."$navn|$melding|$epost|$dato|$ip|\n");
  84. fclose($fp);
  85. } else {
  86. echo $error;
  87. }
  88. }
  89.  
  90. echo "<br><b>$vis siste innlegg:</b><br><br>";
  91.  
  92. /* Nedenfor her vises innleggene! */
  93.  
  94. $fil = file($fil);
  95. $totalt = count($fil);
  96. $linje = 0;
  97. $guest = array();
  98. if ($totalt >= $vis) $linje = $totalt - $vis;
  99.  
  100. while ($fil[$linje])
  101. {
  102. $a = explode("|", $fil[$linje]);
  103. $guest[] = "<div id='guest'>
  104. <b>$a[3] skrev <a href='mailto:$a[2]'>$a[0]</a>:</b><br />
  105. $a[1]<br />
  106. </div><br />
  107. \n";
  108. $linje++;
  109. }
  110.  
  111. echo implode('',array_reverse($guest));
  112.  
  113. ?>

Tilbake til toppen ^

Legg inn en helt ny kode

Valgmuligheter

ZtigO sendte inn denne html4strict-koden 21.01.2007 kl. 00:57.

  1. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
  2. <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
  3. <title>Scrolling</title>
  4. <style type="text/css">
  5. #scroll {
  6. height: 300px;
  7. width: 300px;
  8. overflow: scroll;
  9. }
  10. </style>
  11. </head>
  12.  
  13. <div id="scroll">
  14. Lorem ipsum dolor sit amet, consectetuer adipiscing elit.
  15. Etiam nunc augue, tincidunt sed, lacinia vitae, congue eu, ante.
  16. Nunc sit amet ante. Aliquam at felis. Nulla in libero. Pellentesque tincidunt libero id leo.
  17. Morbi at lorem. Maecenas rhoncus est vitae nibh consequat facilisis.
  18. Fusce mauris arcu, fermentum in, posuere vitae, blandit ac, quam. Aenean elementum euismod mauris.
  19. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus.
  20. Fusce risus felis, tristique a, eleifend in, sodales sit amet, nunc. Proin quis tortor non leo laoreet aliquet.
  21. Aliquam erat volutpat. Donec quis leo.
  22. Pellentesque porttitor leo non ante ultrices pellentesque.
  23. Aenean cursus sapien quis enim.
  24. Proin adipiscing, purus et faucibus vulputate, mauris nulla sagittis metus, in mattis nisi nisl ut leo.
  25. Duis dapibus tincidunt lectus.
  26. </div>
  27.  
  28. </body>
  29. </html>

Tilbake til toppen ^

Legg inn en helt ny kode

Valgmuligheter

ZtigO sendte inn denne php-koden 02.12.2007 kl. 17:59.

  1. <?php
  2.  
  3. // config
  4. $file = "data/shout.dat";
  5. $show = 8;
  6. $spamWords = array("nice site", "free", "casino", "sex", "look at this", "check", "virgin", "poker", "porn", "gratis", "asdfhg", "cheap", "delicious", "fuck", "play", "cards", "win", "gift", "surprise");
  7.  
  8. // start
  9. $name = $_POST['name'];
  10. $msg = $_POST['msg'];
  11.  
  12. // Henter IP adressen
  13. $ip = $_SERVER['REMOTE_ADDR']; // Kaller opp variablen $ip som skal skrives til filen senere
  14.  
  15. // Funksjon som sjekker spammen
  16. function checkSpam($string) {
  17. global $spamWords;
  18. $string = strtolower($string);
  19. foreach ($spamWords as $badWord) {
  20. $badWord = strtolower($badWord);
  21. if (strpos($string, $badWord) !== false) {
  22. $foundWord = TRUE;
  23. return TRUE;
  24. }
  25. }
  26. if (!$foundWord) { return FALSE; }
  27. }
  28.  
  29. // save
  30. if (!empty($name) && !empty($msg) && $name != "Navn" && $msg != "Melding") {
  31. $name = stripslashes($name);
  32. $name = ltrim($name);
  33. $name = rtrim($name);
  34. $msg = stripslashes($msg);
  35. $msg = ltrim($msg);
  36. $msg = rtrim($msg);
  37. if (strlen($name) > 15) die("Navnet er for langt!!");
  38. if (strlen($msg) > 150) die("Meldingen er for lang!");
  39. if (checkSpam($msg)) die("Ditt innlegg inneholder noen ord som regnes som spam!");
  40. if (!ereg("^[^|]+$", $name) || !ereg("^[^|]+$", $msg)) die("Tegnet | er ikke tillat!");
  41. // $msg = wordwrap($msg, 16, " ", 1);
  42. $msg = htmlspecialchars($msg);
  43. $name = htmlspecialchars($name);
  44. $pattern="%((http://|https://|ftp://|file://|www.)[^\s]+?)(.*)%isU";
  45. $msg = preg_replace($pattern, '<a href="\0" target="_new">link</a>', $msg);
  46. $pattern='<a href="www.';
  47. $msg = str_replace($pattern, '<a href="http://www.', $msg);
  48. $ar = file($file);
  49. $a = implode($ar, "");
  50. $fp = fopen($file, "w");
  51. fwrite($fp, $a."$name|$msg|$ip|\n");
  52. fclose($fp);
  53. }
  54.  
  55. // show
  56. $file = file($file);
  57. $total = count($file);
  58. $line = 0;
  59. $shoutOut = array();
  60. if ($total >= $show) $line = $total - $show;
  61.  
  62. while ($file[$line])
  63. {
  64. $a = explode("|", $file[$line]);
  65. $shoutOut[] = "<b>$a[0]:</b> $a[1]<br>\n";
  66. $line++;
  67. }
  68.  
  69. echo implode('',array_reverse($shoutOut));
  70. ?>
  71. <br>
  72. <a name="shout"><br>
  73. <form action="index.php?page=shout#shout" method="post">
  74. <input type="text" name="name" size="25" value="Navn" onBlur="if (this.value == '') this.value = 'Navn';" onFocus="if (this.value == 'Navn') this.value = '';"><br>
  75. <input type="text" name="msg" size="25" value="Melding" onBlur="if (this.value == '') this.value = 'Melding';" onFocus="if (this.value == 'Melding') this.value = '';"><br>
  76. <input type="submit" value="Go"></p>
  77. </form></a>

Tilbake til toppen ^

Legg inn en helt ny kode

Valgmuligheter

ZtigO sendte inn denne php-koden 11.01.2007 kl. 20:45.

  1. <?php
  2. // Slik sjekker du det
  3. if (sjekkBanning($melding)) {
  4. echo "Advarsel! Innlegget ditt inneholdt banneord...";
  5. }
  6.  
  7. // Funksjoner
  8. function stripos ($string, $ord, $start = 0) {
  9. return strpos(strtolower($string), strtolower($ord), $start);
  10. }
  11.  
  12. function sjekkBanning($string) {
  13. $banneord = array("faen", "morrapuler", "fuck"); // Legg til alle du kommer på
  14. $a = 0;
  15.  
  16. foreach ($banneord as $verdi) {
  17. if (stripos($string, $verdi) !== false) {
  18. $a++;
  19. }
  20. }
  21. if ($a > 0) {
  22. return TRUE; // Det er ett eller flere banneord
  23. } else {
  24. return FALSE; // Det er ikke banneord
  25. }
  26. }
  27. ?>

Tilbake til toppen ^

Det vises 10 koder per side.

Velg side:
1 | 2 | Neste

cron