테스트 사이트 - 개발 중인 베타 버전입니다

php소스 질문이요 ㅠ 채택완료

김씨웹 9년 전 조회 3,567

</strong><strong><?php
define('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.

If you've already installed Phurl, then you MUST delete the install directory before it will function.");
}
?>
<?php
require_once("config.php");
require_once("functions.php");</strong></p><p><strong>db_connect();</strong></p><p><strong>if (count($_GET) > 0) {
    $url   = mysql_real_escape_string(trim($_GET['url']));
    $alias = mysql_real_escape_string(trim($_GET['alias']));</strong></p><p><strong>    if (!preg_match("/^(".URL_PROTOCOLS.")\:\/\//i", $url)) {
  $prefix = explode(":", $url);
  if ($prefix[0] == 'mailto') {
   $url = $url;
  } else {
        $url = "<a href='http://".$url'>http://".$url</a>;
  }
    }</strong></p><p><strong>    $last = $url[strlen($url) - 1];</strong></p><p><strong>    if ($last == "/") {
        $url = substr($url, 0, -1);
    }</strong></p><p><strong>    $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();</strong></p><p><strong>        if (preg_match("/($hostname)/i", $data['host'])) {
            $_ERROR[] = "The URL you have entered is not allowed.";
        }
    }</strong></p><p><strong>    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.";
        }
    }</strong></p><p><strong>    if (count($_ERROR) == 0) {
        $create = true;</strong></p><p><strong>        if (($url_data = url_exists($url))) {
            $create    = false;
            $id        = $url_data[0];
            $code      = $url_data[1];
            $old_alias = $url_data[2];</strong></p><p><strong>            if (strlen($alias) > 0) {
                if ($old_alias != $alias) {
                    $create = true;
                }
            }
        }</strong></p><p><strong>        if ($create) {
            do {
                $code = generate_code(get_last_number());</strong></p><p><strong>                if (!increase_last_number()) {
                    die("System error!");
                }</strong></p><p><strong>                if (code_exists($code) || alias_exists($code)) {
                    continue;
                }</strong></p><p><strong>                break;
            } while (1);</strong></p><p><strong>            $id = insert_url($url, $code, $alias);
        }</strong></p><p><strong>        if (strlen($alias) > 0) {
            $code = $alias;
        }</strong></p><p><strong>        $short_url = SITE_URL."/".$code;</strong></p><p><strong>        $_GET['url']   = "";
        $_GET['alias'] = "";</strong></p><p><strong>        require_once("html/header.php");
        require_once("html/index_done.php");
        require_once("html/index_form.php");
        require_once("html/footer.php");
        exit();
    }
}</strong></p><p><strong>require_once("html/header.php");
require_once("html/index_form.php");
require_once("html/footer.php");</strong><strong>


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

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

부탁드립니다 ㅠ

 

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

답변 1개

채택된 답변
+20 포인트
9년 전

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

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

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

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

 

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

사용하셔야 할 듯 하군요.

require_once("html/error1.php");

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

 

로그인 후 평가할 수 있습니다

답변에 대한 댓글 1개

김씨웹
9년 전
$_ERROR = array();로 선언할줄몰라서 ㅎㅎ;

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

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

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

로그인