Link to home
Start Free TrialLog in
Avatar of Neil_Bradley
Neil_BradleyFlag for New Zealand

asked on

PHP 5.3 problem

Hi All,
my code snipped does not work on PHP 5.3. Works perfectly on 5.2 however I may need some help to figure out where the problem lies.
Can anyone assist?
Cheers,
N
<?php
ini_set('display_errors',1); 
 error_reporting(E_ALL);
 include "feed.php";
// declare a default location
$filter="Auckland";
if(isset($_GET['filter'])){$filter=$_GET['filter'];}
if( $filter == "" ) $filter="Auckland";
$now=date( "Hi" );

/* gets the data from a URL */
function get_data($url) {
  $ch = curl_init();
  $timeout = 5;
  curl_setopt($ch, CURLOPT_URL, $url);
  curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
  $data = curl_exec($ch);
  curl_close($ch);
  return $data;
}

$GetTo = get_data('https://tflite.com/takeflitepublicgba/PgFunction.aspx?Func=GetToLocations');
$GetFrom = get_data('https://tflite.com/takeflitepublicgba/PgFunction.aspx?Func=GetToLocations');

		
            
?>
<!doctype html>
<!--[if lt IE 7]> <html class="no-js lt-ie9 lt-ie8 lt-ie7" lang="en"> <![endif]-->
<!--[if IE 7]>    <html class="no-js lt-ie9 lt-ie8" lang="en"> <![endif]-->
<!--[if IE 8]>    <html class="no-js lt-ie9" lang="en"> <![endif]-->
<!--[if gt IE 8]><!--> 
<html class="no-js" lang="en"> <!--<![endif]-->
<head>
	<meta charset="utf-8">
	<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
	<title></title>


</head>
<body >
  <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="get">
      <div class="searchContainer"><label>Select an alternate airport</label>
       <?php
	   $myarray = explode("\n", $GetFrom);
echo " <select name=\"filter\" class=\"field\" id=\"filter\"><option value\"".$filter."\">".$filter."</option>";
foreach ($myarray as  &$value) {
    echo '<option value="'.trim($value).'">'.trim($value).'</option>';
}
echo "</select>";
unset( $value );
	   ?>
        <input type="submit" name="submit" id="submit" value="Go">
      </div>
      </form>

   <div id="status-wrapper">   
   
       
        <div class="status">
          <div class="statusDetail">
            <div class="head arrivals"> <span><?php echo $filter; ?> ARRIVALS</span></div>
       
        
<?php
foreach ($arrivals_xml->flights->flight as $flight) {
	$time=substr( $flight->Scheduled, 0, 2 ).substr( $flight->Scheduled, 3, 2 );
	if( $flight->To == $filter and $time >= $now ){
		$next=$flight;
		break;
	}
}

if( isset( $next ) ){
	// Show flight
	 echo"<div class=\"subhead\"><span class=\"rightcell\">Next arrival from:  - ".$next->From."</span></div>
	
        <div class=\"row\"> <span class=\"leftcell\">Ft No:</span>
				<span class=\"rightcell\">&nbsp;".$next->No."</span></div>
				
				<div class=\"row\"> <span class=\"leftcell\">Gate:</span>
				<span class=\"rightcell\">&nbsp;".$next->Gate."</span></div>
				
                  <div class=\"row\"> <span class=\"leftcell\"> Arrives at:<span></span></span>
				  <span class=\"rightcell\">&nbsp;".$next->Scheduled."</span></div>";
				   
				   if ( $next->Status !="") {  echo"<div class=\"row\"> <span class=\"leftcell\"> Status:<span></span></span>
				  <span class=\"rightcell\">&nbsp;".$next->Status."</span></div>";}
				   
				 
				 if ( $next->Comment !="") { echo"<div class=\"row\"> <span class=\"rightcell\">".$next->Comment."</span></div>";}
         		echo"</div>";
} else {
	// no flight
	echo "<div class=\"subhead\"><span class=\"rightcell\">We have no more flights arriving into ".$filter." today.</span></div>
</div>"; }
	
?>

        </div>
        <div class="status">
          <div class="statusDetail">
            <div class="head departures"> <span><?php echo $filter; ?> DEPARTURES</span></div>
           
<?php
unset( $next );
foreach ($departures_xml->flights->flight as $flight) {
	$time=substr( $flight->Scheduled, 0, 2 ).substr( $flight->Scheduled, 3, 2 );
	if( $flight->From == $filter and $time >= $now ){
		$next=$flight;
		break;
	}
}

if( isset( $next ) ){
	// Show flight
	 echo"<div class=\"subhead\"><span class=\"rightcell\">Next departure to:  - ".$next->To."</span></div>";
	echo "
	 <div class=\"row\"> <span class=\"leftcell\">Ft No:</span>
				<span class=\"rightcell\">&nbsp;".$next->No."</span></div>
				
				<div class=\"row\"> <span class=\"leftcell\">Gate:</span>
				<span class=\"rightcell\">&nbsp;".$next->Gate."</span></div>
				
                  <div class=\"row\"> <span class=\"leftcell\"> Departs at:<span ></span></span>
				  <span class=\"rightcell\">&nbsp;".$next->Scheduled."</span></div>";
				  
				     if ( $next->Status !="") {  echo"<div class=\"row\"> <span class=\"leftcell\"> Status:<span></span></span>
				  <span class=\"rightcell\">&nbsp;".$next->Status."</span></div>";}
				  
				  if ( $next->Comment !="") { echo"<div class=\"row\"> <span class=\"rightcell\">".$next->Comment."</span></div>";}
         echo"</div>";

} else {
	// no flight
	echo "<div class=\"subhead\"><span class=\"rightcell\">We have no more flights leaving ".$filter." today.</span></div>
</div>
	";
}
?>
        </div>
       
        </div>
</body>
</html>

Open in new window

Avatar of Guy Hengel [angelIII / a3]
Guy Hengel [angelIII / a3]
Flag of Luxembourg image

what is the error/different behavior?
without that, it will be difficult to assist
does not work
What is the symptom of failure? Is there a message or a fire under the desk or a zombie attack?
You are also including feed.php in your script - the source for which you have not posted.

As angel and Ray have said too many places for the error to occur and no clue on where it is occuring or how.
Avatar of Neil_Bradley

ASKER

Hi all,
apologies for the info blanks in this question. I will need to put the question on hold while I dig into server configuration problems which may be contributing to the problem.
N
Well, if you want us to help, you just need to tell us the symptom of the problem.  As written this question is like saying, "my car won't run - what's wrong?"  Maybe it is out of gas?  Maybe it's been stolen?  Maybe a wheel fell off?  Could be almost anything!
Understood..
Once again, I am holding back on submitting a revised question until I get to the bottom of server issues which might have caused some of my issues..
Ok, PHP problem take 2.

This code:
  <?php  
  ini_set('display_errors',1<wbr ></wbr>);
ini_set('display_startup_e<wbr ></wbr>rrors',1);<wbr ></wbr>
error_reporting(-1);


  function get_data($url) {
  $ch = curl_init();
  $timeout = 5;
  curl_setopt($ch, CURLOPT_URL, $url);
  curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
  $data = curl_exec($ch);
  curl_close($ch);
  return $data;
}

  $returned_content = get_data('https://graph.fa<wbr ></wbr>cebook.com<wbr ></wbr>/oauth/acc<wbr ></wbr>ess_token?<wbr ></wbr>grant_type<wbr ></wbr>=client_cr<wbr ></wbr>edentials&<wbr ></wbr>client_id=<wbr ></wbr>XXX<wbr ></wbr>40398&clie<wbr ></wbr>nt_secret=<wbr ></wbr>XXX<wbr ></wbr>49b96c4df3<wbr ></wbr>eec0681368<wbr ></wbr>68');
$arr = explode('=', $returned_content); 
echo trim($arr[1]);
?>

Open in new window

can be tested on two servers.
The first (on php 5.2) can be tested here http://gromit.utopia.co.nz/~ballochd/test.php

The second on PHP 5.3 can be tested here http://beaconhilldesign.co.nz/~grovetow/test.php

The code works fine on 5.2 however throws of an error on 5.3. Can anyone help me find a work around so that my code outputs the correct result when being tested on 5.3?
Cheers and apologies for the earlier confusion..
N

(ed.note: My effort to redact the client/secret data seems to have munged the script.  Going forward, it is probably a good idea to keep these kinds of codes "under wraps." ~Ray
can you please put a var_dump($arr); and var_dump($returned_content);
before the echo trim($arr[1]) line?
looks like somehow $arr is not a 1-dimensional array, but 2+ dimension array
ASKER CERTIFIED SOLUTION
Avatar of Julian Hansen
Julian Hansen
Flag of South Africa image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Hi all,
no luck with both solutions unfortunately.
I still get:
Notice: Undefined offset: 1 in /home/grovetow/public_html/test.php on line 20
N
As has already been pointed out, var_dump the returned_content. It appears that your returned content isn't being split into an array (of at least 2 elements) by using the explode() function. Assuming you're not getting the 'False' value echoed out, your get_data() function must be returning some data. Let's have a look at it:

$returned_content = get_data('https://graph.facebook.com/oauth/access_token?grant_type=client_credentials&client_id=REDACTED&client_secret=REDACTED');
var_dump($returned_content);

Open in new window

Run that on both versions and report back with the output
Ok, that's interesting Chris.
Here is the page on php 5.2 using var dump
http://gromit.utopia.co.nz/~cerise/test.php

and here is the same page on php 5.3 using var dump
http://beaconhilldesign.co.nz/~grovetow/test2.php

as you see that data is not getting through on the 5.3 server.
Does this give you any ideas of a work around?
Cheers,
N
Hey Neil,

Can't load the 5.3 page :(
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
@Neil,

Are you sure the SSL_VERIFY did not make a difference. I am able to run your code successfully here on 5.3 - it would not run before - as soon as I added that bit it worked.

I know the recent policy on EE regarding posting of links - the following link is to demonstrate the code posted above works - not as a solution - same code as in this post

Link
http://www.marcorpsa.com/ee/ee28236024.php

As you should see from the above link - runs fine on 5.3
Hi JilianH,
unfortunately not.
It comes up with  Notice:-
Undefined offset: 1 in /home/grovetow/public_html/test2.php on line 24 when I run your code on the 5.3 server.
If it runs ok on your 5.3 then the problem must run deeper. I may need to check with the tec team who run the web server and see if ngelIII's question is the cause of the problem.
Cheers,
Neil
unfortunately not.
It comes up with  Notice:-
In your code or the link I posted?
The link I posted works fine - so obviously something else on your server - but not related to 5.3...?
I have contacted the server tec's and reported the problem.
I will keep you posted.
Cheers,
N
Hi guys,
thanks for all of your comments.
A combination of 2 suggestions helped me resolve the issue.
Cheers,
Neil
You are welcome Neil - thanks for the points.