0

I´ve written a little program which is scraping some data from a website with simplehtmldom. It works perfectly on my localhost, but when I upload it to a subdomain of my server it gives an error 500.

I´m doing a submit on the form with a AJAX call and check that with a Submit.php file.

You can have a look at the live Version here: http://vergleich.unlimited-life-team.de You have to put in only numbers in the form fields.

Thanks for your help!

The HTML form

<form id="ecoop-tarifrechner" method="post">
      <div class="col-md-6">
        <div class="form-group">
          <input type="text" class="form-control" name="verbrauchkwh" id="verbrauchkwh" placeholder="Verbrauch des Kunden">
        </div>
      </div>
      <div class="col-md-6">
        <div class="form-group">
          <input type="text" class="form-control" name="plzkunde" id="plzkunde" placeholder="PLZ des Kunden">
        </div>
      </div>
      <div class="col-md-6">
        <div class="form-group">
          <input type="number" class="form-control" name="ecoop_preis_brutto_waerme" id="ecoop_preis_brutto_waerme" step=0.01 placeholder="ecoop brutto Arbeitspreis Wärme">
        </div>
      </div>
      <div class="col-md-6">
        <div class="form-group">
          <input type="number" class="form-control" name="ecoop_preis_brutto" id="ecoop_preis_brutto" step=0.01 placeholder="ecoop brutto Arbeitspreis">
        </div>
      </div>

      <button type="submit" class="btn btn-default">Jetzt vergleichen</button>

    </form>

The AJAX call

$(document).ready(function() {

 $('#ecoop-tarifrechner').submit(function(e) {

 e.preventDefault(); // Prevent Default Submission

$.ajax({
    url: 'submit.php',
    type: 'POST',
    data: $(this).serialize() // it will serialize the form data
  })
  .done(function(data) {
      $('#tarifecheck24').fadeIn('slow').html(data);
  })
  .fail(function() {
    alert('Ajax Submit Failed ...');
  });

 });

});

The submit.php

<?php

/* update your path accordingly */
include_once 'assets/simple_html_dom.php';
include_once 'functions.php';


if( $_POST ){

$verbrauch = $_POST['verbrauchkwh'];
$plz = $_POST['plzkunde'];
$ecoop_preiskwh_waerme = $_POST['ecoop_preis_brutto_waerme'];
$ecoop_preiskwh = $_POST['ecoop_preis_brutto'];
$ecoop_grundpreis = 107.76;

$link = "https://www.check24.de/strom/result/?c24api_zipcode={$plz}&c24api_totalconsumption={$verbrauch}&c24api_customertype=private&c24api_eco=no&c24api_considerdiscounts=no&c24api_maxbonusshare=no&c24api_companyevaluation_positive=75&c24api_guidelinematch=yes&c24api_contractextension=12&c24api_cancellationperiod=30&c24api_contractperiod=12&c24api_paymentperiod=month&c24api_onlinesubscription=no&c24api_priceguarantee=guarantee_price&c24_priceguarantee_months=12&c24api_eco_type=normal&pid=24&c24_from_result_page=1";

$ecoop_kostenjahr = (($ecoop_preiskwh*$verbrauch)/100)+$ecoop_grundpreis;
$ecoop_kostenjahr_waerme = (($ecoop_preiskwh_waerme*$verbrauch)/100)+$ecoop_grundpreis;

// Create DOM from URL
$html = file_get_html($link);

// Find all article blocks
foreach($html->find('.c24-result-row-energy') as $konkurrent) {
  $item['anbieter']   = $konkurrent->find('.c24-provider-logo', 0)->alt;
  $item['tarifname']  = $konkurrent->find('.c24-tariffname', 0)->plaintext;
  $item['preiskwh']  = $konkurrent->find('.c24EnergyPriceLayer tbody tr td', 7)->plaintext;
  $item['grundpreis']  = $konkurrent->find('.c24EnergyPriceLayer tbody tr td', 13)->plaintext;
  $item['gesamtkosten']  = $konkurrent->find('.c24-result-price', 0)->plaintext;
  $item['preisgarantie']  = $konkurrent->find('.c24ResultsTableListBold span', 0)->plaintext;
  $item['vertragslaufzeit']  = $konkurrent->find('.c24-result-informations li span', 5)->plaintext;
  $konkurrenten[] = $item;
}

// var_dump($konkurrenten);

?>

<div class="container">
  <div class="row">
    <table class="table table-striped table-responsive">
        <tr>
            <th>Anbieter</th>
            <th>Stromtarif</th>
            <th>Preis/kWh (brutto/netto)</th>
            <th>Grundpreis/Jahr</th>
            <th>Gesamtkosten/Jahr</th>
            <th>Ersparnis/Jahr</th>
            <th>Preisgarantie</th>
            <th>Vertragslaufzeit</th>
        </tr>
        <tr class="ecoop-blue">
          <td>ecoop</td>
          <td>ecoop Strom</td>
          <td><?= $ecoop_preiskwh ?> (<?= $ecoop_preiskwh_netto ?>) Ct./kWh</td>
          <td><?= $ecoop_grundpreis ?> (<?= $ecoop_grundpreis_netto ?>) €/Jahr</td>
          <td><?= $ecoop_kostenjahr ?> €</td>
          <td></td>
          <td>31.12.2020</td>
          <td>12 Monate 1. Jahr - danach 1 Monat</td>
        </tr>
        <tr class="ecoop-blue">
          <td>ecoop</td>
          <td>ecoop Wärme</td>
          <td><?= $ecoop_preiskwh_waerme ?> (<?= $ecoop_preiskwh_waerme_netto ?>) Ct./kWh</td>
          <td><?= $ecoop_grundpreis ?> (<?= $ecoop_grundpreis_netto ?>) €/Jahr</td>
          <td><?= $ecoop_kostenjahr_waerme ?> €</td>
          <td></td>
          <td>31.12.2020</td>
          <td>12 Monate 1. Jahr - danach 1 Monat</td>
        </tr>

        <? foreach ($konkurrenten as $checked) : ?>
         <tr>
           <td><?= $checked['anbieter']; ?></td>
           <td><?= $checked['tarifname']; ?></td>
           <td><?= $checked['preiskwh']; ?></td>
           <td><?= $checked['grundpreis']; ?></td>
           <td><?= $checked['gesamtkosten']; ?></td>
           <td><?= (priceToDouble($checked['gesamtkosten']))-$ecoop_kostenjahr ?> €</td>
           <td><?= str_replace('Preisgarantie: ', '', $checked['preisgarantie']) ?></td>
           <td><?= str_replace('Vertragslaufzeit: ', '', $checked['vertragslaufzeit']) ?></td>
         </tr>
         <? endforeach; ?>
    </table>
  </div>
</div>


<?php
}
  • 2
    response is 500 then its must be something in your php side .not in ajax call – zabusa May 08 '17 at 10:48
  • 2
    Switch on PHP error reporting so you get an informative error: http://stackoverflow.com/questions/1053424/how-do-i-get-php-errors-to-display – Alex K. May 08 '17 at 10:48
  • Ajax is working properly, check your backend code – RAUSHAN KUMAR May 08 '17 at 10:55
  • What version of PHP is on the server? Before version 5.4 the following was applicable: PHP also allows for short open tag (which is discouraged since it is only available if enabled using the short_open_tag php.ini configuration file directive, or if PHP was configured with the --enable-short-tags option). Furthermore, there is a ?> missing at the end – Gerard May 08 '17 at 10:59
  • is short tags enabled on your live server? – Masivuye Cokile May 08 '17 at 11:01
  • I turned on PHP error reporting and get an error because of the simpledom php file. I can´t figure out why it´s working on localhost and not on a webserver :/ – pascallammers May 08 '17 at 11:29

0 Answers0