Skip to content
Advertisement

Simple Html Dom library works on local server but not in mostly live server

I am using curl for web scraping and to parse html used simple html dom library which is great and simple. But my main problem is that this library works smoothly on local server but not in live server. Strange thing is that it can work on 000webhost hosting without any issue, but when I use other paid hosting like godaddy,namecheap etc.

Paid Hostinger plan also not support. I contacted to godaddy support and they said you need to contact your developer thats not hosting issue.

I searched a lot on internet and found that I need to enable php extension ‘mbstring’, but same issue.

When I search the data it give me empty array like ‘Array’. I try everything but can not get any solution and also not get whats the issue with that.

<?php

error_reporting(0);

                    
                    if (isset($_POST['submit'])) 
                    {
                        $search = $_POST['cnic'];
                        if (strlen($search) < 12) 
                        {
                          $search = substr($search, 1);
                        }
                        
                        $url = "https://allcstech.com/tele/search-result.php";
                        $ch = curl_init();
                        curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
                        curl_setopt($ch, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']);
                        curl_setopt($ch, CURLOPT_TIMEOUT, 40);
                        curl_setopt($ch, CURLOPT_COOKIEFILE, "cookie.txt");
                        curl_setopt($ch, CURLOPT_URL, $url);
                        curl_setopt($ch, CURLOPT_POSTFIELDS, "cnnum=$search");
                        $html = curl_exec($ch);
                                
                                include 'dfapi/simple_html_dom.php';
            $dom = new simple_html_dom();
            $dom->load($html);
            
            $firstname = $dom->find('td',3);
            
            $lastname = $dom->find('td',5) ;
            
            $cnic = $dom->find('td',7);
            
            $number = $dom->find('td',1);
            $mod = "<strong>0</strong>".$number;
            
            $address = $dom->find('td',9);
            
            // $address1 = $dom->find('#address1',0);

            // $city = $dom->find('#city',0);

            if(!empty($firstname)||!empty($fullname)||!empty($lastname)||!empty($cnic)||!empty($number)||!empty($number))
            {
                
            }
            else
            {
                $msg = "No record Found";
            }
            

            foreach($dom->find('table') as $e)
              $otherdata = $e;
            $otherdata1 = $dom->find('table',1);
            
}
                    
?>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>DataFinder</title>
    <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
</head>
<style>
    @font-face { font-family: Jameel Noori Nastaleeq; src: url('Jameel Noori Nastaleeq.ttf'); } 
    img[src*="https://cdn.000webhost.com/000webhost/logo/footer-powered-by-000webhost-white2.png"] {
display: none;}
body {
  font-family: Arial;
}

* {
  box-sizing: border-box;
}

table
{
  color: white;
  text-transform: capitalize;
}
td
{
  text-align: right;
  margin-left: 20px;
}

form.example input[type=number] {
  padding: 10px;
  font-size: 17px;
  border: 1px solid grey;
  float: left;
  width: 80%;
  background: #f1f1f1;
}

form.example button {
  float: left;
  width: 20%;
  padding: 10px;
  background: #2196F3;
  color: white;
  font-size: 17px;
  border: 1px solid grey;
  border-left: none;
  cursor: pointer;
}

form.example button:hover {
  background: #0b7dda;
}

form.example::after {
  content: "";
  clear: both;
  display: table;
}

/* Hide HTML5 Up and Down arrows. */
input[type="number"]::-webkit-outer-spin-button, input[type="number"]::-webkit-inner-spin-button {
    -webkit-appearance: none;
    margin: 0;
}
 
input[type="number"] {
    -moz-appearance: textfield;
}
#alert { font-family: Jameel Noori Nastaleeq, sans-serif;color: #fff }
</style>

<script>
    $(document).ready(function() {
        $("#hide").hide();
        $("#again").hide();
        $("#show").click(function() {
            $("#hide").show();
            $("#show").hide();
            $("#again").show();
        });
        $("#show").click(function() {
            $("#hide").show();
        });
        $("#again").click(function() {
            $("#hide").hide();
            $("#again").hide();
            $("#show").show();
        });
        
    });
</script>
<body style="background-color: orange">

    <div class="container mt-2">

        <span id="alert"><span id="again" style="cursor: pointer;"> (Hide this) </span> <span id="show" style="cursor: pointer;">...</span>ڈیٹافائنڈر گورنمنٹ کی طرف سے بلیک لسٹ میں ڈالا  <span id="hide">گیا،جس کی وجہ سے ہمیں سرور میں وی پی این لگانا پڑا،وی پی این کی وجہ سے ڈیٹا سرچ میں ٹائم لگ سکتا ہے۔کسی بھی نمبر یا آئی ڈی کارڈ کا ڈیٹآ دو یا تین مرتبہ سرچ کرنے سے شو نہ ہو تو مطلب اس کا ڈیٹا نہیں ہے۔  </span></span>

        <form action="numdb.php" method="post" class="example">

          <input type="number" placeholder="03xxxxxxxxx" name="cnic" autocomplete="off" minlength="10" value="<?php if(isset($_POST['submit'])) echo $_POST['cnic']; ?>">
          <button type="submit" name="submit"><i class="fa fa-search"></i></button>
    
        </form>
        <?php echo $msg; ?>

        <div class="mt-4">
            <strong class="float-left text-white">Name:</strong>
            <span class="float-right text-white"><?php echo $firstname." ".$lastname." ".$fullname; ?></span>
            <br><br>
            <strong class="float-left text-white">CNIC:</strong>
            <span class="float-right text-white"><?php echo $cnic; ?></span>
            <br><br>
            <strong class="float-left text-white">Number:</strong>
            <span class="float-right text-white"><?php echo $mod; ?></span>
            <br><br>
            <strong class="float-left text-white">Address:</strong>
            <span class="float-right text-white"><?php echo $address." ".$address1." ".$city; ?></span>
            <br><br><br>
            
                <!--<center>-->
                <!--    <br>-->
                <!--    <h3 style="width: 100%;height: 30px;color: white;background-color: orange;display: block;">Possible Data</h3>-->
                <!--    <br>-->
                <!--</center>-->
            

            <strong><?php echo $otherdata; ?></strong>
            <br><br>
            <hr>
    <strong><?php echo $otherdata1; ?></strong>
        </div>
        

    </div>

<center>
    <div style="color: white;size: 15px;margin: 10px">
      <span>
        Install DataFinder Application and Get a lot other services like:
      </span>
      <ul>
        <li>Family Tree</li>
        <li>Cnic Copy</li>
        <li>Live Location</li>
        <li>Call History</li>
        <li>IMEI Tracing</li>
        <span>Its paid service and you need to purchase registration and get 24/7 customer support</span>
      </ul>
    </div>

    <h4><a href="href="https://play.google.com/store/apps/details?id=com.darkcoderz.datafinderService"">Download DataFinder</a></h4></center>

    
</body>
</html>```

Advertisement

Answer

Try below curl settings, I think the problem is curl instead of html_simple_dom.

    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
    curl_setopt($ch, CURLOPT_TIMEOUT, 40);
    curl_setopt($ch, CURLOPT_POSTFIELDS, "cnnum=$search");
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
    curl_setopt($ch, CURLOPT_HEADER, false);
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
    $html = curl_exec($ch);

    curl_close($ch);
User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement