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

LVL 5
Neil_BradleyWeb UX/UI DeveloperAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Guy Hengel [angelIII / a3]Billing EngineerCommented:
what is the error/different behavior?
without that, it will be difficult to assist
0
Ray PaseurCommented:
does not work
What is the symptom of failure? Is there a message or a fire under the desk or a zombie attack?
0
Julian HansenCommented:
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.
0
C++ 11 Fundamentals

This course will introduce you to C++ 11 and teach you about syntax fundamentals.

Neil_BradleyWeb UX/UI DeveloperAuthor Commented:
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
0
Ray PaseurCommented:
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!
0
Neil_BradleyWeb UX/UI DeveloperAuthor Commented:
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..
0
Neil_BradleyWeb UX/UI DeveloperAuthor Commented:
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
0
Guy Hengel [angelIII / a3]Billing EngineerCommented:
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
0
Julian HansenCommented:
This should fix it - add the SSL_VERIFYPEER option as FALSE ...
<?php  
ini_set('display_errors',1);
ini_set('display_startup_errors',1);
error_reporting(-1);

function get_data($url) 
{
  $ch = curl_init();
  $timeout = 15;
  
  curl_setopt($ch, CURLOPT_URL, $url);
  curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
  curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE); // <==== ADD THIS
  
  $data = curl_exec($ch);
  if ($data === false) echo "False";
  curl_close($ch);
  return $data;
}

$returned_content = get_data('https://graph.facebook.com/oauth/access_token?grant_type=client_credentials&client_id=REDACTED&client_secret=REDACTED');
$arr = explode('=', $returned_content); 
echo trim($arr[1]);

Open in new window


But also read this article http://snippets.webaware.com.au/howto/stop-turning-off-curlopt_ssl_verifypeer-and-fix-your-php-config/
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Neil_BradleyWeb UX/UI DeveloperAuthor Commented:
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
0
Chris StanyonWebDevCommented:
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
0
Neil_BradleyWeb UX/UI DeveloperAuthor Commented:
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
0
Chris StanyonWebDevCommented:
Hey Neil,

Can't load the 5.3 page :(
0
Guy Hengel [angelIII / a3]Billing EngineerCommented:
get_data => does the web server (with the php 5.3) allow cross domain requests?
0
Julian HansenCommented:
@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
0
Neil_BradleyWeb UX/UI DeveloperAuthor Commented:
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
0
Julian HansenCommented:
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...?
0
Neil_BradleyWeb UX/UI DeveloperAuthor Commented:
I have contacted the server tec's and reported the problem.
I will keep you posted.
Cheers,
N
0
Neil_BradleyWeb UX/UI DeveloperAuthor Commented:
Hi guys,
thanks for all of your comments.
A combination of 2 suggestions helped me resolve the issue.
Cheers,
Neil
0
Julian HansenCommented:
You are welcome Neil - thanks for the points.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
PHP

From novice to tech pro — start learning today.