machanla help php

sudu hawa

Well-known member
  • Dec 1, 2011
    1,626
    100
    63
    machanla mata me code eka piliwelata hadala onne mata one message eka vitharai anithe awa wadak na

    $to = '[email protected]';
    $subject = 'HACK ATTEMPT';
    $header = 'From: [email protected]';
    if (mail($to, $subject, $logging, $header)) {
    echo "Sent notice to admin.";
    }

    }

    function verifyFormToken($form) {

    // check if a session is started and a token is transmitted, if not return an error
    if(!isset($_SESSION[$form.'_token'])) {
    return false;
    }

    // check if the form is sent with token in it
    if(!isset($_POST['token'])) {
    return false;
    }

    // compare the tokens against each other if they are still the same
    if ($_SESSION[$form.'_token'] !== $_POST['token']) {
    return false;
    }

    return true;
    }

    function generateFormToken($form) {

    // generate a token from an unique value, took from microtime, you can also use salt-values, other crypting methods...
    $token = md5(uniqid(microtime(), true));

    // Write the generated token to the session variable to check it against the hidden field when the form is sent
    $_SESSION[$form.'_token'] = $token;

    return $token;
    }

    // VERIFY LEGITIMACY OF TOKEN
    if (verifyFormToken('form1')) {

    // CHECK TO SEE IF THIS IS A MAIL POST
    if (isset($_POST['URL-main'])) {

    // Building a whitelist array with keys which will send through the form, no others would be accepted later on
    $whitelist = array('token','req-name','req-email','typeOfChange','urgency','URL-main','addURLS', 'curText', 'newText', 'save-stuff', 'mult');

    // Building an array with the $_POST-superglobal
    foreach ($_POST as $key=>$item) {

    // Check if the value $key (fieldname from $_POST) can be found in the whitelisting array, if not, die with a short message to the hacker
    if (!in_array($key, $whitelist)) {

    writeLog('Unknown form fields');
    die("Hack-Attempt detected. Please use only the fields in the form");

    }

    // PREPARE THE BODY OF THE MESSAGE

    $message = '<html><body>';
    $message .= '<img src="http://css-tricks.com/examples/WebsiteChangeRequestForm/images/wcrf-header.png" alt="Website Change Request" />';
    $message .= '<table rules="all" style="border-color: #666;" cellpadding="10">';
    $message .= "<tr style='background: #eee;'><td><strong>Name:</strong> </td><td>" . strip_tags($_POST['txtna']) . "</td></tr>";
    $message .= "<tr><td><strong>Email:</strong> </td><td>" . strip_tags($_POST['req-email']) . "</td></tr>";
    $message .= "<tr><td><strong>Type of Change:</strong> </td><td>" . strip_tags($_POST['typeOfChange']) . "</td></tr>";
    $message .= "<tr><td><strong>Urgency:</strong> </td><td>" . strip_tags($_POST['urgency']) . "</td></tr>";
    $message .= "<tr><td><strong>URL To Change (main):</strong> </td><td>" . $_POST['URL-main'] . "</td></tr>";
    $addURLS = $_POST['addURLS'];
    if (($addURLS) != '') {
    $message .= "<tr><td><strong>URL To Change (additional):</strong> </td><td>" . strip_tags($addURLS) . "</td></tr>";
    }
    $curText = htmlentities($_POST['curText']);
    if (($curText) != '') {
    $message .= "<tr><td><strong>CURRENT Content:</strong> </td><td>" . $curText . "</td></tr>";
    }
    $message .= "<tr><td><strong>NEW Content:</strong> </td><td>" . htmlentities($_POST['newText']) . "</td></tr>";
    $message .= "</table>";
    $message .= "</body></html>";




    // MAKE SURE THE "FROM" EMAIL ADDRESS DOESN'T HAVE ANY NASTY STUFF IN IT

    $pattern = "/^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$/i";
    if (preg_match($pattern, trim(strip_tags($_POST['req-email'])))) {
    $cleanedFrom = trim(strip_tags($_POST['req-email']));
    } else {
    return "The email address you entered was invalid. Please try again!";
    }




    // CHANGE THE BELOW VARIABLES TO YOUR NEEDS

    $to = '[email protected]';

    $subject = 'Website Change Reqest';

    $headers = "From: " . $cleanedFrom . "\r\n";
    $headers .= "Reply-To: ". strip_tags($_POST['req-email']) . "\r\n";
    $headers .= "MIME-Version: 1.0\r\n";
    $headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";

    if (mail($to, $subject, $message, $headers)) {
    echo 'Your message has been sent.';
    } else {
    echo 'There was a problem sending the email.';
    }

    // DON'T BOTHER CONTINUING TO THE HTML...
    die();

    }
    } else {

    if (!isset($_SESSION[$form.'_token'])) {

    } else {
    echo "Hack-Attempt detected. Got ya!.";
    writeLog('Formtoken');
    }

    }
    ?>
     

    Pink panther

    Well-known member
  • Nov 8, 2011
    23,234
    3,133
    113
    35
    ~ ση тнє ƒℓσω ~
    fsvT.jpeg
     

    shan_wicram

    Member
    Aug 21, 2011
    857
    84
    0
    මුලින්ම හොඳට පිළිවෙලට ඉගෙනගෙන වැඩේට බහින්න.....එතකොට ඔයවගේ මගදි හිරවෙන්නේ නැහැ..පොඩ්ඩක් http://stackoverflow.com/ එකෙන් අහල බලන්න..උදව්වක් ගන්න පුලුවන් වෙයි...:) ගෑනුන්ගේ..photos මේකෙ දම දමා පිස්සුකෙලින උන්‍එක්ක බැලුවම ඔයා හොඳයි..අත්හදා බැලීම් කරන්න..තව උනන්දු වෙන්න...මම දැන් online ඉන්නේ..mobile එකෙන්...ගෙදර ආවම තමයි බලන්න වෙන්නේ...:)
     

    ishan001

    Active member
  • Sep 10, 2006
    327
    43
    28
    try this machan..

    $to = '[email protected]';
    $subject = 'Website Change Reqest';

    //html message any html code u can write
    $message = '<html><body>';
    $message .= '<img src="http://css-tricks.com/examples/WebsiteChangeRequestForm/images/wcrf-header.png" alt="Website Change Request" />';
    $message .= '<table rules="all" style="border-color: #666;" cellpadding="10">';
    $message .= "<tr style='background: #eee;'><td><strong>Name:</strong> </td><td>" . strip_tags($_POST['txtna']) . "</td></tr>";
    $message .= "<tr><td><strong>Email:</strong> </td><td>" . strip_tags($_POST['req-email']) . "</td></tr>";
    $message .= "<tr><td><strong>Type of Change:</strong> </td><td>" . strip_tags($_POST['typeOfChange']) . "</td></tr>";
    $message .= "<tr><td><strong>Urgency:</strong> </td><td>" . strip_tags($_POST['urgency']) . "</td></tr>";
    $message .= "<tr><td><strong>URL To Change (main):</strong> </td><td>" . $_POST['URL-main'] . "</td></tr>";
    $message .= "<tr><td><strong>NEW Content:</strong> </td><td>" . htmlentities($_POST['newText']) . "</td></tr>";
    $message .= "</table>";
    $message .= "</body></html>";

    $cleanedFrom = trim(strip_tags($_POST['req-email']));

    $headers = "From: " . $cleanedFrom . "\r\n";
    $headers .= "Reply-To: ". strip_tags($_POST['req-email']) . "\r\n";
    $headers .= "MIME-Version: 1.0\r\n";
    $headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";

    if (mail($to, $subject, $message, $headers)) {
    echo 'Your message has been sent.';
    } else {
    echo 'There was a problem sending the email.';
    }
     

    sudu hawa

    Well-known member
  • Dec 1, 2011
    1,626
    100
    63
    මුලින්ම හොඳට පිළිවෙලට ඉගෙනගෙන වැඩේට බහින්න.....එතකොට ඔයවගේ මගදි හිරවෙන්නේ නැහැ..පොඩ්ඩක් http://stackoverflow.com/ එකෙන් අහල බලන්න..උදව්වක් ගන්න පුලුවන් වෙයි...:) ගෑනුන්ගේ..photos මේකෙ දම දමා පිස්සුකෙලින උන්‍එක්ක බැලුවම ඔයා හොඳයි..අත්හදා බැලීම් කරන්න..තව උනන්දු වෙන්න...මම දැන් online ඉන්නේ..mobile එකෙන්...ගෙදර ආවම තමයි බලන්න වෙන්නේ...:)


    gedara giya hama podak balala help ekak denna yaluwa
     

    sudu hawa

    Well-known member
  • Dec 1, 2011
    1,626
    100
    63
    try this machan..

    $to = '[email protected]';
    $subject = 'Website Change Reqest';

    //html message any html code u can write
    $message = '<html><body>';
    $message .= '<img src="http://css-tricks.com/examples/WebsiteChangeRequestForm/images/wcrf-header.png" alt="Website Change Request" />';
    $message .= '<table rules="all" style="border-color: #666;" cellpadding="10">';
    $message .= "<tr style='background: #eee;'><td><strong>Name:</strong> </td><td>" . strip_tags($_POST['txtna']) . "</td></tr>";
    $message .= "<tr><td><strong>Email:</strong> </td><td>" . strip_tags($_POST['req-email']) . "</td></tr>";
    $message .= "<tr><td><strong>Type of Change:</strong> </td><td>" . strip_tags($_POST['typeOfChange']) . "</td></tr>";
    $message .= "<tr><td><strong>Urgency:</strong> </td><td>" . strip_tags($_POST['urgency']) . "</td></tr>";
    $message .= "<tr><td><strong>URL To Change (main):</strong> </td><td>" . $_POST['URL-main'] . "</td></tr>";
    $message .= "<tr><td><strong>NEW Content:</strong> </td><td>" . htmlentities($_POST['newText']) . "</td></tr>";
    $message .= "</table>";
    $message .= "</body></html>";

    $cleanedFrom = trim(strip_tags($_POST['req-email']));

    $headers = "From: " . $cleanedFrom . "\r\n";
    $headers .= "Reply-To: ". strip_tags($_POST['req-email']) . "\r\n";
    $headers .= "MIME-Version: 1.0\r\n";
    $headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";

    if (mail($to, $subject, $message, $headers)) {
    echo 'Your message has been sent.';
    } else {
    echo 'There was a problem sending the email.';
    }


    yaluwa wada karannae naha .... puluwan nam mata register unama thanking email ekak yawana hadala denwada
     

    ishan001

    Active member
  • Sep 10, 2006
    327
    43
    28
    yaluwa wada karannae naha .... puluwan nam mata register unama thanking email ekak yawana hadala denwada
    machan ubage form eke thiyena email and name wage fileds wala details submit karapuwama yana php files eken aragena uba uba $message kiyana eka ubata ona message eka liyapan html hari nikan text ekak hari dapan. eke thiyena ocooma danna one naha uba ewwa eka hindai mama a occoma damme eta passe subject ekai danna thiyenne
     

    sudu hawa

    Well-known member
  • Dec 1, 2011
    1,626
    100
    63
    machan ubage form eke thiyena email and name wage fileds wala details submit karapuwama yana php files eken aragena uba uba $message kiyana eka ubata ona message eka liyapan html hari nikan text ekak hari dapan. eke thiyena ocooma danna one naha uba ewwa eka hindai mama a occoma damme eta passe subject ekai danna thiyenne

    $to = '[email protected]';
    $subject = 'Website Change Reqest';

    //html message any html code u can write
    $message = '<html><body>';
    $message .= '<img src="http://css-tricks.com/examples/WebsiteChangeRequestForm/images/wcrf-header.png" alt="Website Change Request" />';
    $message .= '<table rules="all" style="border-color: #666;" cellpadding="10">';
    $message .= "<tr style='background: #eee;'><td><strong>Name:</strong> </td><td>" . strip_tags($_POST['First']) . "</td></tr>";
    $message .= "<tr><td><strong>Email:</strong> </td><td>" . strip_tags($_POST['Last']) . "</td></tr>";
    $message .= "<tr><td><strong>Type of Change:</strong> </td><td>" . strip_tags($_POST['typeOfChange']) . "</td></tr>";
    $message .= "<tr><td><strong>Urgency:</strong> </td><td>" . strip_tags($_POST['urgency']) . "</td></tr>";
    $message .= "<tr><td><strong>URL To Change (main):</strong> </td><td>" . $_POST['URL-main'] . "</td></tr>";
    $message .= "<tr><td><strong>NEW Content:</strong> </td><td>" . htmlentities($_POST['newText']) . "</td></tr>";
    $message .= "</table>";
    $message .= "</body></html>";

    if (mail($to, $subject, $message)) {
    echo 'Your message has been sent.';
    } else {
    echo 'There was a problem sending the email.';
    }


    machan mehemada
     
    Last edited:

    ishan001

    Active member
  • Sep 10, 2006
    327
    43
    28
    $to = '[email protected]';
    $subject = 'Website Change Reqest';

    //html message any html code u can write
    $message = '<html><body>';
    $message .= '<img src="http://css-tricks.com/examples/WebsiteChangeRequestForm/images/wcrf-header.png" alt="Website Change Request" />';
    $message .= '<table rules="all" style="border-color: #666;" cellpadding="10">';
    $message .= "<tr style='background: #eee;'><td><strong>Name:</strong> </td><td>" . strip_tags($_POST['First']) . "</td></tr>";
    $message .= "<tr><td><strong>Email:</strong> </td><td>" . strip_tags($_POST['Last']) . "</td></tr>";
    $message .= "<tr><td><strong>Type of Change:</strong> </td><td>" . strip_tags($_POST['typeOfChange']) . "</td></tr>";
    $message .= "<tr><td><strong>Urgency:</strong> </td><td>" . strip_tags($_POST['urgency']) . "</td></tr>";
    $message .= "<tr><td><strong>URL To Change (main):</strong> </td><td>" . $_POST['URL-main'] . "</td></tr>";
    $message .= "<tr><td><strong>NEW Content:</strong> </td><td>" . htmlentities($_POST['newText']) . "</td></tr>";
    $message .= "</table>";
    $message .= "</body></html>";

    if (mail($to, $subject, $message)) {
    echo 'Your message has been sent.';
    } else {
    echo 'There was a problem sending the email.';
    }


    machan mehemada


    meka balapan
    poddak withara advance habai
    http://youhack.me/2010/04/01/building-a-registration-system-with-email-verification-in-php/