Jump to content

PHP5 Security Block!!


justlukeyou

Recommended Posts

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'; 

Link to comment
Share on other sites

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)

{

Link to comment
Share on other sites

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.

 

 

Link to comment
Share on other sites

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)
    {

Link to comment
Share on other sites

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;
}
}
}
?>

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.