xmlHttpRequest.php

Einklappen
X
 
  • Filter
  • Zeit
  • Anzeigen
Alles löschen
neue Beiträge

  • xmlHttpRequest.php

    Habe ein xmlHttpRequest aus dem Web zusammen gebastelt aber irgendwie funktionniert dies nicht:
    Anbei der Source vielleicht könnt ihr mit weiterhelfen.

    Besten dank schon im Voraus

    <?php


    $referringPage = 'http://...';


    $recipients = "onerecip|noone@nowhere.ch";


    $form_structure = array(
    "text|Name|fm_name|true|none",
    "text|organisation|fm_organisation|false|none",
    "text|strasse|fm_strasse|false|none",
    "text|plz|fm_plz|false|none",
    "text|tel|fm_tel|false|none",
    "text|email|fm_email|true|email",
    "text|subject|fm_subject|false|none",
    "textarea|message|fm_message|true|none"
    );


    $field_name = "fm_name";
    $field_email = "fm_email";
    $field_subject = "fm_subject";

    $subject = 'Website Contact: ';


    $show_headers_in_message = FALSE;
    $wrap_messages = TRUE;
    $include_ip = TRUE;
    $msg_mailserver = "No connection to the mailserver. Please try again later.";
    $msg_sent = "Your message has been sent.";
    $msg_error = "Please click the back button, correct the errors and submit the form again.";





    $email_sent = FALSE;
    $t_out = "";


    $recipients = explode("|", $recipients);
    for ($i = 0; $i < count($recipients); $i++) {
    $recipients[$i] = trim($recipients[$i]);
    }


    for ($i = 0; $i < count($form_structure); $i++) {
    $form_structure[$i] = explode("|", $form_structure[$i]);
    for ($j = 0; $j < count($form_structure[$i]); $j++) {
    $form_structure[$i][$j] = trim($form_structure[$i][$j]);
    }
    }


    function cleanPosUrl ($str) {
    $nStr = $str;
    $nStr = str_replace("**am**","&",$nStr);
    $nStr = str_replace("**pl**","+",$nStr);
    $nStr = str_replace("**eq**","=",$nStr);
    return stripslashes($nStr);
    }


    function is_valid_url($link) {


    if (strpos($link, "http://") === FALSE) { $link = "http://" . $link; }
    $url_parts = @parse_url($link);
    if (empty($url_parts["host"])) return( false );
    if (!empty($url_parts["path"])) { $documentpath = $url_parts["path"]; }
    else { $documentpath = "/"; }
    if (!empty($url_parts["query"])) { $documentpath .= "?" . $url_parts["query"]; }
    $host = $url_parts["host"]; $port = $url_parts["port"];
    if (empty($port)) $port = "80";
    $socket = @fsockopen( $host, $port, $errno, $errstr, 30 );
    if (!$socket) { return(false); }
    else {fwrite ($socket, "HEAD ".$documentpath." HTTP/1.0\r\nHost: $host\r\n\r\n");
    $http_response = fgets( $socket, 22 );
    if (ereg("200 OK", $http_response, $regs)) { return(true); fclose($socket); }
    else { return(false); } }
    }


    function is_valid_email($email) {


    $qtext = '[^\\x0d\\x22\\x5c\\x80-\\xff]';
    $dtext = '[^\\x0d\\x5b-\\x5d\\x80-\\xff]';
    $atom = '[^\\x00-\\x20\\x22\\x28\\x29\\x2c\\x2e\\x3a-\\x3c'.
    '\\x3e\\x40\\x5b-\\x5d\\x7f-\\xff]+';
    $quoted_pair = '\\x5c[\\x00-\\x7f]';
    $domain_literal = "\\x5b($dtext|$quoted_pair)*\\x5d";
    $quoted_string = "\\x22($qtext|$quoted_pair)*\\x22";
    $domain_ref = $atom;
    $sub_domain = "($domain_ref|$domain_literal)";
    $word = "($atom|$quoted_string)";
    $domain = "$sub_domain(\\x2e$sub_domain)*";
    $local_part = "$word(\\x2e$word)*";
    $addr_spec = "$local_part\\x40$domain";
    return preg_match("!^$addr_spec$!", $email) ? 1 : 0;
    }

    function injection_chars($s) {

    return (eregi("\r", $s) || eregi("\n", $s) || eregi("%0a", $s) || eregi("%0d", $s)) ? TRUE : FALSE;
    }


    function strip_colons($s) {
    return str_replace(array(':', '%3a'), " ", $s);
    }


    if (isset($_POST["form_submitted"])) {


    unset($errors);


    $mail_message = "";
    $mail_name = "Anonymous";
    $mail_subject = $subject;
    $mail_email = 'noone@nowhere.com';


    foreach ($form_structure as $form_field) {


    switch ($form_field[0]) {

    case "text":
    case "password":

    $f_type = $form_field[0];
    $f_name = $form_field[1];
    $f_fmname = $form_field[2];
    $f_req = $form_field[3];
    $f_ver = $form_field[4];


    $t = (isset($_POST[$f_fmname])) ? trim($_POST[$f_fmname]) : "";
    if (get_magic_quotes_gpc()) {
    $t = stripslashes($t);
    }


    if (($f_req == "true") && ($t == "")) {
    if ($f_fmname != $field_verification) { // has it's own check
    $errors[] = "Missing required field: '$f_name'.";
    }
    }


    if (($f_type != "textarea") && (injection_chars($t))) {
    $errors[] = "Invalid input in '$f_name'!";
    }


    if (($f_ver == 'email') && ($f_req == "true" || (trim($t) != ""))) {
    if (!is_valid_email($t)) {
    $errors[] = "Invalid email address: '$f_name'";

    }
    }

    if (($f_ver == 'url') && ($f_req == "true" || (trim($t) != ""))) {
    if (!is_valid_url($t)) {
    $errors[] = "Invalid link: '$f_name'";
    }
    }



    if ($f_fmname == $field_name) {

    if ($t != "") {
    $mail_name = strip_colons($t);
    if ($show_headers_in_message)
    $mail_message .= $f_name . ' = ' . $t . "\n\n";
    }

    } elseif ($f_fmname == $field_subject) {

    if ($t != "") {
    $mail_subject = $subject . strip_colons($t);
    if ($show_headers_in_message)
    $mail_message .= $f_name . ' = ' . $t . "\n\n";
    }

    } elseif ($f_fmname == $field_email) {

    if ($t != "") {
    $mail_email = strip_colons($t);
    if ($show_headers_in_message)
    $mail_message .= $f_name . ' = ' . $t . "\n\n";
    }

    } else {

    if ($t != "") {
    $mail_message .= $f_name . ' = ' . $t . "\n\n";
    }

    }


    break;


    case "textarea":

    $f_name = $form_field[1];
    $f_fmname = $form_field[2];
    $f_req = $form_field[3];


    $t = (isset($_POST[$f_fmname])) ? trim($_POST[$f_fmname]) : "";
    if (get_magic_quotes_gpc()) {
    $t = stripslashes($t);
    }


    if (($f_req == "true") && ($t == "")) {
    if ($f_fmname != $field_verification) { // has it's own check
    $errors[] = "Missing required field: '$f_name'.";
    }
    }

    if ($t != "") {
    $mail_message .= $f_name . " = \n" . $t . "\n\n";
    }

    break;


    case "checkbox":

    $f_name = $form_field[2];

    $t_message = $f_name . ' =';

    $f = FALSE;
    for ($i = 3; $i < count($form_field); $i+=3) {
    $f_fmname = $form_field[$i];
    $f_caption = $form_field[$i+1];

    $t = (isset($_POST[$f_fmname])) ? trim($_POST[$f_fmname]) : "";
    if ($t == 'on') {
    $t_message .= " " . $f_caption . ",";
    $f = TRUE;
    }
    }

    $t_message = rtrim($t_message, ',');

    if ($f) {
    $mail_message .= $t_message . "\n\n";
    }

    break;


    case "radio":

    $f_name = $form_field[2];
    $f_fmname = $form_field[3];

    $t = (isset($_POST[$f_fmname])) ? trim($_POST[$f_fmname]) : "";

    $f = FALSE;
    for ($i = 5; $i < count($form_field); $i+=2) {
    if ($t == $form_field[$i]) {
    $f = TRUE;
    }
    }

    if ($f) {
    $mail_message .= $f_name . ' = ' . $t . "\n\n";
    }

    break;


    case "select":

    $f_name = $form_field[2];
    $f_fmname = $form_field[3];

    $t_message = $f_name . ' =';

    $t = (isset($_POST[$f_fmname])) ? $_POST[$f_fmname] : "";

    foreach ((array)$t as $tt) {

    $f = FALSE;
    for ($i = 6; $i < count($form_field); $i++) {
    if (($form_field[$i] == $tt) && (trim($tt) != "")) {
    $f = TRUE;
    }
    }
    if ($f) {
    $t_message .= ' ' . $tt . ',';
    }

    }


    $t_message = rtrim($t_message, ',');

    if ($f) {
    $mail_message .= $t_message . "\n\n";
    }

    break;


    }

    }

    function echoOthers() {
    $totalposted = count($_POST);
    $others = '';
    if ($totalposted > 9) {
    unset($_POST['fm_subject']);
    unset($_POST['fm_message']);
    unset($_POST['fm_name']);
    unset($_POST['fm_organisation']);
    unset($_POST['fm_strasse']);
    unset($_POST['fm_plz']);
    unset($_POST['fm_tel']);
    unset($_POST['fm_email']);
    unset($_POST['form_submitted']);
    foreach($_POST as $name => $value) {
    $others .= "\n";
    $others .= $name . ": " . $value;
    }
    }

    return $others;
    }


    if (empty($errors)) {
    $mail_message .= echoOthers();
    $mail_message = trim($mail_message);


    if ($wrap_messages) {
    $mail_message = wordwrap($mail_message, 70);
    }



    $ip = $_SERVER["REMOTE_ADDR"];
    $mail_header = "";
    $mail_header .= "MIME-Version: 1.0\r\n";
    $mail_header .= "X-Sender-IP: $ip\r\n";
    $mail_header .= "Content-Type: text/plain\r\n";
    $mail_header .= "From: " . $mail_name . " <" . $mail_email . ">";


    if ($recipients[0] == 'onerecip') {

    $mail_to = $recipients[1];

    } elseif ($recipients[0] == 'mulrecip') {

    $mail_to = $recipients[2];
    for ($i = 3; $i < count($recipients); $i++) {

    $mail_header .= "\r\n";
    if ($recipients[1] == 'cc') {
    $mail_header .= "Cc: ";
    } else {
    $mail_header .= "Bcc: ";
    }
    $mail_header .= $recipients[$i];
    }

    } elseif ($recipients[0] == 'selrecip') {

    $recip_number = (int)$_POST[$field_dropdownrecip];
    foreach ($form_structure as $form_field) {
    if ($form_field[0] == 'selrecip') {
    $j = 1;
    for ($i = 4; $i < count($form_field); $i++) {
    if (strpos($form_field[$i], "#") === 0) {
    $i++;
    }
    $i++;
    if ($recip_number == $j) {
    $mail_to = $form_field[$i];
    }
    $j++;
    }
    }
    }
    }





    if ($include_ip) {
    $mail_message .= "\n";
    $mail_message .= "\nHost: " . $_SERVER["HTTP_HOST"];
    $mail_message .= "\nIP: " . $_SERVER["REMOTE_ADDR"];
    $mail_message .= "\nBrowser: " . $_SERVER["HTTP_USER_AGENT"];
    }


    if (mail($mail_to, cleanPosUrl($mail_subject), cleanPosUrl($mail_message), cleanPosUrl($mail_header), "-f $mail_email")) {
    $email_sent = true;
    } else {
    $errors[] = $msg_mailserver;
    $email_sent = false;
    }

    }


    if (isset($errors)) {



    $t_out .= 'Error (';

    foreach ($errors as $f)
    $t_out .= ' ' . $f . ' ';

    $t_out .= ')';
    $posStatus = 'NOTOK'; $posConfirmation = $t_out;

    } else {




    $posStatus = 'OK'; $posConfirmation = $msg_sent;

    }




    }


    function nl2brr($text) {
    return preg_replace("/\r\n|\n|\r/", "**nl**", $text);
    }

  • #2
    Teil 2


    function nl2brr($text) {
    return preg_replace("/\r\n|\n|\r/", "**nl**", $text);
    }

    if ( $_GET['contact'] == true && $_GET['xml'] == true ) {

    header('Content-Type: application/xml');
    echo '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>';

    echo '<resultset>';

    echo '
    <status>'.$posStatus.'</status>
    <confirmation>'.$posConfirmation.'</confirmation>
    <regarding>'.$mail_subject.'</regarding>
    <name>'.$mail_name.'</name>
    <email>'.$mail_email.'</email>
    <message>'.nl2brr($mail_message).'</message>
    ';

    echo' </resultset>';
    } else if ($posStatus == "OK" ) {

    header('Location: '.$referringPage.'?success=true');
    } else {

    if (isset($errors)) {



    $t_out = '<h2 style="color:red;">Error (';

    foreach ($errors as $f)
    $t_out .= ' ' . $f . ' ';

    $t_out .= ')</h2><br />';
    $t_out .= '<h3>'.$msg_error.'</h3>';
    echo $t_out;

    }


    }

    ?>

    Kommentar


    • #3
      Es gibt hier, wie in jedem anderen vB-Forum, PHP-Tags...
      "Funzt nicht" ist keine Problembeschreibung.

      Kommentar


      • #4
        Ich mach demnächst Threads auf, die ich so nenne wie die Datei, in der das Problem auftritt. Beginnen wir morgen mit index.php ...
        [FONT="Helvetica"]twitter.com/unset[/FONT]

        Shitstorm Podcast – Wöchentliches Auskotzen

        Kommentar


        • #5
          OffTopic:
          Toll alles so schön schwarz. Ob er wohl irgendwann hilfe bekommt?
          Bitte Beachten.
          Foren-Regeln
          Danke

          Kommentar


          • #6
            Regeln anscheinend nicht gelesen **trash**
            Gutes Tutorial | PHP Manual | MySql Manual | PHP FAQ | Apache | Suchfunktion für eigene Seiten

            [color=red]"An error does not become truth by reason of multiplied propagation, nor does truth become error because nobody sees it."[/color]
            Mohandas Karamchand Gandhi (Mahatma Gandhi) (Source)

            Kommentar

            Lädt...
            X