Coding error or Security Certificate Issue?

Hi folks,

a few days back, we enabled SSL on our office server and the intranet migrated to https. Everything is ok on the intranet.

On the public internet, we noticed today that the page on our website, which connects to our office server to fetch and display data was throwing an error, which I presumed was a Security Certificate issue… An area that’s like the Dark Side of the Moon for me…

the webpage - Live Connections - We place People First - List of Cream Jobs, Top Jobs, Hot Jobs

Anycase, the internet was willing to help and so I updated the code to a curl function. The Data is not displaying still…

However, when I try to access the office server by loading the php page in my localhost, the data is displayed.

Here’s the code… where am i going wrong ?

<?php 
	//error_reporting(E_ERROR | E_PARSE | E_ALL);
	//$cpg="jobs-listing";
?>
<header class="section background-livec text-center">
            <h3 class="text-white margin-bottom-0 text-size-40 text-thin text-line-height-1">Current & Hot Jobs</h3>
        </header>
<?php 
	$industry = $_GET['industry'];
	$location = $_GET['location'];
	$expMin = $_GET['expMin'];
	$expMax = $_GET['expMax'];
	$sortBy = $_GET['sortBy'];
	$cpg    = $_GET['page'];
	
	if(empty($cpg) || $cpg==1)
		$npl = 1;
	else {
		//$npl = (($cpg+1)*10) - 9;
		$npl = $_GET['startingRowNo'];
	}

	$industry = str_replace(' ', '%20', $industry);
	$location = str_replace(' ', '%20', $location);
	

	$url = "http://xxx.xxx.xxx.xxx/LCWebService/rest/";
	function file_get_contents_curl($url) {
	$ch = curl_init();
	curl_setopt($ch, CURLOPT_HEADER, 0);
	curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); //Set curl to return the data instead of printing it to the browser.
	curl_setopt($ch, CURLOPT_URL, $url);
	$data = curl_exec($ch);
	curl_close($ch);
	return $data;
	}

	if(!empty($sortBy)) { 
		$json = file_get_contents_curl($url.'getHeadersBySearch?industry='.$industry.'&location='.$location.'&expMin='.$expMin.'&expMax='.$expMax.'&sortBy='.$sortBy.'&startingRowNo='.$npl.'&noOfRows=1000000');
		$data = json_decode($json);
	} else if(!empty($industry) || !empty($location) || !empty($expMin) || !empty($expMax)) {
		$json = file_get_contents_curl($url.'getHeadersBySearch?industry='.$industry.'&location='.$location.'&expMin='.$expMin.'&expMax='.$expMax.'&sortBy=&startingRowNo='.$npl.'&noOfRows=1000000');
		$data = json_decode($json);
	} else {	
		//$json = file_get_contents_curl($url.'getOnlineWebPosting');
		$json = file_get_contents_curl($url.'getHeadersBySearch?industry='.$industry.'&location='.$location.'&expMin='.$expMin.'&expMax='.$expMax.'&sortBy=&startingRowNo='.$npl.'&noOfRows=1000000');
		$data = json_decode($json);
		echo 'Data : ' . $data;
	//if (!$data) echo "Data Not Found" ;
	}

	if($sortBy=='DESC' || $sortBy=='') {
		$aclass = 'down_arrow';
	} else {
		$aclass = 'up_arrow';
	}
	$json2 = file_get_contents_curl($url.'getSearchData');
	$data2 = json_decode($json2);

	$industry = str_replace('%20', ' ', $industry);
	$location = str_replace('%20', ' ', $location);
	if($industry=='F amp A - BPO') {
		$industry = 'F & A - BPO';
	}	
	if($industry=='OIL amp GAS') {
		$industry = 'OIL & GAS';
	}
?>
        

<div class="section background-white"> 

	<div class="background-white"> 
	<p class="text-padding-bot text-letter-spacing1">A cross-section of Jobs currently available. We recommend you to contact our Executives for further info. <br />
	More details available when the Job is '<strong>View'</strong>ed. </p>
	</div>

<?php 
//$data='';
if($data!=''){ ?> 

		<?php //if ($checkyear>2017) { ?>

        <div class="subJobs">
        	<ul>
        	    	<li> Industry <br /> 
        	        	<select name="industry" id="industry" class="sel">
			            	<option value="">Select Industry Name</option>
					<?php for($i=0; $i<count($data2[0]); $i++) { ?>
						<?php if(isset($industry) && $industry==$data2[0][$i]) { ?>
							<option selected value="<?php echo $data2[0][$i];?>"><?php echo $data2[0][$i];?></option>
						<?php } else { ?>
							<option value="<?php echo $data2[0][$i];?>"><?php echo $data2[0][$i];?></option>
						<?php } 
					} ?>
		        	</select>                    
                    	</li>
		        <li>Location<br /> 
		        	<select name="city" id="city" class="sel">
				    	 <option value="">Select City Name</option 
					><?php $m=0; for($j=0; $j<count($data2[1]); $j++) { ?>
						<?php $locat = explode(",",$location); ?>
						<?php if($locat[$m]!="" && $locat[$m]==$data2[1][$j]) { ?>
							<option selected value="<?php echo $data2[1][$j];?>"><?php echo $data2[1][$j];?></option>
						<?php ++$m; } else { ?>
							<option value="<?php echo $data2[1][$j];?>"><?php echo $data2[1][$j];?></option>
						<?php } 
					} ?>
				</select>
		        </li>
		       <li>Experience <br /> 
			       <select name="minyear" class="sel2" id="minyear">
			       	    <option value="">Min</option>
				    <?php for($ii=0; $ii<46; $ii++) { ?>
					<?php if($expMin!="" && $expMin==$ii) { ?>
						<option selected value="<?php echo $ii; ?>"><?php echo $ii; ?></option>
					<?php } else { ?>
				    		<option value="<?php echo $ii; ?>"><?php echo $ii; ?></option>
				    	<?php } 
				    } ?>
			       </select>
			       <select name="maxyear" class="sel2" id="maxyear" onchange="return select_max();">
			       	    <option value="">Max</option>
				    <?php for($ii=0; $ii<51; $ii++) { ?>
					<?php if($expMax!="" && $expMax==$ii) { ?>
						<option selected value="<?php echo $ii; ?>"><?php echo $ii; ?></option>
					<?php } else { ?>
				    		<option value="<?php echo $ii; ?>"><?php echo $ii; ?></option>
				    	<?php } 
				    } ?>
			       </select>
			       <!-- select name="" class="sel2" id="sort">
					<option value="">Select</option>
					<option value="ASC">ASC</option>
					<option value="DESC">DESC</option>
			       </select -->		       
		       </li>
               <li class="ser"><button type="button" onclick="search_by_category()" class="btn btn-default" style="margin-top:25px;"><i class="fa fa-search"></i> Search</button></li>
            </ul>
        </div>
       <!-- Selected Jobs Headline Info -->
		<div class="line">
			<p class="text-dark text-center text-size-16">
			<?php if($industry) echo 'Showing ' .  '<b>' . $industry .'</b>' .  ' Jobs' ; ?>  
			<?php if($location) echo ' at ' .  '<b>' . $location .'</b>' ; ?>
			<?php if($expMin) echo ' with Min ' .  '<b>' . $expMin .'</b>' ; ?>
			<?php if($expMax) echo ' to Max '.  '<b>' . $expMax.'</b>' ; ?>
			<?php if($expMin | $expMax) echo ' Years Experience' ;?>
			</p>
	</div>  

       <!-- Jobs Table -->
        <table id="example" class="display" cellspacing="0" width="100%">
            <thead>
              <tr>
                <th class="jobs_noshow text-center" width="5%">S.No</th>
                <th class="text-center" width="15%">Posted On</th>
                <th class="text-center" width="30%">Job Title</th>
                <th class="jobs_noshow text-center" width="15%">Level</th>
                <th class="jobs_noshow text-center" width="15%">Location</th>
                <th class="jobs_noshow text-center" width="15%">Job Code</th>
                <th class="text-center" width="5%">Action</th>
              </tr>
            </thead>
            <tbody>
              <?php $ri=1; foreach($data as $kk=>$d) { ?>
				  <?php  
					$date_posted = $d->postedDate; // get the Posted Date
					$date_posted_year=date("Y",strtotime($date_posted)); // Get the Year from the date and store in a variable
					//if ($date_posted_year>$jobs_restrict_year) { // Show only Jobs posted after this year ?>
					  <tr>
						<td class="jobs_noshow text-center"><?php echo $ri; ?></td>
						<td class="text-center"><?php echo $d->postedDate; ?></td>
						<td><?php echo $d->title; ?></td>
						<td class="jobs_noshow  ctext notreq"><?php echo $d->level; ?></td>
						<td class="jobs_noshow text-center notreq"><?php echo $d->location; ?></td>
						<td class="jobs_noshow  text-center"><?php echo $d->requirementID; ?></td>
						<td class="text-center"><a class="button background-livec border-radius text-white" style="color:white" data-fancybox="ajax" href="?contentid=jobs-detail&requirementID=<?php echo $d->requirementID; ?>&requirementSeqNo=<?php echo $d->requirementSeqNo; ?>" data-type="ajax">View</a></td>
					  </tr>
				  <?php // } ?>
              <?php $ri=$ri+1; } ?>
            </tbody>
          </table>
          <script type="text/javascript">
			$(document).ready(function () {
				var table = $('#example').DataTable( {
					"pageLength": 25,
					"sPaginationType":"full_numbers",
					"oLanguage": {
					"sInfo": 'Showing _START_ to _END_ of _TOTAL_ Jobs.',
					"sInfoEmpty": '',
					"sEmptyTable": "No Jobs found currently",
					}
				}); 
				$('#example').removeClass( 'display' ).addClass('table table-striped table-bordered');
			});
   		  </script>
          <style> .dataTables_filter { display: none; } </style>
          <!-- End of Table -->
 </div>      
<?php } else { ?>
<div style="margin: 20px 0 40px 0px;height:200px;text-align:center;">
<h1 style="font-size:16px;">Server is unavailable at the moment. Please try after some time.</h1>
</div>
<?php }?>     
  
</div>


<!--jobs end-->
<script type="text/javascript">
	function search_by_category() {
		industry	= $('#industry option:selected').val();
		//city1		= $('#city option:selected').val();
		minyear		= $('#minyear option:selected').val();
		maxyear		= $('#maxyear option:selected').val();
		//sortBy		= $('#sort option:selected').val();
		var city = $('select#city').val();
		var cur_pg = "<?php echo $cpg; ?>";
		var tot = "<?php echo $total; ?>";
		var tot_pgs = Math.ceil(tot/25);
		//if(cur_pg=="")
			cur_pg = 1;
		var last_pg = tot_pgs - cur_pg;
		if(last_pg==0)
			records = tot - ((tot_pgs -1) * 25);
		else
			records = 25;

		var strt_val = ((cur_pg-1) * 25) + 1; 
		
		if(industry=='F & A - BPO')
			industry ='F amp A - BPO';
		if(industry=='OIL & GAS')
			industry ='OIL amp GAS';
		city1 = document.getElementById("city").value;
		if(city1=="" || city1=="null") {
			city="";
		}		
		if(industry!="" || city!="" || minyear!="" || maxyear!="") {
			location.href="hotjobs.php?contentid=hotjobs&industry="+industry+"&location="+city+"&expMin="+minyear+"&expMax="+maxyear+"&sortBy=&startingRowNo=1"+"&noOfRows="+records+"&page="+cur_pg;
		} else {
			//alert("Please select any one of the fields");
			location.href="hotjobs.php?contentid=hotjobs&industry="+industry+"&location="+city+"&expMin="+minyear+"&expMax="+maxyear+"&sortBy=&startingRowNo=1"+"&noOfRows="+records+"&page="+cur_pg;
		}
	}
	function sort_by_location() {
		var order = '<?php echo $sortBy; ?>';
		industry	= $('#industry option:selected').val();
		city		= $('#city option:selected').val();
		minyear		= $('#minyear option:selected').val();
		maxyear		= $('#maxyear option:selected').val();
		city1 = document.getElementById("city").value;
		if(industry=='F & A - BPO')
			industry ='F amp A - BPO';
		if(industry=='OIL & GAS')
			industry ='OIL amp GAS';
		if(city1=="") {
			city="";
		} else {
			city = $('select#city').val();
		}
		if(order=="" || order=="DESC") {
			location.href="hotjobs.php?contentid=hotjobs&industry="+industry+"&location="+city+"&expMin="+minyear+"&expMax="+maxyear+"&sortBy=ASC"+"&startingRowNo=1&noOfRows=10";
		} else {
			location.href="hotjobs.php?contentid=hotjobs&industry="+industry+"&location="+city+"&expMin="+minyear+"&expMax="+maxyear+"&sortBy=DESC"+"&startingRowNo=1&noOfRows=10";
		}
	}

	function select_max() {
		minyear = document.getElementById("minyear").value;
		maxyear = document.getElementById("maxyear").value;
		if(parseInt(maxyear)>=parseInt(minyear)) {
			return true;
		} else {
			if(maxyear!="") {
				alert("Maximum year must be equal or greater than minimum year");
				$('#maxyear').val("");
				return false;
			}
		}
	}
	
</script>

The data as seen when accessed on my localhost

Can you make a few changes to your function so that we can debug your code?

function file_get_contents_curl($url) {
	echo 'The URL for CURL: ' . $url;
	$ch = curl_init();
	if($ch === false) {
		echo '$ch is false. init error!';
	}
	curl_setopt($ch, CURLOPT_HEADER, 0);
	curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); //Set curl to return the data instead of printing it to the browser.
	curl_setopt($ch, CURLOPT_URL, $url);
	$data = curl_exec($ch);
	if($data === false) {
		echo '$data === false. curl_exec error!';
	}
	echo '<pre>' . print_r(curl_getinfo($ch), true) . '</pre>';
	curl_close($ch);
	return $data;
}

You could also try this option:

curl_setopt($ch,CURLOPT_SSL_VERIFYPEER, false);

Thanks… wildo tonight when I reach home.

frankbeen> here is the output … for security reasons I’ve shaded out the URL

The URL for CURL: http://xxx.xxx.xxx.xxx:8081/LCWebService/rest/getHeadersBySearch?industry=&location=&expMin=&expMax=&sortBy=&startingRowNo=1&noOfRows=1000000$data === false. curl_exec error!

Array
(
    [url] => http://xx.xxx.xxx.xxx;8081/LCWebService/rest/getHeadersBySearch?industry=&location=&expMin=&expMax=&sortBy=&startingRowNo=1&noOfRows=1000000
    [content_type] => 
    [http_code] => 0
    [header_size] => 0
    [request_size] => 0
    [filetime] => -1
    [ssl_verify_result] => 0
    [redirect_count] => 0
    [total_time] => 0.223812
    [namelookup_time] => 0.000227
    [connect_time] => 0
    [pretransfer_time] => 0
    [size_upload] => 0
    [size_download] => 0
    [speed_download] => 0
    [speed_upload] => 0
    [download_content_length] => -1
    [upload_content_length] => -1
    [starttransfer_time] => 0
    [redirect_time] => 0
    [redirect_url] => 
    [primary_ip] => 
    [certinfo] => Array
        (
        )

    [primary_port] => 0
    [local_ip] => 
    [local_port] => 0
)

Data : The URL for CURL: https://xx.xxx.xxx.xxx/LCWebService/rest/getSearchData$data === false. curl_exec error!

Array
(
[url] => https://xx.xxx.xxx.xxx/LCWebService/rest/getSearchData
[content_type] =>
[http_code] => 0
[header_size] => 0
[request_size] => 0
[filetime] => -1
[ssl_verify_result] => 18
[redirect_count] => 0
[total_time] => 0.452527
[namelookup_time] => 3.7E-5
[connect_time] => 0.208941
[pretransfer_time] => 0
[size_upload] => 0
[size_download] => 0
[speed_download] => 0
[speed_upload] => 0
[download_content_length] => -1
[upload_content_length] => -1
[starttransfer_time] => 0
[redirect_time] => 0
[redirect_url] =>
[primary_ip] => xx.xxx.xxx.xxx
[certinfo] => Array
(
)

[primary_port] => 443
[local_ip] => 167.99.238.135
[local_port] => 60708

)

Well, I removed all the other code and made it simple… Removed the curl function and reverted to file_get_contents. Still, the data is not displayed. But weirdly, loading the page on my localhost shows the data :innocent:

<?php 
	$url = "http://xx.xx.xx.xxx:8081/LCWebService/rest/getHeadersBySearch?startingRowNo=25&noOfRows=25";
	$x = file_get_contents($url);
		$data = json_decode($x);
		echo 'Data : ' . $data;
	
?>
       <!-- Jobs Table -->
        <table id="example" class="display" cellspacing="0" width="100%">
            <thead>
              <tr>
                <th class="jobs_noshow text-center" width="5%">S.No</th>
                <th class="text-center" width="15%">Posted On</th>
                <th class="text-center" width="30%">Job Title</th>
                <th class="jobs_noshow text-center" width="15%">Level</th>
                <th class="jobs_noshow text-center" width="15%">Location</th>
                <th class="jobs_noshow text-center" width="15%">Job Code</th>
                <th class="text-center" width="5%">Action</th>
              </tr>
            </thead>
            <tbody>
              <?php $ri=1; foreach($data as $kk=>$d) { ?>
				  <?php  
					$date_posted = $d->postedDate; // get the Posted Date
					$date_posted_year=date("Y",strtotime($date_posted)); // Get the Year from the date and store in a variable
					//if ($date_posted_year>$jobs_restrict_year) { // Show only Jobs posted after this year ?>
					  <tr>
						<td class="jobs_noshow text-center"><?php echo $ri; ?></td>
						<td class="text-center"><?php echo $d->postedDate; ?></td>
						<td><?php echo $d->title; ?></td>
						<td class="jobs_noshow  ctext notreq"><?php echo $d->level; ?></td>
						<td class="jobs_noshow text-center notreq"><?php echo $d->location; ?></td>
						<td class="jobs_noshow  text-center"><?php echo $d->requirementID; ?></td>
						<td class="text-center"><a class="button background-livec border-radius text-white" style="color:white" data-fancybox="ajax" href="?contentid=jobs-detail&requirementID=<?php echo $d->requirementID; ?>&requirementSeqNo=<?php echo $d->requirementSeqNo; ?>" data-type="ajax">View</a></td>
					  </tr>
				  <?php // } ?>
              <?php $ri=$ri+1; } ?>
            </tbody>
          </table>
Sponsor our Newsletter | Privacy Policy | Terms of Service