PHP echo help

GetRekt

Member
Aug 1, 2014
75
5
How can i make it so

echo 'System error: '.$text.'<br>Text: ' .$text.'';

If IP is: 000.000.000.000 etc if not then show this text

echo 'Out site has encountered an error we are trying to fix it as much as we can.'';
 

TesoMayn

Boredom, it vexes me.
Oct 30, 2011
1,482
1,482
PHP:
<?
$ip = $_SERVER['REMOTE_ADDR'];
if($ip == '000.000.0000.000) {
  echo "System error: {$text}<br />Text: {$text}";
} else {
  echo 'Out site has encountered an error we are trying to fix it as much as we can.'';
}
?>
 

RastaLulz

fight teh power
Staff member
May 3, 2010
3,926
3,921
PHP:
<?php

$displayErrorsTo = array('127.0.0.1', '12.34.56.78', '000.000.000.000');

if(in_array($_SERVER['REMOTE_ADDR'], $displayErrorsTo)) {

    echo 'System error: ' . $text . '<br>Text: ' . $text;

}else{

    echo 'Out site has encountered an error we are trying to fix it as much as we can.';

}
 

Weasel

👄 I'd intercept me
Nov 25, 2011
4,132
2,456
PHP:
<?php

public function errorCheck()
{
    $displayErrorsTo = array('127.0.0.1', '12.34.56.78', '000.000.000.000');

    if (in_array($_SERVER['REMOTE_ADDR'], $displayErrorsTo))
    {
        $error = "System error: " . $text . "<br />";
        $error .= "Text: " . $text;
    }
    else
    {
        $error = "Out site has encountered an error we are trying to fix it as much as we can.";
    }
  
    return $error;
}

Just call $class->errorCheck() to echo the message.
 

RastaLulz

fight teh power
Staff member
May 3, 2010
3,926
3,921
PHP:
<?php

public function errorCheck()
{
    $displayErrorsTo = array('127.0.0.1', '12.34.56.78', '000.000.000.000');

    if (in_array($_SERVER['REMOTE_ADDR'], $displayErrorsTo))
    {
        $error = "System error: " . $text . "<br />";
        $error .= "Text: " . $text;
    }
    else
    {
        $error = "Out site has encountered an error we are trying to fix it as much as we can.";
    }

    return $error;
}

Just call $class->errorCheck() to echo the message.
That wouldn't work in that context because the variable $text would always be null, as it isn't being passed into the function, or isn't being referenced from a global perspective. That function also doesn't check for an error, it just simply provides an error message based on the users IP, regardless if there is actually an error or not.
 

Weasel

👄 I'd intercept me
Nov 25, 2011
4,132
2,456
That wouldn't work in that context because the variable $text would always be null, as it isn't being passed into the function, or isn't being referenced from a global perspective. That function also doesn't check for an error, it just simply provides an error message based on the users IP, regardless if there is actually an error or not.
I agree with you on the text part, missed that out in the hurry. However, it would do the same thing as normal PHP in a page as your script.
PHP:
public function errorCheck($text = null)
{
    $displayErrorsTo = array('127.0.0.1', '12.34.56.78', '000.000.000.000');

    if (in_array($_SERVER['REMOTE_ADDR'], $displayErrorsTo) && !is_null($text))
    {
        $error = "System error: " . $text . "<br />";
        $error .= "Text: " . $text;
    }
    else
    {
        $error = "Out site has encountered an error we are trying to fix it as much as we can.";
    }

    return $error;
}

Unless you specifically call the function with the $text var in the call, it will return the else. If you do add a message in the call, it will call the error.

Example:
$class->errorCheck(); will return the else
$class->errorCheck($errortext); will return the detailed message
 

Users who are viewing this thread

Top