Ir para conteúdo

POWERED BY:

Arquivado

Este tópico foi arquivado e está fechado para novas respostas.

Henrique Flausino

Converter PHP4 para PHP5

Recommended Posts

Pessoal.

 

Tenho um sistema de e-mail em php4 e preciso converter para php5.

Como devo fazer?

Existe algum programa para isso?

 

Exemplo, tenho este código:

<?
error_reporting(0);
$sess_save_path = "./tmp/";
function open ($save_path, $session_name) { 
 global $sess_save_path, $sess_session_name; 
 $sess_save_path = $save_path; 
 $sess_session_name = $session_name; 
 return(true); 
} 
function close() { 
 return(true); 
} 
function read ($id) { 
 global $sess_save_path, $sess_session_name; 
 $sess_file = "$sess_save_path/sess_$id"; 
 if ($fp = @fopen($sess_file, "r")) { 
   $sess_data = @fread($fp, @filesize($sess_file)); 
   return($sess_data); 
 } else { 
   return(""); 
 } 
} 
function write ($id, $sess_data) { 
 global $sess_save_path, $sess_session_name; 
 $sess_file = "$sess_save_path/sess_$id"; 
 if ($fp = @fopen($sess_file, "w")) { 
   return(fwrite($fp, $sess_data)); 
 } else { 
   return(false); 
 } 
} 
function destroy ($id) { 
 global $sess_save_path, $sess_session_name; 
 $sess_file = "$sess_save_path/sess_$id"; 
 return(@unlink($sess_file)); 
} 
function gc ($maxlifetime) { 
 return true; 
} 
session_set_save_handler ("open", "close", "read", "write", "destroy", "gc"); 
session_start(); 
session_start();
require_once _LIBPATH . "common.php";
require_once _LIBPATH . "xml.php";
require_once _LIBPATH . "template.php";
require_once _LIBPATH . "config.php";
require_once _LIBPATH . "html.php";
require_once _LIBPATH . "database.php";
require_once _LIBPATH . "vars.php";
require_once _LIBPATH . "library.php";
require_once _LIBPATH . "sqladmin.php";
require_once _LIBPATH . "forms.php";
require_once _LIBPATH . "sendmail.php";
class CBase {
	var $html;
}
class CSite {
	var $admin;
	var $html;
	function CSite($xml , $admin = true) {
		global $_CONF , $base;
		$this->admin = $admin;
		$tmp_config = new CConfig($xml);
		$_CONF = $tmp_config->vars["config"];
		if ($this->admin) {
			if (is_array($_CONF["templates"]["admin"])) {
				foreach ($_CONF["templates"]["admin"] as $key => $val) {
					if ($key != "path")
						$this->templates[$key] = new CTemplate($_CONF["templates"]["admin"]["path"] . $_CONF["templates"]["admin"][$key]);
				}			
			}			
		} else {
			if (is_array($_CONF["templates"])) {
				foreach ($_CONF["templates"] as $key => $val) {
					if (($key != "path" ) && ($key != "admin"))
						$this->templates[$key] = new CTemplate($_CONF["templates"]["path"] . $_CONF["templates"][$key]);
				}				
			}
		}
		$base = new CBase();
		$base->html = new CHtml();
		$this->html = &$base->html;
		if (is_array($_CONF["database"])) {
			$this->db = new CDatabase($_CONF["database"]);
			if ($_CONF["tables"]["vars"]) {
				$this->vars = new CVars($this->db , $_CONF["tables"]["vars"]);
				$base->vars = &$this->vars;
			}
			$this->tables = &$_CONF["tables"];
		}				
	}
	function TableFiller($item) {
		if (file_exists("pb_tf.php")) {
			include("pb_tf.php");
		}
	}
	function Run() {
		global $_TSM , $_SITE_IDENTITY_CODE ;
		if (file_exists("pb_events.php")) {
			include("pb_events.php");
			$_TSM["PB_EVENTS"] = @DoEvents($this);
		}
		if (is_object($this->templates["layout"])) {
			echo $this->templates["layout"]->Replace($_TSM) . $_SITE_IDENTITY_CODE ;
		}		
	}
}
?>

Preciso passar para PHP5

Att.

Henrique Flausino

Compartilhar este post


Link para o post
Compartilhar em outros sites

Pessoal.

 

Tenho um sistema de e-mail em php4 e preciso converter para php5.

Como devo fazer?

Existe algum programa para isso?

 

Att.

Henrique Flausino

 

Não vejo muitos problemas, claro não sei como você fez, mas aconselho você ler isso antes: http://www.php.net/manual/pt_BR/faq.migration5.php

 

abs

Compartilhar este post


Link para o post
Compartilhar em outros sites

Olá David.

 

Só tem um pequeno problema, não entendo quase nada de PHP, e este código foi feito para PHP4

É um sistema de Newsletter com confirmação de envio, bem completo.

 

 

Att.

Henrique Flausino

Compartilhar este post


Link para o post
Compartilhar em outros sites

não entendo quase nada de PHP

Ae complicou, mas você ja testou pra ver se roda no php5, reporta os erros e veja qual função alterar.

Compartilhar este post


Link para o post
Compartilhar em outros sites

o Jeito é fazer o que WDuarte disse mesmo, não tem outro jeito!

Compartilhar este post


Link para o post
Compartilhar em outros sites

o Jeito é fazer o que WDuarte disse mesmo, não tem outro jeito!

 

Amigo,

 

Para converter para php5 não é muito dificil, mais tem que botar a mão na massa.

 

precisa verificar todo codigo onde tiver:

<? mude para <?php

<?= mude para <?php echo ou <?php print

 

O PHP armazena as variáveis vindas por GET e por POST em vetores associativos (vetores cujos índices são strings).

Para pegar o id fazemos, por exemplo:

$id = $_GET["id"];

$descricao = $_GET["descricao"];

 

se usar $_REQUEST["id"];

recebe em GET e POST

 

O basico para converter é isso ai.

 

qualquer coisa poste as duvidas...

Compartilhar este post


Link para o post
Compartilhar em outros sites

No meu caso já estou rodando o sistema no PHP5, porém ele só executa esta parte do código.

<?
error_reporting(0);
$sess_save_path = "./tmp/";
function open ($save_path, $session_name) { 
 global $sess_save_path, $sess_session_name; 
 $sess_save_path = $save_path; 
 $sess_session_name = $session_name; 
 return(true); 
} 
function close() { 
 return(true); 
} 
function read ($id) { 
 global $sess_save_path, $sess_session_name; 
 $sess_file = "$sess_save_path/sess_$id"; 
 if ($fp = @fopen($sess_file, "r")) { 
 $sess_data = @fread($fp, @filesize($sess_file)); 
 return($sess_data); 
 } else { 
 return(""); 
 } 
} 
function write ($id, $sess_data) { 
 global $sess_save_path, $sess_session_name; 
 $sess_file = "$sess_save_path/sess_$id"; 
 if ($fp = @fopen($sess_file, "w")) { 
 return(fwrite($fp, $sess_data)); 
 } else { 
 return(false); 
 } 
} 
function destroy ($id) { 
 global $sess_save_path, $sess_session_name; 
 $sess_file = "$sess_save_path/sess_$id"; 
 return(@unlink($sess_file)); 
} 
function gc ($maxlifetime) { 
 return true; 
} 
session_set_save_handler ("open", "close", "read", "write", "destroy", "gc"); 
session_start(); 
session_start();
require_once _LIBPATH . "common.php";
require_once _LIBPATH . "xml.php";
require_once _LIBPATH . "template.php";
require_once _LIBPATH . "config.php";
require_once _LIBPATH . "html.php";
require_once _LIBPATH . "database.php";
require_once _LIBPATH . "vars.php";
require_once _LIBPATH . "library.php";
require_once _LIBPATH . "sqladmin.php";
require_once _LIBPATH . "forms.php";
require_once _LIBPATH . "sendmail.php";
class CBase {
	var $html;
}
class CSite {
	var $admin;
	var $html;
	function CSite($xml , $admin = false) {
		global $_CONF , $base;

Depois ele mostra na tela o código abaixo, logo após o $this->

 

$this->admin = $admin;
		$tmp_config = new CConfig($xml);
		$_CONF = $tmp_config->vars["config"];
		if ($this->admin) {
			if (is_array($_CONF["templates"]["admin"])) {
				foreach ($_CONF["templates"]["admin"] as $key => $val) {
					if ($key != "path")
						$this->templates[$key] = new CTemplate($_CONF["templates"]["admin"]["path"] . $_CONF["templates"]["admin"][$key]);
				}			
			}			
		} else {
			if (is_array($_CONF["templates"])) {
				foreach ($_CONF["templates"] as $key => $val) {
					if (($key != "path" ) && ($key != "admin"))
						$this->templates[$key] = new CTemplate($_CONF["templates"]["path"] . $_CONF["templates"][$key]);
				}				
			}
		}
		$base = new CBase();
		$base->html = new CHtml();
		$this->html = &$base->html;
		if (is_array($_CONF["database"])) {
			$this->db = new CDatabase($_CONF["database"]);
			if ($_CONF["tables"]["vars"]) {
				$this->vars = new CVars($this->db , $_CONF["tables"]["vars"]);
				$base->vars = &$this->vars;
			}
			$this->tables = &$_CONF["tables"];
		}				
	}
	function TableFiller($item) {
		if (file_exists("pb_tf.php")) {
			include("pb_tf.php");
		}
	}
	function Run() {
		global $_TSM , $_SITE_IDENTITY_CODE ;
		if (file_exists("pb_events.php")) {
			include("pb_events.php");
			$_TSM["PB_EVENTS"] = @DoEvents($this);
		}
		if (is_object($this->templates["layout"])) {
			echo $this->templates["layout"]->Replace($_TSM) . $_SITE_IDENTITY_CODE ;
		}		
	}
}
?>

Compartilhar este post


Link para o post
Compartilhar em outros sites

  var $html;

var esta depreciado no php 5.x

troque var por

 

public
ou

private
ou

protected

Compartilhar este post


Link para o post
Compartilhar em outros sites

Amigo acho que seria mais o menos assim:

<?php

//o id vem de post o get? se for de post ou get faça como esta abaixo
$id = $_REQUEST[id];
error_reporting(0);
$sess_save_path = "./tmp/";
function open ($save_path, $session_name) { 
global $sess_save_path, $sess_session_name; 
$sess_save_path = $save_path; 
$sess_session_name = $session_name; 
return(true); 
} 
function close() { 
return(true); 
} 
function read ($id) { 
global $sess_save_path, $sess_session_name; 
$sess_file = "$sess_save_path/sess_$id"; 
if ($fp = @fopen($sess_file, "r")) { 
$sess_data = @fread($fp, @filesize($sess_file)); 
return($sess_data); 
} else { 
return(""); 
} 
} 
function write ($id, $sess_data) { 
global $sess_save_path, $sess_session_name; 
$sess_file = "$sess_save_path/sess_$id"; 
if ($fp = @fopen($sess_file, "w")) { 
return(fwrite($fp, $sess_data)); 
} else { 
return(false); 
} 
} 
function destroy ($id) { 
global $sess_save_path, $sess_session_name; 
$sess_file = "$sess_save_path/sess_$id"; 
return(@unlink($sess_file)); 
} 
function gc ($maxlifetime) { 
return true; 
} 

Compartilhar este post


Link para o post
Compartilhar em outros sites

Você está certo, no PHP5 ainda é permitido, porém não recomendado. A partir do PHP6, essa directiva não irá existir mais e short-tag-open não será mais permitido.

 

Já é legal ir mudando, ir se acostumando porque é como disse, shots tags não irão mais existir.

Compartilhar este post


Link para o post
Compartilhar em outros sites

É, os caras desenvolvendo uma versão com suporte a Unicode e pessoas enfrentando problemas com o maldito "<?" igual a xml...

Compartilhar este post


Link para o post
Compartilhar em outros sites

×

Informação importante

Ao usar o fórum, você concorda com nossos Termos e condições.