Gel vatandas gell.. TikLaa'da gel..
Programlama
PHP OOP – MP3 Script
Ara 28th
Arkadaslar Türkiye’de veoh görüntülenemiyormus. Az sonra yahoo linklerini paylasacagim.
Videolar
Alternativ – Yahoo
Part – 1
Part – 2
Devamını Okumak için »
Java ile Emailsender (Socket)
Ara 9th
Selam arkadaşlar, java ile basit bir emailsender yapmıştım paylaşmak istedim. Email hesabınızdan giriş yaptığınızda bu program üzerinden maillerinizi gönderebilirsiniz. Program statik çalışıyor, yani ne cmd’den nede herhangi bir arayüz aracılığı ile değişkenlere değer atanmıyor. Fakat bunu isterseniz çok basit bir şekilde yapabilirsiniz. Umarım işinize yarar.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
import java.io.*; import java.net.*; public class EmailSender { public static void main(String[] args) throws Exception { Socket socket = new Socket("smtp.web.de",25); InputStream is = socket.getInputStream(); InputStreamReader isr = new InputStreamReader(is); BufferedReader br = new BufferedReader(isr); String response = br.readLine(); System.out.println(response); if (!response.startsWith("220")) { throw new Exception("220 reply not received from server."); } OutputStream os = socket.getOutputStream(); String command = "HELO localhost\r\n"; System.out.print(command); os.write(command.getBytes("US-ASCII")); response = br.readLine(); System.out.println(response); if (!response.startsWith("250")) { throw new Exception("250 reply not received from server."); } command = "MAIL FROM: qonyali@web.de\r\n"; System.out.print(command); os.write(command.getBytes("US-ASCII")); response = br.readLine(); System.out.println(response); if (!response.startsWith("250")) { throw new Exception("250 reply not received from server."); } command = "RCPT TO: halil@tiklaa.com\r\n"; System.out.print(command); os.write(command.getBytes("US-ASCII")); response = br.readLine(); System.out.println(response); if (!response.startsWith("250")) { throw new Exception("250 reply not received from server."); } command = "DATA\r\n"; System.out.print(command); os.write(command.getBytes("US-ASCII")); response = br.readLine(); System.out.println(response); if (!response.startsWith("354")) { throw new Exception("354 reply not received from server."); } command = "SUBJECT: Email Basligi\r\n"; System.out.print(command); os.write(command.getBytes("US-ASCII")); command = "E-Mail'in icerigi\r\n"; System.out.print(command); os.write(command.getBytes("US-ASCII")); command = ".\r\n"; System.out.print(command); os.write(command.getBytes("US-ASCII")); command = "QUIT\r\n"; System.out.print(command); os.write(command.getBytes("US-ASCII")); response = br.readLine(); System.out.println(response); if (!response.startsWith("250")) { throw new Exception("250 reply not received from server."); } } } |
Java ile Webserver Yapımı (Socket)
Ara 9th
Selam arkadaşlar deneme amaçlı bi Webserver yapmıştım. Sizlerle paylaşmak istedim. Serveri java’da yazdim. WebServer ve HttpRequest class’ları olmak üzere iki class’dan oluşuyor.
Webserver.java
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
import java.io.*; import java.net.*; import java.util.*; public final class WebServer { public static void main(String argv[]) throws Exception { int port = 3542; ServerSocket listenSocket = new ServerSocket(port); while (true) { Socket connectionSocket = listenSocket.accept(); HttpRequest request = new HttpRequest(connectionSocket); Thread thread = new Thread(request); thread.start(); } } } |
HttpRequest.java
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 |
import java.io.* ; import java.net.* ; import java.util.* ; final class HttpRequest implements Runnable { final static String CRLF = "\r\n"; Socket socket; // Constructor public HttpRequest(Socket socket) throws Exception { this.socket = socket; } // Implement the run() method of the Runnable interface. public void run() { try { processRequest(); } catch (Exception e) { System.out.println(e); } } private void processRequest() throws Exception { InputStream is = socket.getInputStream(); DataOutputStream os = new DataOutputStream(socket.getOutputStream()); BufferedReader br = new BufferedReader(new InputStreamReader(is)); String requestLine = br.readLine(); System.out.println(); System.out.println(requestLine); String headerLine = null; while ((headerLine = br.readLine()).length() != 0) { System.out.println(headerLine); } StringTokenizer tokens = new StringTokenizer(requestLine); tokens.nextToken(); String fileName = tokens.nextToken(); fileName = "." + fileName; FileInputStream fis = null; boolean fileExists = true; try { fis = new FileInputStream(fileName); } catch (FileNotFoundException e) { fileExists = false; } String statusLine = null; String contentTypeLine = null; String entityBody = null; if (fileExists) { statusLine = "HTTP/1.0 200 OK" + CRLF; contentTypeLine = "Content-type: " + contentType( fileName ) + CRLF; } else { statusLine = "HTTP/1.0 404 Not Found" + CRLF; contentTypeLine = "Content-type: " + "text/html" + CRLF; entityBody = "<HTML>" + "<HEAD><TITLE>Not Found</TITLE></HEAD>" + "<BODY>Not Found</BODY></HTML>"; } os.writeBytes(statusLine); os.writeBytes(contentTypeLine); os.writeBytes(CRLF); if (fileExists) { sendBytes(fis, os); fis.close(); } else { os.writeBytes(entityBody); } System.out.println(); System.out.println(requestLine); os.close(); br.close(); socket.close(); } private static void sendBytes(FileInputStream fis, OutputStream os) throws Exception { byte[] buffer = new byte[1024]; int bytes = 0; while ((bytes = fis.read(buffer)) != -1) { os.write(buffer, 0, bytes); } } private static String contentType(String fileName) { if (fileName.endsWith(".htm") || fileName.endsWith(".html")) { return "text/html"; } if (fileName.endsWith(".jpg") || fileName.endsWith(".jpeg")) { return "image/jpeg"; } if (fileName.endsWith(".gif")) { return "image/gif"; } if (fileName.endsWith(".txt")) { return "text/plain"; } if (fileName.endsWith(".pdf")) { return "application/pdf"; } return "application/octet-stream"; } } |
Bu iki class’ımızı oluşturduktan sonra Webserver.java dosyasında belirlediğimiz port üzerinden sorgumuzu yapabiliriz.
Örneğin : http://127.0.0.1:3542/dosya.txt
HttpRequest.java class’ını biraz daha geliştirebilirz. contentType içinde daha fazla uzantı ekleyebiliriz vs.
PHP ile Youtube Botu
Ara 8th
Evet arkadaşlar PHP ile basit bir youtube bot yazmıştım. Sizlerle paylaşmak istedim. Kullanımı gayet basit. Asağıda demosunu verdim.
Demo için tıklayınız
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
<?php $tag = $_GET['tag']; $bunu = array("Ü","Þ","Ç","Ý","Ö","ü","þ","ð","ç","ý","ö"); $buna = array("Ü","Ş","Ç","İ","Ö","ü","ş ","ğ","ç","ı","ö"); $string = file_get_contents('http://gdata.youtube.com/feeds/api/videos?q='. $tag .'&max-results=50'); $xml = simplexml_load_string($string); foreach($xml->entry as $ent){ echo "title-> " . str_replace($bunu, $buna, $ent->title) . "<br />"; echo "link-> " . str_replace($bunu, $buna, $ent->id) . "<br />"; echo "content->" . str_replace($bunu, $buna, $ent->content) . "<br /><br />"; } ?> |
PHP ile Türkçe Tarih Formatı
Kas 22nd
Php’de türkçe tarih yazdırmayla ilgili çok makale var evet ama aslında okadar uzun kodlara hiç gerek yok
Aşağıdaki gibi kısa bi şekildede bu işlemi yapmak mümkün.
<?php setlocale(LC_TIME,'turkish'); echo strftime('%d %b %y'); ?>
PHP ile Kaynak Kodu Renklendirme (Syntax Highlight)
Kas 22nd
Aslında çok basit bişey arkadaşlar kaynak kodunu renklendirip ekrana bastırmak. highlight_file veya show_source ile kaynak kodunu renklendirebiliriz.
<?php highlight_file('dosya.php'); show_source(dosya.php'); ?>
PHP ile Otomatik Şifre Oluşturma
Kas 22nd
Php ile otomatik şifre oluşturmayı sağlayan bir betik. Şifrenin zorluğunu $karakterler değişkenine ekleme ve çıkarma yaparak değiştirebilirsiniz. Uzunluğunu ise fonksiyonu çağırırken verdiğiniz parametre belirler.
<?php function olustur($sayi){ $karakterler = "qazwsxedcrfvtgbyhnujmIkolpQAZWSXEDCRFVTGBYHNUJMIKOLP1234567890"; $karakteruzunlugu = strlen($karakterler); srand((double)microtime()*1000000); for($i = 0; $i < $sayi; ++$i) { $rasgele .= $karakterler[rand(0, $karakteruzunlugu)]; } return $rasgele; } $yenisifre=olustur(8); echo ($yenisifre); ?>
PHP ile Tarayıcı Diline Göre Otomatik Dil Seçimi
Kas 22nd
Google’de, HP’de ve diğer büyük sitelerdeki gibi tarayıcımızın diline göre web sayfamızda otomatik dil seçimi yapmayı sağlayan ufak bi betik.
<?php $lang = substr($_SERVER['HTTP_ACCEPT_LANGUAGE'], 0, 2); header("Location:index.php?lang=$lang"); ?>
PHP ile Dosya/Dizin Okuma Işlemi
Kas 22nd
Php ile bir dosyanın/dizinin içinde bulunan dosyaları okuyup ekrana yazdırmaya yarayan bir betik.
<?php $path = "."; $ds = opendir($path); $i=1; while (($file = readdir($ds)) !== false) { if($file != "." && $file != "..") { $fl = str_replace("_"," ",$file); $fl = str_replace("-"," ",$fl); $fl = explode('.',$fl); echo "$i. <a href='$path/$file'>$fl[0]</a><br />"; $i++; } } closedir($ds); ?>
PHP ile Google Translate API Kullanımı
Kas 22nd
Selam arkadaşlar, google’nin hizmetlerinden birisi olan translate api’sını kullanarak hazırlamış olduğum GoogleTranslater.
<?php $q = $_REQUEST['q']; $lang_1 = $_REQUEST['lang1']; $lang_2 = $_REQUEST['lang2']; if(!isset($lang_1)) $lang_1 = "en"; if(!isset($lang_2)) $lang_2 = "tr"; header("Content-Type: text/html; charset=UTF-8"); $language = array('ar'=>'Arabisch','bg'=>'Bulgarisch','zh-CN'=>'Chinesisch','da'=>'Dänisch','de'=>'Deutsch','en'=>'Englisch','fi'=>'Finnisch','fr'=>'Französisch','el'=>'Griechisch','iw'=>'Hebräisch','hi'=>'Hindi','id'=>'Indonesisch','it'=>'Italienisch','ja'=>'Japanisch','ca'=>'Katalanisch','ko'=>'Koreanisch','hr'=>'Kroatisch','lv'=>'Lettisch','lt'=>'Litauisch','nl'=>'Niederländisch','no'=>'Norwegisch','pl'=>'Polnisch','pt'=>'Portugiesisch','ro'=>'Rumänisch','ru'=>'Russisch','sv'=>'Schwedisch','sr'=>'Serbisch','sk'=>'Slowakisch','sl'=>'Slowenisch','es'=>'Spanisch','tl'=>'Tagalog','cs'=>'Tschechisch','tr'=>'Turkish','uk'=>'Ukrainisch','vi'=>'Vietnamesisch'); function googleTranslator($text,$lang1,$lang2){ $data = file_get_contents('http://ajax.googleapis.com/ajax/services/language/translate?v=1.0&q='.urlencode($text).'&langpair='.$lang1.'%7C'.$lang2); $data = json_decode($data); return $data->responseData->translatedText; } echo <<<END Cevrilecek Metin : <form method="post" action=""> <textarea name="q" rows="5" cols="36">$q</textarea> <br /> <select name="lang1"> END; foreach($language as $k=>$n){ if($k == $lang_1){ echo '<option SELECTED value="'.$k.'">'.$n.'</option>'; } else echo '<option value="'.$k.'">'.$n.'</option>'; } echo '</select> > '; echo '<select name="lang2">'; foreach($language as $k=>$n){ if($k == $lang_2){ echo '<option value="'.$k.'" SELECTED>'.$n.'</option>'; } else echo '<option value="'.$k.'">'.$n.'</option>'; } echo <<<END </select> <input type="submit" value="Go.."> </form> END; echo googleTranslator("$q","$lang_1","$lang_2"); ?>
















