Chat does not appear

Asked

Viewed 61 times

-1

Good evening, everyone, and then good to you ?

Guys I created a very simple code,

IF enabled, display the chat , if disabled, display the error message, if the chat is enabled it must display the chat, but it displays the variable and not the code that is to be shown

define("Chat_Enable", false); // -- Ativar/Destivar Chat do Servidor
define("Chat_Scripts", '<embed  src="http://www.xatech.com/web_gear/chat/chat.swf" quality= "high" width= "500" height= "300" name= "chat" FlashVars="id=158331371&rl=Brazilian" align="middle" allowscriptaccess= "sameDomain" type= "application/x-shockwave-flash" pluginspage= "http://xat.com/update_flash.shtml" /></embed>'); // -- Script do Chat

Code to display chat

<?php
       if(@Chat_Enable == false)
       {
         echo "<div class=\"info-box\"> O Chat se encontra Desativado</div>";
       }
       else
       {

      echo @Chat_Scripts;

       }
       ?>

Instead of showing the chat, it displays the variable name "Chat_scripts", you can tell me where the error in the code is ?

  • Question: why the use of @ in front of constants? Codes are in the same file?

  • to hide the error , are in separate files, but included

  • Since it’s going wrong, wouldn’t it be interesting to see the mistake you’re making? Personal tip: avoid using @as much (even) as an application gets out of control very easy in such cases.

1 answer

1

This will occur because it is not including the other file and precisely because it is hiding the error message makes it difficult to know the reason for the problem. Avoid using the @, in fact never use, much less if it is in a development phase, after all if it is developing something which the reason to hide the error message, that are there to help you?! I recommend you read publication on this subject.


When you do:

@Chat_Scripts;

You remove the Notice: Use of undefined constant Chat_Scripts - assumed 'Chat_Scripts' in /in/meLso on line 3', this occurs twice. That’s why he gives a echo of Chat_Scripts, because it assumes that it would echo 'Chat_Scripts'.

Removing the error message does not fix the error, put the @ is not the solution. What happens is that constant cannot be accessed, as said in the message, to resolve you must use include() between the files or put all the information in one file, so just join the two pieces of code you have in one.

For example:

C:.
├───inc
│       chat.php
│
└───public_html
        index.php

There are two folders, in the hierarchy shown above, each folder with a different file.

The C:/servidor/inc/ chat.php will possess:

const CHAT_ENABLE = 1;
const CHAT_HTML = [
    1 => '<embed  src="http://www.xatech.com/web_gear/chat/chat.swf" quality= "high" width= "500" height= "300" name= "chat" FlashVars="id=158331371&rl=Brazilian" align="middle" allowscriptaccess= "sameDomain" type= "application/x-shockwave-flash" pluginspage= "http://xat.com/update_flash.shtml" /></embed>',
    0 => '<div class="info-box"> O Chat se encontra Desativado</div>'
    ];

The C:/servidor/public_html/ index.php possesses:

include('../inc/chat');

echo CHAT_HTML[ CHAT_ENABLE ];

The include will include the archive chat.php, so there will be the CHAT_HTML and also the CHAT_ENABLE that have been defined.


The modifications I made are optional, what you really need to do is include one file in the other, using include.


If you don’t want the include() (or similar) only use then:

define("Chat_Enable", false); // -- Ativar/Destivar Chat do Servidor
define("Chat_Scripts", '<embed  src="http://www.xatech.com/web_gear/chat/chat.swf" quality= "high" width= "500" height= "300" name= "chat" FlashVars="id=158331371&rl=Brazilian" align="middle" allowscriptaccess= "sameDomain" type= "application/x-shockwave-flash" pluginspage= "http://xat.com/update_flash.shtml" /></embed>'); // -- Script do Chat


if(!Chat_Enable){

    echo "<div class=\"info-box\"> O Chat se encontra Desativado</div>";

}else{

    echo Chat_Scripts;

}

This will solve the problem because the Chat_Enable and the Chat_Scripts are defined, test it out here.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.