Help with rewriting, keeping up with latest php

Why is php updates changing variables?

I pay for hosting, and run a tiny personal weather website that uses phonifier v. 2.1 which is a very old script that allows me to see national weather service ftp text weather products, where their .htaccess page is broken and I otherwise couldn’t see it. …I also use php to crank images through an external proxy in the Netherlands, which allows me to see a few hundred megs of data in under a meg. It is a real time saver and a data saver. No ads.

I also hate javascript with a passion: both as a client and as an author. I always turn off javascript and have a visceral hatred of javascript and the modern slow internet. I refuse to view most webpages that use javascript.

On the other hand, I really like php. Its basic like logic, speed, universally accessible code, and readable code, appeals to me . The browser focus can be on features and accessiblity and speed, rather than constant security plugs.

I was able to sit down, knowing nothing, except little more how to program basic in 1983, knowing dos scripting, and ahk scripting–I read for about an hour and was able to program some pretty cool and complex stuff in an afternoon, with no difficulty maintining the code as I added to my website.

Unfortunately, I don’t remember is my php website was done in 2009, 2012, 2014, 2017 or 2018. Probably, 2016 to 2018 era. I also don’t know what epoch my phonifier php was written.

Recently, my php pages aren’t working. I understand that php may need to upgrade to plug security holes. But I am seeing complaints that variables have changed (time and quotes), plus my phoniefier isn’t working any more.

Why would any self respecting project break compatibility, when many people pick the language because the langue is humanly readable and well documented enough to allow very few hours learning the langue and hundreds of hours perfecting scripts that actually do useful things that are previously impossible! I see zero point wasting hundreds of hours on a script that will be useful 30 to 100 years from now, if the project is going to be abandoned or depricated 4 or 10 years from now. It is not worth my time. … On the other hand, I will gladly spend a thousand hours on one script or program, if it permanently solves a problem that will continue to save a hundred hours a year for the next 50 years for me, and longer, for future generations. I am not trying to make money: I am trying to problems solve. Changing the backwards compatibility just creates more problems.

So, I may have solved some of the time variable problems, but not why phonifier is broken.

I guess all of the websearching documents are now broken too, and not caught up. It will be hit or miss getting accurate php instructions, as web pages are also a labor of love and left for the benefit of others and forgotten by the author.

Is there a tool we can run our old code through to update syntax that was deprecated? Is there a site to tell us what year each version of php came out, so we can roll back the php version to avoid being like a dog chasing a car? Is there a terse page that lists the changes. Can I post the code to have an expert altruist tell me where things got broken and how to fix it?

I really like php, a lot. However, this is because it does stuff without hamstringing me into learning a bunch of stuff that I will never use or need. (The power of readability, and Basic like if/then/goto/variables structure, which was used by every home computer user since the early 1980s because, back then, we had to write our own accounting or other software to get anything out of a computer. It wasn’t professionally obfuscated, and shouldn’t be.)

By the way, the crappy javascript on this forum, is broken, as usual.

It flickers uncontrollably on my 2020 win 10 computer.

This couldn’t happen if the forum stuck to php and didn’t use aweful javascript.

1 Like

I can’t even read anything that I wrote. Every now and then the page stops jiggling enough to read. (Half of the problem is with javascript compatibility with the end user and the nightmare of chasing that car. The other half of the problem I have with javascript is page size, speed of page load, compatibility, the complexity of the code, loosing the thread of the page information in favor of author OCD tendencies, inaccessibility to the end user of the layout and manner to consume the webpage. The modern webpage is a train wreck of ads, autoplaying streams, unreadable text, huge data chunks, browser security risks, very little real information worth the hassle. This is due to javascript. But I guess, my preferred php approach to function, needs server-side updates for server security reasons.

A good example is accuweather and weather.com will offer 12 hours of hourly weather conditions at 20 megs on one page. The national weather service will offer a far more easy to see table layout in 200 kb. I can grab the tabular page of the national weather service, strip out some of the useless code and a have the same table as the NWS in 12 KB.

I could get it down to 6 kb if I spent more time streamlining the code.

This unnecessarry 20 megs of data, with less information, is a huge problem for the end user, who is clueless.

Not that I know of. Having php, of the target version, attempt to run the code will result in errors about removed or deprecated features.

See the - Release history here - PHP - Wikipedia
Or more specifically here - PHP: Version History

See the migration sections here - PHP: Appendices - Manual

Yes.

The biggest changes up to php8, that will affect most code are the removal of register_globals, magic_quotes, and the mysql_ database extension. The biggest php8 change is how indirect (variable) OOP references are parsed, which won’t affect simple code.

About database extensions. If you have old mysql_ based code, don’t bother with the overly complicated and inconsistent mysqli extension. Go directly to the much simpler and more modern PDO database extension. When you make a connection using PDO, set the character set to match your database tables, set the error mode to exceptions, set emulated prepared queries to false, and set the default fetch mode to assoc. For prepared queries, use simple positional ? place-holders and use implicit binding, by supplying an array of values to the ->execute([…]) call.

Here is the phonifier code that broke a few months ago:

<?php
/**
 * Phonifier - Websites and RSS mobile accessible!
 *
 * Copyright (C) 2005 Peter de Blieck, Paragin
 * 
 * Licensed under the Creative Commons Attribution-ShareAlike License.
 *      http://creativecommons.org/licenses/by-sa/2.0/nl/
 * 
 * For further information visit:
 *      http://www.phonifier.com/
 * 
 * File Name: Phonifier.php
 *
 * This Class was made originally for ShotCode.com
 *
 * This is a PHP-class that allows users to access webpages 
 * on small screen-devices by removing unnecessary code.
 * 
 * Features:
 * - HTTP + HTTPS
 * - Follow redirects
 * - Forms (GET AND POST)
 * - Cookies
 * - Url-rewriting (../, /, //, mailto:, javascript:, #, <base href='#'>)
 * - Frames
 * - RSS+ATOM-feeds
 * - Removing lots of unnecessary code
 * - Optionally replacing images with their alt-text
 * - Wap-pages passthru
 * - Follow <meta refresh>-tags
 *
 * Limitations:
 * - Pages that require an Authorization username and password (not implemented for safety reasons)
 * - If you come accross other limitations, please let me know
 * 
 **/
session_start();

class Phonifier {

    var $baseurl          = "";           //Baseurl of the phonifier
    var $user_agent       = 'Mozilla/5.0 (compatible; Phonifier; +http://www.phonifier.com)';  //The name of the user-agent
    var $time_out         = 5;            //Maximum time you want fsockopen to access the url
    var $data             = "";           //The outputdata
    var $header           = "";           //The headerdata
    var $scheme           = "";           //HTTP OR HTTPS
    var $port             = 80;           //HTTP=80 (default), HTTPS=443
    var $times            = 0;            //Number of redirects followed
    var $iswap            = false;        //Is the accessed page a wml-page?
    var $post             = "";           //Post-values
    var $method           = "GET";        //GET (default), POST
    
    var $url              = "http://";           //The url the parser has to access
    var $img              = true;         //Show images in the result or replace them with their alt-text
    var $urlinfo;                         //Result of parse_url()
    
    var $contenttype      = "";           //Content-type of the result
    var $contentlength    = 0;            //Content-lenght of the result
    var $starttime        = 0;            //Start-time, used for benchmarking
    var $error            = false;        //No errors yet :-)
    var $errortype        = "";           //The errortype (for debugging)
    var $feed             = false;        //Is this a feed?

    //The template used for displaying the result
    var $template     ="<!DOCTYPE html PUBLIC '-/W3C//DTD XHTML 1.0 Transitional//EN' 
    'http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd'>
<html xmlns='http://www.w3.org/1999/xhtml'>
<head>
<title>%1\$s</title>
<meta http-equiv='Content-Type' content='%2\$s' />
<link rel='stylesheet' type='text/css' media='all' href='%3\$s/phonify.css'/>
<base href='%3\$s/' />
</head>
<body>
<a name='phonifiertop'></a>
<form action='index.php' method='get'>
    <input type='hidden' name='l' value='1' />
    <input type='text' name='u' value='%4\$s' size='30' />
    <input type='submit' value='go' /><br />
    images <input type='radio' name='i' value='1'%5\$s/>on /<input type='radio' name='i' value='0'%6\$s/>off
    <hr />
</form>
%7\$s
<br /><a href='#phonifiertop'>top</a>
</body>
</html>    
";

    /**
     * Make an instance of the Phonifier-class
     *
     * $url       (string) : The url that you want to access
     **/
    function Phonifier($url)
    {
        //get the baseurl of the phonifier
        $this->baseurl = preg_replace("/\/$/","",str_replace('\\','/',dirname("http://".$_SERVER['HTTP_HOST'].$_SERVER['SCRIPT_NAME'])));

        $this->starttime = $this->microtime_float();
        $this->url       = $url;
        
        //If there is a POST, set the variables right
        if(isset($_POST) && sizeof($_POST)>0)
        {
            foreach($_POST as $name=>$value ){
                $this->post .= urlencode($name)."=".urlencode($value).'&';
            }
            $this->post   = substr($this->post,0,-1);
            $this->method = "POST";
        }
        
    }
    
    /**
     * This function activates the Phonifier
     * Run this after you set values like $img
     **/
    function run()
    {
        if(eregi("^(http|https)+(:\/\/)",$this->url))
        {
            //initiate vars
            $this->init();
            
            if(!$this->error)
            {
                //get the contents of the url
                $this->get();
            }
        }
        else
        {
            //the url doesnt start with http(s)
            $this->error       = true;
            $this->errortype   = "Url not valid, no http(s)://";
            $this->contenttype = "text/html; charset=iso-8859-1";
            $this->data = sprintf($this->template,"",$this->contenttype,$this->baseurl,htmlspecialchars($this->url,ENT_QUOTES),$this->img?" checked='checked'":"",$this->img?"":" checked='checked'",empty($this->url)?"Insert url in textfield and press 'go'":"Error: the url is not valid");
        }
    }
    
    /**
     * Initiate function
     * This function sets variables to the right value
     **/
    function init()
    {
        //url seems valid...
        $this->data     = "";
        $this->header   = "";
        $this->urlinfo  = @parse_url($this->url);
        
         //get the hostname withoud www
        $host =  eregi_replace("^www.","",$_SERVER['HTTP_HOST']);

        if(eregi($host,$this->urlinfo['host']) || eregi($_SERVER['SERVER_ADDR'],$this->urlinfo['host']) || eregi("127.0.0.1",$this->urlinfo['host']) || eregi("localhost",$this->urlinfo['host']))
        {
            //don't call yourself
            $this->error       = true;
            $this->errortype   = "Own domain";
            $this->contenttype = "text/html; charset=iso-8859-1";
            $this->data = sprintf($this->template,"",$this->contenttype,$this->baseurl,htmlspecialchars($this->url,ENT_QUOTES),$this->img?" checked='checked'":"",$this->img?"":" checked='checked'","Error: choose a domain outside {$host}");
        }

        //when the scheme is https fsockopen wants a 'ssl://'- url
        //and off course a different port
        if($this->urlinfo['scheme']=='https')
        {
            $this->port   = 443;
            $this->scheme = "ssl://";
        }    
    }
    
    /**
     * returns time
     * Used for benchmarking
     **/
    function microtime_float()
    {
       list($usec, $sec) = explode(" ", microtime());
       return ((float)$usec + (float)$sec);
    }
    
    /**
     * The get function
     * These are the 'brains' of the Phonifier
     **/
    function get()
    {
        //do the request
        $this->request();
        
        $requesttime = round($this->microtime_float() - $this->starttime,5);
        
        //Put the cookie in the session when set
        if(preg_match_all("/Set-Cookie: (.*)=(.*);/Uis",$this->header, $cookies))
        {
            if(!isset($_SESSION[$this->urlinfo['host']]))
            {
                $_SESSION[$this->urlinfo['host']] = array();
            }
            for($i=0;$i<sizeof($cookies[1]);$i++)
            {
                if(eregi("^deleted",$cookies[2][$i]) && isset($_SESSION[$this->urlinfo['host']][$cookies[1][$i]]))
                {
                    unset($_SESSION[$this->urlinfo['host']][$cookies[1][$i]]);
                }
                else
                {
                    $_SESSION[$this->urlinfo['host']][$cookies[1][$i]] = $cookies[2][$i];
                }
            }            
        }
        
        //Check contenttype
        if(preg_match("/Content-Type:(.*)\\n/Uis",$this->header, $content_type))
        {
            $this->contenttype = trim($content_type[1]);
            $this->iswap = (strpos($this->contenttype,"text/vnd.wap.wml") !== false)? true : false;
            
            //rss and atom feeds
            if(eregi("^(application|text)\/(atom\+)?xml",$this->contenttype))
            {
                $this->error = true;
                $this->feed  = true;
                $this->data  = $this->feedToHtml();
            }
            //anything except (x)html or wap
            else if(!eregi("^text\/html",$this->contenttype) && !eregi("application\/xhtml\+xml",$this->contenttype) && !$this->iswap)
            {
                $this->error       = true;
                $this->errortype   = "Wrong Content-type";
                $this->contenttype = "text/html; charset=iso-8859-1";
                $this->data = sprintf($this->template,"Wrong Content-type",$this->contenttype,$this->baseurl,htmlspecialchars($this->url,ENT_QUOTES),$this->img?" checked='checked'":"",$this->img?"":" checked='checked'","The page that I found cannot be optimized for use on a mobile device.<br />Click <a href='{$this->url}'>here</a> to access the address without optimization."); 
            }
        }

        //rewrite the urls
        if(!$this->error)
        {
            $this->rewrite();
        }

        $rewritetime = round($this->microtime_float() -$this->starttime,5);

        //clean non-used tags and meta-data
        if(!$this->iswap && !$this->error)
        {
            $this->tiny();
        }
        $cleantime = round($this->microtime_float() -$this->starttime,5);            

        $this->data = eregi_replace("(\r\n|\r|\n| )+", " ", $this->data); //remove all spaces and linebreaks
        if(!$this->iswap)
        {
            $this->data.= "\r\n<!-- Request: {$requesttime}|{$rewritetime}|{$cleantime} -->"; //benchmarks
        }
        
        
        
        if($this->feed)
        {
            $this->error = false;
        }

        $this->contentlength = strlen($this->data);
        $this->contenttype   = empty($this->contenttype)? "text/html; charset=iso-8859-1":$this->contenttype;
    }
    

    function contentlength() {
        $this->contentlength = strlen($this->data);
        return $this->contentlength;
    }


    /**
     * The request-function. It checks the url and handles the request
     **/
    function request()
    {
    
        if ($this->url == "" or $this->url == "http://" or $this->url == "https://")
        {
            $this->error       = true;
            $this->errortype   = "Insert url in textfield and press 'go'";
            $this->contenttype = "text/html; charset=iso-8859-1";
            $this->data = sprintf($this->template,"",$this->contenttype,$this->baseurl,htmlspecialchars($this->url,ENT_QUOTES),$this->img?" checked='checked'":"",$this->img?"":" checked='checked'","Insert url in textfield and press 'go'");
        } 
        
        else 
        {

            //every time we call this function we count it... we don't want to run forever...
            if($this->times<4)
            {
                if(isset($this->urlinfo['host']) && isset($this->urlinfo['scheme']))
                {
                    //open the socket
                    $fp=@fsockopen($this->scheme.$this->urlinfo['host'], $this->port, $errno, $errstr, $this->time_out);
                    if($fp) {
                        //get the data
                        /***************[BEGIN]***************/
                        $receivingheaders = true;
                        $this->data = "";
                        $this->header = '';
    
                        $this->urlinfo['path'] = isset($this->urlinfo['path'])? $this->urlinfo['path'] : "";
    
                        $accept = isset($_SERVER['HTTP_ACCEPT']) ? $_SERVER['HTTP_ACCEPT'] : "*/*";
    
                        $head = "{$this->method} {$this->urlinfo['path']}?".(isset($this->urlinfo['query'])?"{$this->urlinfo['query']}":"")." HTTP/1.0\r\nHost: {$this->urlinfo['host']}\r\nUser-Agent: {$this->user_agent}\r\nAccept: {$accept}\r\n";
                        if(isset($_SESSION[$this->urlinfo['host']]) && sizeof($_SESSION[$this->urlinfo['host']])>0)                    
                        {
                            $head.= 'Cookie: ';
                            foreach ($_SESSION[$this->urlinfo['host']] as $cookieKey => $cookieVal ) {
                                $head.= $cookieKey."=".urlencode($cookieVal)."; ";
                            }
                            $head = substr($head,0,-2) . "\r\n";
    
                        }
                        if(!empty($this->post))
                        {
                           $length = strlen($this->post);
                           $head.= "Content-Type: application/x-www-form-urlencoded\r\n";
                           $head.= "Content-Length: $length\r\n";
                           $head.= "\r\n";
                           $head.= $this->post;
                        }                    
                        $head.= "\r\n";
                        
                        fputs($fp,$head);
    
                        while(!feof($fp)) {
                            if($data=trim(@fgets($fp, 8192))) {
                                if(!$receivingheaders)
                                {
                                    $this->data.=$data."\r\n";
                                }
                                else
                                {
                                    $this->header.=$data."\r\n";
                                }
                            }
                            else
                            {
                                $receivingheaders = false;
                            }
                        }
                        /***************[/END]***************/
                        fclose($fp);
                        //now we have the result. but there can be problems...
                        
                        //check if we get a new Location
                        $location = "";
                        preg_match("/Location:(.*)\\n/Uis",$this->header, $loc);
                        preg_match("/<meta.+http-equiv=('|\")refresh('|\").*content=.*; url=(.*)('|\").*>/Uis",$this->data, $loc2);
                        
                        if(sizeof($loc)==2)
                        {
                            $location = $loc[1];
                        }
                        else if(sizeof($loc2)==5)
                        {
                            $location = $loc2[3];
                        }
    
                        if(!empty($location))
                        {
                            $this->url = eregi_replace("^./","/",trim($location));
    
                            //not a valid redirect... but we take care of it
                            if($this->url{0}=="/")
                            {
                                $this->url = "{$this->urlinfo['scheme']}://{$this->urlinfo['host']}{$this->url}";
                            }
                            else if(!eregi("^(http|https)+(:\/\/)",$this->url))
                            {
                                $this->url = "{$this->urlinfo['scheme']}://{$this->urlinfo['host']}/{$this->url}";
                            }
    
                            if(eregi("^(http|https)+(:\/\/)",$this->url))
                            {
                                //re-initiate vars
                                $this->init();
                                $this->post="";
                                $this->times++;
                                $this->request();
                            }
                        }
                        //or is there is a bad request...try again
                        else if(eregi("(400 )?Bad Request",$this->header) || eregi("302 Found",$this->header) || strlen(trim($this->header))==0)
                        {
                            //possible error of missing the last /.. change it and try again
                            $this->url.='/';
                            $this->urlinfo['path'].= '/';
                            $this->post="";
                            $this->times++;
                            $this->request();
                        }
                        //or is the page moved?
                        else if(eregi("301 Moved Permanently",$this->header))
                        {
                            //we checked this first but if there isn't a 
                            //Location-header we can't do anything
    
                            $this->error       = true;
                            $this->errortype   = "Redirect misunderstood";
                            $this->contenttype = "text/html; charset=iso-8859-1";
                            $this->data = sprintf($this->template,"",$this->contenttype,$this->baseurl,htmlspecialchars($this->url,ENT_QUOTES),$this->img?" checked='checked'":"",$this->img?"":" checked='checked'","Error: Redirect misunderstood.<br />Click <a href='{$this->url}'>here</a> to access the address without optimization.");
                        }
                        //or doesn't the page exist?
                        else if(eregi("404 Not Found",$this->header))
                        {
                            $this->error       = true;
                            $this->errortype   = "404";
                            $this->contenttype = "text/html; charset=iso-8859-1";
                            $this->data = sprintf($this->template,"404 File Not Found",$this->contenttype,$this->baseurl,htmlspecialchars($this->url,ENT_QUOTES),$this->img?" checked='checked'":"",$this->img?"":" checked='checked'","Error 404: The page you want to visit does not exist");
                        }
                        //or is the page password protected?
                        else if(eregi("401 Authorization Required",$this->header))
                        {
                            $this->error       = true;
                            $this->errortype   = "Authorization required";
                            $this->contenttype = "text/html; charset=iso-8859-1";
                            $this->data = sprintf($this->template,"401 Authorization Required",$this->contenttype,$this->baseurl,htmlspecialchars($this->url,ENT_QUOTES),$this->img?" checked='checked'":"",$this->img?"":" checked='checked'","The page you want to visit is password-protected. Click <a href='{$this->url}'>here</a> to access this page.");
                        }
                    }
                    else
                    {
                        $this->error       = true;
                        $this->errortype   = "Timeout";
                        $this->contenttype = "text/html; charset=iso-8859-1";
                        $this->data = sprintf($this->template,"",$this->contenttype,$this->baseurl,htmlspecialchars($this->url,ENT_QUOTES),$this->img?" checked='checked'":"",$this->img?"":" checked='checked'","Error: the request timed out.<br />Click <a href='{$this->url}'>here</a> to access the address without optimization.");
                    }
                }
                else
                {
                    $this->error       = true;
                    $this->errortype   = "No optimization";
                    $this->contenttype = "text/html; charset=iso-8859-1";
                    $this->data = sprintf($this->template,"",$this->contenttype,$this->baseurl,htmlspecialchars($this->url,ENT_QUOTES),$this->img?" checked='checked'":"",$this->img?"":" checked='checked'","Error: the url could not be optimized.<br />Click <a href='{$this->url}'>here</a> to access the address without optimization.");
                }
            }
            else
            {
                $this->error       = true;
                $this->errortype   = "Too many redirects";
                $this->contenttype = "text/html; charset=iso-8859-1";
                $this->data = sprintf($this->template,"",$this->contenttype,$this->baseurl,htmlspecialchars($this->url,ENT_QUOTES),$this->img?" checked='checked'":"",$this->img?"":" checked='checked'","Error: redirected too many times.. quitting.<br />Click <a href='{$this->url}'>here</a> to access the address without optimization.");
            }
        }
    }
    
    /**
     * Rewrite the urls in de responsedata
     **/
    function rewrite()
    {

        $base = "{$this->urlinfo['scheme']}://{$this->urlinfo['host']}";
        $path = $this->urlinfo['path'];
        $baseuri = "";
        $img  = $this->img? 1 : 0;
        
        if(!eregi("/$",$path))
        {
            $path = preg_replace("/\/$/","",str_replace('\\','/',dirname($path)));
        }
        
        //if there is a base-url specified.. use it in every link
        preg_match("/<base.+href=('|\")(.*)('|\").*>/Ui",$this->data, $baseurl);
        if(sizeof($baseurl)==4)
        {
            $baseuri = $baseurl[2];
        }
        
        /**
         * The function that replaces the urls
         * This function is not my favourite, it must be possible to do it better
         **/
        function replaceUrl($base,$path,$baseuri,$img,$type,$a,$b,$c)
        {
            $type = strtolower($type);
            if(!empty($baseuri))
            {
                $current = $baseuri;
            }
            else
            {
                $current = $base.$path;
            }

            if(eregi("^/",$b))
            {
                if(substr($b,0,2)!="//")
                {
                    $b = (empty($baseuri)?$base:$baseuri).$b;
                }
                else
                {
                    $b = "http:".$b;
                }
            }
            else if(eregi("^../",$b))
            {
                if($base==$current)
                {
                    $b = $current.substr($b,2);
                }
                else
                {
                    $b = $current.(eregi("/$",$current)?"":"/").$b;
                }
            }
            else if(eregi("^mailto:",$b))
            {
                $b = "#";
            }
            else if(eregi("^#",$b))
            {
                $b = $b;
            }
            else if(eregi("^javascript:",$b))
            {
                $b = "#";
            }
            else if(!eregi("^(http|https)://",$b))
            {
                $b = $current.(substr($current,-1)=="/"?"":"/").$b;
            }

            if($type=="href" && !eregi("^#",$b))
            {
                $output = $type.'='.$a."?i={$img}&amp;u=".urlencode(html_entity_decode($b)).$c;
            }
            else if($type=="action" && !eregi("^#",$b))
            {
                $scheme = substr($b,0,strpos($b, "/")-1);
                $b      = trim(substr($b,strpos($b, "/")+2));
                $output = $type.'='.$a."index.php/{$img}/{$scheme}/".$b.$c;
            }
            else
            {
                $output = $type.'='.$a.$b.$c;
            }

            return stripslashes($output);
        }
        
        $this->data = preg_replace("/(href|action|src|;url)+=(['\"])?+(.+)([\"'> ])/Uie","replaceUrl('$base','$path','$baseuri','$img','\\1','\\2','\\3','\\4')",$this->data);
    }
    
    
    /**
     * Clean all tags you don't want
     **/
    function tiny()
    {
        if(preg_match("/text\/html\; charset=(.*)['\"]/iU",$this->data, $ct))
        {
            $this->contenttype = "text/html; charset={$ct[1]}";
        }        
        $title = preg_match("/<title>(.*)<\/title>/i",$this->data, $titlecontents)? $titlecontents[1] : "";
        
        $search = array(
                        '@<!--(.*)-->@Usi'                                                                                                        //html-comments
                       ,'@\/\/<!\[CDATA\[.*?\/\/\]\]>@ism'
                       ,'@on(click|mouseover|mouseout|blur|error|focus|load|unload|submit|reset|abort|change|select)=(\'|").*(["\'])+( |>)@Usi'   //all javascript-triggers that results in an js-error
                       ,'@<link(.*)media=(\'|")(screen|print)(\'|").*?'.'>\r\n@Uie'                                                                  //remove stylesheets that a mobile phone doesn't use
                       ,'@<(noedit|iframe|script)[^>]*?'.'>.*?<\/(noedit|iframe|script)>@ism'                                                        //script and object-tags
                       ,'@<(head|object|style|map)[^>]*?'.'>.*?<\/(head|object|style|map)>@ism'                                                      //script and object-tags
                       ,'@<(body|p)[^>]*?'.'>@ism'                                                                                                   //empty body-tag
                       ,'@.*<html[^>]*?'.'>@ism'
                       ,'@</tr>@ism'
                       ,'@<(\/)?(html|body|div|span|link|meta|font|center|noscript|frameset|noframes|table|tr|th|td|tbody|thead|tfoot)[^>]*?'.'>@ism'                                 //remove tables,div,span,link,meta
                       ,'@<\/p>(\r\n)+\|(\r\n)+<p>@ism'
                       ,'@((<br ?/?'.'>)+((\r)?\n)*)+@i'
                       ,'@(\r\n)+@'
                       ,'@(style)=(\'|").*(["\'])+( |>)@Usi'
                       ,'@<frame.*src=(\'|")(.*)(\'|").*>@Uis'
                       ,'@(target)=(\'|").*(["\'])+( |>)@Usi'
                       );
        $replace = array(
                        ''
                       ,''
                       ,'\4'
                       ,''
                       ,''
                       ,''
                       ,'<\1>'
                       ,''
                       ,'<br />'
                       ,''
                       ,' | '
                       ,'<br />'
                       ,' '
                       ,'\4'
                       ,'Frame: <a href=\'?i=1&u=\2\'>\2</a><br />'
                       ,''
                       );
                       
        if(!$this->img) //filter out images
        {
            //images with alt
            $search[]  = "/<img[^>]* alt=(\"([^\"]+)\"|'([^']+)'|([^\"'> ]+))[^>]*>/i";
            $replace[] = "[$2$3$4] ";
            
            //images without alt
            $search[]  = '/<img.*[^>]*?'.'>/Ui';
            $replace[] = '[img]';
        }
        
        $this->data = preg_replace($search, $replace, $this->data);
        $this->data = sprintf($this->template,$title,$this->contenttype,$this->baseurl, htmlspecialchars($this->url,ENT_QUOTES),$this->img?" checked='checked'":"",$this->img?"":" checked='checked'",$this->data);
    }
    
    /**
     * When accessing a RSS or ATOM feed this function is called to make the feed readable
     **/
    function feedToHtml()
    {
        $outputhtml = "";
        
        $atom = false;
        $channelCount = preg_match_all("|(xml.*encoding=['\"](.*)['\"].*>.*)?<channel>.*<title>(.*)</title>.*<link>(.*)</link>.*</channel>|iUs",$this->data,$channels,PREG_SET_ORDER); 
        if($channelCount==0)
        {
            $channelCount = preg_match_all("|(xml.*encoding=['\"](.*)['\"].*>.*)?<feed.*>.*<title>(.*)</title>.*<link.*href=['\"](.*)['\"].*<author>|iUs",$this->data,$channels,PREG_SET_ORDER); 
            $atom = true;
        }
        $channels = reset($channels);
        $outputhtml.= "<h1><a href='{$channels[4]}'>{$channels[3]}</a></h1><br />";
        
        if($atom)
        {
            $itemCount = preg_match_all("|<entry>(.*)</entry>|iUs",$this->data,$items,PREG_SET_ORDER); 
        }
        else
        {
            $itemCount = preg_match_all("|<item>(.*)</item>|iUs",$this->data,$items,PREG_SET_ORDER); 
        }
        
        if($itemCount>0)
        {
            foreach($items as $item)
            {
                $str_title = "";
                $str_link  = "";
                $str_descr = "";
                
                $linkmatch  = $atom? "|<link.*rel=['\"]alternate['\"].*href=['\"](.*)['\"].*/>|iUs" : "|<link.*>(.*)</link>|iUs";
                $descrmatch = $atom? "|<summary.*>(.*)</summary>|iUs" : "|<description.*>(.*)</description>|iUs";
                
                if(preg_match_all("|<title.*>(.*)</title>|iUs",$item[0],$title,PREG_SET_ORDER))
                {
                    $str_title = $title[0][1];
                }
                if(preg_match_all($linkmatch,$item[0],$link,PREG_SET_ORDER))
                {
                    $str_link = $link[0][1];
                }
                if(preg_match_all($descrmatch,$item[0],$descr,PREG_SET_ORDER))
                {
                    $str_descr = str_replace("<![CDATA[","",str_replace("]]>","",$descr[0][1]));
                }
                
                $outputhtml.= "<h2><a href='{$str_link}'>{$str_title}</a></h2>";
                $outputhtml.= "{$str_descr}<br /><br />";
            }
        }
        else
        {
            $outputhtml.= "Feed couldn't be parsed";
        }
        
        $this->data = $outputhtml;
        
        $charset    = empty($channels[2])?"UTF-8":$channels[2];
        $this->contenttype = "text/html; charset=$charset";
        
        $this->rewrite();
        
        $outputhtml = sprintf($this->template,"{$channels[3]}",$this->contenttype,$this->baseurl,$this->url,$this->img?" checked='checked'":"",$this->img?"":" checked='checked'",$this->data);
        
        return $outputhtml;
    }

}

?>

Just skimming through the code, the main problems are the eregi… functions. They have been removed and would need to be converted to the equivalent preg_ functions, which interestingly the code already uses.

Adding the following two function definitions may (untested) allow the code to work -

function eregi($pattern,$value)
{
	// using / as the preg_ delimiter is common, but not for urls, which contain / characters
	// there are also both / and escaped \/ in the patterns in the code already, so cannot use preg_quote() on the pattern
	// therefore a different delimiter should be used, such as #
	// this however can exist in urls, and therefore needs to be escaped when it exists in the pattern
	$pattern = preg_replace('/#/','\#',$pattern);
	return preg_match("#$pattern#i",$value);
}

function eregi_replace($pattern,$replace,$value)
{
	$pattern = preg_replace('/#/','\#',$pattern);
	return preg_replace("#$pattern#i",$replace,$value);
}

Awesome.

Do you know on which line I should inject these lines?

Perhaps, this will make it easier, if I upload it as a txt file.
http://www.clevelandohioweatherforecast.com/phonifier21/Phonifier.txt

The current phonifier.php is at http://www.clevelandohioweatherforecast.com/phonifier21/Phonifier.php

Deprecated : Array and string offset access syntax with curly braces is deprecated in /home/clevela1/public_html/phonifier21/Phonifier.php on line 373

Deprecated : Methods with the same name as their class will not be constructors in a future version of PHP; Phonifier has a deprecated constructor in /home/clevela1/public_html/phonifier21/Phonifier.php on line 40

Warning : session_start(): Cannot start session when headers already sent in /home/clevela1/public_html/phonifier21/Phonifier.php on line 38

I am not sure if my line search in my text editor is correct, since in some languages, commented lines are not counted as lines, which really throws the monkey wrench into figuring out which lines need fixing.

So, I am not sure if any of the 3 lines it is complaining about are the actual lines. If so, the ergi thing is not in them. 373 is if($this->url{0}=="/")

Line 38 is session_start();
line 40 is class Phonifier {

I think line 373 is a simple fix.

I don’t get the complaint about line 40 or 38 , even after googling.

None of the search results has anything resembling these lines.

I would firstly like to fix Deprecated : Methods with the same name as their class will not be constructors in a future version of PHP; Phonifier21 has a deprecated constructor in /home/clevela1/public_html/phonifier21/PhonifierT6.php on line 40

But I tried changing the line to all sorts of things, after googling. Nothing works. The syntax needed escapes me.

I would either put them into your main file, the one that requires Phonifier.php, or put them into their own file and require it by your main file.

Changing that line to the following should work -

 if($this->url[0]=="/")

The method/function definition - function Phonifier($url) should be changed to -

function __construct($url)

It’s not really the responsibility of the Phonifier.php class definition file to start the session. The session_start() statement should be moved to the start of your main file, in an initialization section, that would be above the start of any output that’s sent to the browser. If you still get that message after moving the line of code, the whole message should indicated where the output was at that is preventing the session_start from working (though php had a couple of versions where this information wasn’t included in the error message.)

I made the changes here, http://www.clevelandohioweatherforecast.com/phonifier21/PhonifierTphdr.php

the txt version is http://
www.clevelandohioweatherforecast.com/phonifier21/PhonifierTphdr.txt

First it complained that line 57, function __construct{ needed to change to function __construct(
Then I am getting a var error, which I assume all the following variables need a different syntax because it is not a class anymore.

I played around trying to change or eliminate the var in line 58,59,60 etc. but nothing is working. It seems to not understand the ; between variable definitions.

The start of the class definition class Phonifier { doesn’t change. The -

i’m pretty much almost exactly a year too late but damn you really do hate javascript don’t you xD

i agree that PHP is like, much more efficient and stuff but don’t knock java down so much! it’s really useful when used correctly – the ads and such are to blame on the companies and ad placement of the hosting, not javascript itself!

as for the PHP tool, i don’t think i know any that track the changes necessarily. my main thing recently has been working on a PHP code security scanner cause like. yeah java has security issues but so does PHP and so does any code in existence. i found that PHP is easier to catch issues w tho, esp with the thing that my team has recently finally finished jfc it has been MONTHS of zero sleep, it’s basically like you just run your code and it gives you prompts to fix it which is freaking cool imho. i’m sure there’s something like that for javascript too?

i know you weren’t asking for a javascript tool but i’m js that i feel like your seething hatred of javascipt might be a biiiiiit. idk. unjustified? not to like, devalue your opinion though or anything.

Sponsor our Newsletter | Privacy Policy | Terms of Service