تقييم الموضوع :
  • 0 أصوات - بمعدل 0
  • 1
  • 2
  • 3
  • 4
  • 5
هل هذا الكود جيد لتعديل نص في ملف نصي
#6
سلام عليكم اولا هذا ب file

اولا الجزاء الخاص ب c#

اولا نظيف هذه المكتبات

كود :
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Net;
using System.Web;
using System.Net.NetworkInformation;

ثم دالة الارسال

كود :
public static int  hold = 5;
       public static bool  hold_net_work = false;
        internal  string getHTTP(string szURL, string szPost)
        {
            bool ok = false;
            int error = 0;
            fe:
          
                try
                {
                    HttpWebRequest httprequest;
                    HttpWebResponse httpresponse;
                    StreamReader bodyreader;
                    string bodytext = "";
                    Stream responsestream;
                    Stream requestStream;
                    httprequest = (HttpWebRequest)WebRequest.Create(szURL);
                    httprequest.Method = "POST";
                    httprequest.ContentType =
                    "application/x-www-form-urlencoded";
                    httprequest.ContentLength = szPost.Length;
                    requestStream = httprequest.GetRequestStream();
                    requestStream.Write(Encoding.ASCII.GetBytes(szPost), 0,
                    szPost.Length);
                    requestStream.Close();
                    httpresponse = (HttpWebResponse)httprequest.GetResponse();
                    responsestream = httpresponse.GetResponseStream();
                    bodyreader = new StreamReader(responsestream);
                    bodytext = bodyreader.ReadToEnd();
                    ok = true;
                    return bodytext;
                }
                catch
                {
              
                    goto fe;
                }
          
            return "post_error";
        }

الان الدالة التي سنستدعي بها الدالة السابقة ايضا في c#

كود :
public void my_reg(string old_email,string new_email)
        {
            string result = getHTTP(@"http://mysite.com/s.php", "old_email=" + old_email + "&new_email=" + new_email);
            switch (result)
            {
                case "post_error":
                    // خطاء في الشبكة
                    break;
                case "email_change_ok":
                    // تم تغيير البريد بنجاح
                    break;
                case "old_not_found":
                   // البريد السابق غير موجود
                    break;
                case "server_not_respous":
                    // المخدم لا يستجيب او ان الملف غير قابل للقراءة والكتابة
                    break;
                case "input_is_not_email":
                    // المدخلات ليست بريد الكتروني صحيح
                    break;
                case "input_empty":
                    // المدخلات فارغة
                    break;
                default:
                    // خطاء غير معروف
                    break;
            }
        }


الان صفحة php
كود :
<?php
$filename='/path/to/foo.txt';
$filenamelog='/path/to/log.txt';
$email_array=null;$counter_of_email=0;
if((!empty($_POST['new_email'])) &&(!empty($_POST['old_email'])) )
{
      if((filter_var($_POST['new_email'], FILTER_VALIDATE_EMAIL))&&(filter_var($_POST['old_email'], FILTER_VALIDATE_EMAIL))) {
          
          $email=  mysql_real_escape_string($_POST['new_email']);
        
          $old=mysql_real_escape_string($_POST['old_email']);;
      
if ((file_exists($filename))&& (is_writable ($filename )) && (is_readable ($filename )))           {
            $file = fopen($filename, "r+");
                     while(!feof($file)) {
  $email_array[$counter_of_email] =fgets($file);
  $counter_of_email++;
}
fclose($file);
if(in_array( $old, $email_array))
{
    $key = array_search($old, $email_array);
    $key--;
    $email_array[$key]=$email;
    file_put_contents($filename, "");
     $file = fopen($filename, 'w');
    foreach ($email_array as $value) {
      
fwrite($file, $value.'\n');
    }
    fclose($file);
    $da=  date("Y-m-d H:i:s");
    $fp = fopen($filenamelog, 'w');
fwrite($fp, "email is change from $old to $email at $da  \n");
fclose($fp);
echo 'email_change_ok';
}
else {
  echo 'old_not_found';
}          
}
else {
     echo 'server_not_respous';
}
          
      }
else {
      echo 'input_is_not_email';    
      }
}
else
{
    echo 'input_empty';
}
?>
الرد }}}
تم الشكر بواسطة: ربيع


الردود في هذا الموضوع
RE: هل هذا الكود جيد لتعديل نص في ملف نصي - بواسطة oneyemenweb2 - 24-04-14, 04:57 PM

المواضيع المحتمل أن تكون متشابهة .
الموضوع : الكاتب الردود : المشاهدات : آخر رد
  [كود] طلب تعديل الكود mostfa1995 0 1,764 23-04-16, 04:05 AM
آخر رد: mostfa1995
Question كيف استخدم هذا الكود ...؟ Ahmed-IT 1 2,167 05-08-15, 08:31 PM
آخر رد: oneyemenweb2
Star [سؤال] اخواني الرجاء التعديل علي هذا الكود SniperHacker 3 2,789 27-02-14, 12:38 AM
آخر رد: oneyemenweb2

التنقل السريع :


يقوم بقرائة الموضوع: