채택완료

php소스 질문이요 ㅠ

2016-01-13 (수) 23:07:50 3,722

Copy
<?phpdefine('PHURL', true);ini_set('display_errors', 0);$prefix[0] = '';$filename = 'install';if (is_dir($filename)) {    die ("To get Phurl up and running, you first need to go through the <a href=\"install\">installation wizard</a> which will help you set up your new URL shortener in a matter of moments.<br/><br/>If you've already installed Phurl, then you MUST delete the install directory before it will function.");}?><?phprequire_once("config.php");require_once("functions.php");db_connect();if (count($_GET) > 0) {    $url   = mysql_real_escape_string(trim($_GET['url']));    $alias = mysql_real_escape_string(trim($_GET['alias']));    if (!preg_match("/^(".URL_PROTOCOLS.")\:\/\//i", $url)) {  $prefix = explode(":", $url);  if ($prefix[0] == 'mailto') {   $url = $url;  } else {        $url = "http://".$url;  }    }    $last = $url[strlen($url) - 1];    if ($last == "/") {        $url = substr($url, 0, -1);    }    $data = @parse_url($url);  if ($prefix[0] == 'mailto') {   $data['scheme'] = 'mailto';   $data['host'] = 'none';  }    if (strlen($url) == 0) {        $_ERROR[] = "Please enter a URL to shorten.";    }    else if (empty($data['scheme']) || empty($data['host'])) {        $_ERROR[] = "Please enter a valid URL to shorten.";    }    else {        $hostname = get_hostname();        $domain   = get_domain();        if (preg_match("/($hostname)/i", $data['host'])) {            $_ERROR[] = "The URL you have entered is not allowed.";        }    }    if (strlen($alias) > 0) {        if (!preg_match("/^[a-zA-Z0-9_-]+$/", $alias)) {            $_ERROR[] = "Custom aliases may only contain letters, numbers, underscores and dashes.";        }        else if (code_exists($alias) || alias_exists($alias)) {            $_ERROR[] = "The custom alias you entered already exists.";        }    }    if (count($_ERROR) == 0) {        $create = true;        if (($url_data = url_exists($url))) {            $create    = false;            $id        = $url_data[0];            $code      = $url_data[1];            $old_alias = $url_data[2];            if (strlen($alias) > 0) {                if ($old_alias != $alias) {                    $create = true;                }            }        }        if ($create) {            do {                $code = generate_code(get_last_number());                if (!increase_last_number()) {                    die("System error!");                }                if (code_exists($code) || alias_exists($code)) {                    continue;                }                break;            } while (1);            $id = insert_url($url, $code, $alias);        }        if (strlen($alias) > 0) {            $code = $alias;        }        $short_url = SITE_URL."/".$code;        $_GET['url']   = "";        $_GET['alias'] = "";        require_once("html/header.php");        require_once("html/index_done.php");        require_once("html/index_form.php");        require_once("html/footer.php");        exit();    }}require_once("html/header.php");require_once("html/index_form.php");require_once("html/footer.php");


위 소스에서   $_ERROR[] = "Please enter a valid URL to shorten."; 오류메시지를 php에서 불러오게 하고싶은데 어떻게 하면될까요?

$_ERROR[] = require_once("html/error1.php"); 이렇게 해봤으나 밑에 숫자1이 나오네요;;

부탁드립니다 ㅠ

|

답변 1개 / 댓글 1개

채택된 답변
+20 포인트

내용은 길어 읽지 않았습니다 ㅎㅎ

$_ERROR[] = require_once("html/error1.php");//1 리턴 한다는 것은 성공적으로

error1.php불러 왔다는 겁니다.

다시 얘기하면 require_once가 성공하면 true, 실패하면 false값을 리턴하기 때문이죠.

error1.php 파일 내에 $_ERROR = array();로 선언하고

사용하셔야 할 듯 하군요.

require_once("html/error1.php");

$ERROR = "추가할 에러 내용"; 이런 식으로 사용하셔야 할 듯... 

답변에 대한 댓글 1개

$_ERROR = array();로 선언할줄몰라서 ㅎㅎ;

require_once("html/error1.php");
$ERROR = "추가할 에러 내용";
이런식으로 사용했더니 되네요!! 정말감사합니다.

답변을 작성하려면 로그인이 필요합니다.