justlukeyou Posted February 3, 2011 Author Share Posted February 3, 2011 Parse error: syntax error, unexpected $end in /homepages/1/d179449150/htdocs/(domain)/ProductFeed/phpfeed.php on line 59 Its an end error but its just a standard end which I have used a few times before. Does anything interfere with end tags? Quote Link to comment https://forums.phpfreaks.com/topic/226445-php5-security-block/page/2/#findComment-1169592 Share on other sites More sharing options...
BlueSkyIS Posted February 3, 2011 Share Posted February 3, 2011 it usually means that you are missing at least one closing curly bracket, } i suggest that you indent your code so that the structure is more clear and you can more easily see where the } is missing. Quote Link to comment https://forums.phpfreaks.com/topic/226445-php5-security-block/page/2/#findComment-1169601 Share on other sites More sharing options...
justlukeyou Posted February 3, 2011 Author Share Posted February 3, 2011 Im pretty sure it comes from this, I need to place an ending to this but wherever I place brings up the error I had "No such file or directory". I have tried placing it in around 5 places. Do I need to close off a certain section which looks up where the file is and reads it? { print 'Could not open xml file'; Quote Link to comment https://forums.phpfreaks.com/topic/226445-php5-security-block/page/2/#findComment-1169608 Share on other sites More sharing options...
BlueSkyIS Posted February 3, 2011 Share Posted February 3, 2011 if there is a { anywhere, there must be a } somewhere later. Quote Link to comment https://forums.phpfreaks.com/topic/226445-php5-security-block/page/2/#findComment-1169615 Share on other sites More sharing options...
btherl Posted February 3, 2011 Share Posted February 3, 2011 The solution is to indent your code consistently. Every time you use a "{", increase the indent. Every time you use a "}", decrease the indent. Then it will be obvious where one is missing. Quote Link to comment https://forums.phpfreaks.com/topic/226445-php5-security-block/page/2/#findComment-1169621 Share on other sites More sharing options...
justlukeyou Posted February 3, 2011 Author Share Posted February 3, 2011 Thanks, I have done that, I have tried placing it everywhere between the opening { and next opening { but its keeps coming up with error that the file cannot be found. The two opening { do have closing which work but closing the { print opening creates the error that file cant found which means I back to square one. { print 'Could not open xml file' ; file_put_contents($filename, file_get_contents($xml)); $url_contents = file_get_contents($url);if ($url_contents === false) { die("file_get_contents($url) failed");}if ($url_contents === '') { die("file_get_contents($url) returned no data");}$retval = file_put_contents($filename, $url_contents);if ($retval === false) { die("file_put_contents($filename) failed");} $xmlReader->open($filename); while ($xmlReader->read()) { switch ($xmlReader->name) { Quote Link to comment https://forums.phpfreaks.com/topic/226445-php5-security-block/page/2/#findComment-1169627 Share on other sites More sharing options...
justlukeyou Posted February 3, 2011 Author Share Posted February 3, 2011 Sorry to reply to my own post but it is now creating new XML feed in the same folder as my php script. but it is blank. I take that it means it is creating the XML file but not reading the information from the existing file. My long term objective is to automatically create an XML file from a feed but I whilst I am learning I am putting a test XML file on my own server which I copy into a different folder and then insert that information into a database. I can echo content from my database its just a matter of bloody putting data into the database from an XML feed. Quote Link to comment https://forums.phpfreaks.com/topic/226445-php5-security-block/page/2/#findComment-1169633 Share on other sites More sharing options...
btherl Posted February 4, 2011 Share Posted February 4, 2011 This is the kind of indenting I mean: { print 'Could not open xml file' ; $url_contents = file_get_contents($url); if ($url_contents === false) { die("file_get_contents($url) failed"); } if ($url_contents === '') { die("file_get_contents($url) returned no data"); } $retval = file_put_contents($filename, $url_contents); if ($retval === false) { die("file_put_contents($filename) failed"); } $xmlReader->open($filename); while ($xmlReader->read()) { switch ($xmlReader->name) { Quote Link to comment https://forums.phpfreaks.com/topic/226445-php5-security-block/page/2/#findComment-1169706 Share on other sites More sharing options...
justlukeyou Posted February 5, 2011 Author Share Posted February 5, 2011 Hi, I have tried this again but it is still coming up with the same error: failed to open stream: No such file or directory Can anyone please help me with this. I have read that some servers block "file_get_contents" so I emailed my hosting company and they told me that it should work but I still cant get it to work. Is it possible that my server is set up differently? I dont know why it keeps saying failing to open the stream other than some form of security block. mysql_connect("$host", "$username", "$password")or die("no connection"); mysql_select_db("$db_name")or die("Database Connection Error"); $xmlReader = new XMLReader(); $filename = "datafeed_98057.xml"; print $_SERVER['DOCUMENT_ROOT']; if(!$xml = file_get_contents('/path/to/datafeed_98057.xml')) { print 'Could not open xml file' ; $url_contents = file_get_contents($url); if ($url_contents === false) { die("file_get_contents($url) failed"); } if ($url_contents === '') { die("file_get_contents($url) returned no data"); } $retval = file_put_contents($filename, $url_contents); if ($retval === false) { die("file_put_contents($filename) failed"); } $xmlReader->open($filename); while ($xmlReader->read()) { switch ($xmlReader->name) { case 'product': $dom = new DOMDocument(); $domNode = $xmlReader->expand(); $element = $dom->appendChild($domMode); $domString = utf8_encode($dom->saveXML($element)); $product = new SimpleXMLElement($domString); $awImage = $product->image; //insert query if(strlen($image) > 0) { $query = mysql_query("REPLACE INTO productfeed (image) VALUES ('$awImage')"); echo $awImage . "has been inserted </br>"; } break; } } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/226445-php5-security-block/page/2/#findComment-1170204 Share on other sites More sharing options...
BlueSkyIS Posted February 5, 2011 Share Posted February 5, 2011 this is probably not the actual path to the datafeed: '/path/to/datafeed_98057.xml' there is probably no directory /path/, nor /path/to/ what is the actual path to the datafeed on the server? Quote Link to comment https://forums.phpfreaks.com/topic/226445-php5-security-block/page/2/#findComment-1170292 Share on other sites More sharing options...
justlukeyou Posted February 5, 2011 Author Share Posted February 5, 2011 Hi, The XML file is in my root folder. The hosting company has actually come back to me as said I should add a php.ini file and add "allow_url_fopen = On" But I thought the whole purpose of this code is to not use that as it switches on the PHP 5 security block. Quote Link to comment https://forums.phpfreaks.com/topic/226445-php5-security-block/page/2/#findComment-1170319 Share on other sites More sharing options...
JonnoTheDev Posted February 5, 2011 Share Posted February 5, 2011 The XML file is in my root folder. $xml = file_get_contents('datafeed_98057.xml'); Quote Link to comment https://forums.phpfreaks.com/topic/226445-php5-security-block/page/2/#findComment-1170328 Share on other sites More sharing options...
BlueSkyIS Posted February 5, 2011 Share Posted February 5, 2011 The hosting company has actually come back to me as said I should add a php.ini file and add "allow_url_fopen = On" But I thought the whole purpose of this code is to not use that as it switches on the PHP 5 security block. I think we already touched on this on page one of this thread: If the default is changed to off to improve security why is it best to change it to on? your script needs it to be on. if you don't want your script to work, leave it off. Quote Link to comment https://forums.phpfreaks.com/topic/226445-php5-security-block/page/2/#findComment-1170330 Share on other sites More sharing options...
justlukeyou Posted February 5, 2011 Author Share Posted February 5, 2011 But the page I found said that you should leave that off and use another method. You can read pages on your own server without having that on. Switching it on cases the purposes of PHP 5 switching it off. Quote Link to comment https://forums.phpfreaks.com/topic/226445-php5-security-block/page/2/#findComment-1170340 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.