24-04-14, 04:57 PM
سلام عليكم اولا هذا ب file
اولا الجزاء الخاص ب c#
اولا نظيف هذه المكتبات
ثم دالة الارسال
الان الدالة التي سنستدعي بها الدالة السابقة ايضا في c#
الان صفحة php
اولا الجزاء الخاص ب 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';
}
?>