0

I have a website homepage that is static. There is a separate blog hosted on Wordpress on the same domain (at /blog). Six years ago, I asked a friend for help with displaying two recent posts from the blog on the homepage, and he did that by:

  1. Changing the homepage from index.html to .php

  2. included the following code in index.php

                        function blog()
                        {
                            $url = 'MysiteURL.com/blog/feed/';
                            $xmlinfo = simplexml_load_file($url);
                            if($xmlinfo)
                            {
    
                                $temp=$xmlinfo->channel->item;
                                $i=0;
                                foreach ($temp as $key) 
                                {
                                    if($i<2)
                                    {
                                        echo '<div class="span5">'; 
                                        $a=$key->title;
                                        echo '<div class="title"><a href ='.$key->link.'><h4>'.$a.'</h4></a></div>';
                                        $pieces = explode("[", $key->description);
                                        echo '<div class="description">'.$pieces[0].'<a href ='.$key->link.'>... Read More</a></div>';
                                        echo '</div>';
                                        echo '<div class="span1">&nbsp;</div>';
                                         $i=$i+1;
                                    }
    
                                }
                            }
                        }
                        blog();
                    ?> ```
    
    

It used to work just fine until last year, when I got an SSL certificate, and moved my hosting from Godaddy legacy to new 'Starter Linux Hosting with cPanel'. And now the code is just not working. Other changes since last year or till the time the code was working and displaying posts:

  1. I have upgraded PHP to 7.4 (the latest version that Godaddy currently offers)
  2. I have upgraded Wordpress to latest version

I tested the code in https://sandbox.onlinephpfunctions.com/, and it showed me the following error:

<b>Warning</b>:  simplexml_load_file() has been disabled for security reasons in <b>[...][...]</b> on line <b>477</b><br />

But if I view the 'page source', there is no sign of any output from the code. It is just blank. Could anyone please help me understand what is it that going wrong with PHP code execution? Thanks a lot in advance!

1

I figured out that the problem was with executing the simplexml_load_file, and it simply required going to my php.ini file and setting allow_url_fopen flag from off to on. The code now executes flawlessly and the output is as intended.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.