PDA

View Full Version : Parse error دیگه چیه؟



sargardoon
سه شنبه 23 فروردین 1390, 18:24 عصر
سلام دوستان، من یه کلاس form validation نوشتم، روی لوکال هاست کار میکنه مشکلی نداره ولی زمانی که این فایل رو میذارم رو هاست (آنلاین)، این پیغام رو بهم میده



Parse error: syntax error, unexpected T_STRING, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}' in /home/webnegas/public_html/phptut/validation.class.php on line 5


این هم مشخصاتی از هاست:
Apache version 2.2.17
PHP version 5.2.14
MySQL version 5.0.92-community
Architecture x86_64
Operating system linux

نگاه هم کردم هیچ جا مشکلی نداشت. اگر لازم بود بگید تا فایل رو هم بذارم.

Mr.Moghadam
سه شنبه 23 فروردین 1390, 19:18 عصر
فایل رو بذار

sargardoon
سه شنبه 23 فروردین 1390, 19:43 عصر
فایل رو بذار


<?php

if (isset($_POST['submit'])) {
require_once "validation.class.php";

$name = trim($_POST['name']);
$email = trim($_POST['email']);
$website = trim($_POST['website']);

$validate = new Validation();
$validate -> isValidStr($name, 'name', 2, 32);
$validate -> isValidEmail($email);
$validate -> isValidURL($website);

if (!$validate -> errCount()) {
echo '<h3>You have Successfully Registered</h3>';
echo "Name: {$name} | Email: {$email} | Website: {$website}";
} else {
$errCount = $validate -> errCount();
$errCount = 'There were '.$errCount.' errors, Please fill the required fields';
$errName = $validate -> getError('name');
$errEmail = $validate -> getError('email');
$errURL = $validate -> getError('url');
}
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Class :: Validation Form</title>
</head>
<body>
<form action="" method="post">
<?php echo '<h4>'.$errCount.'</h4>'; ?>
<table border="0" cellpadding="2" cellspacing="2">
<tr>
<td>Name:</td>
<td>
<input type="text" name="name" value="<?php echo htmlentities($name); ?>" /><br />
<?php echo $errName; ?>
</td>
</tr>
<tr>
<td>email:</td>
<td>
<input type="text" name="email" value="<?php echo htmlentities($email); ?>" /><br />
<?php echo $errEmail; ?>
</td>
</tr>
<tr>
<td>website:</td>
<td>
<input type="text" name="website" value="<?php echo htmlentities($website); ?>" /><br />
<?php echo $errURL; ?>
</td>
</tr>
<tr>
<td></td>
<td><input type="submit" name="submit" value=" Register " /></td>
</tr>
</table>
</form>
</body>
</html>



<?php

class Validation
{
public $errors = array();

public function isValidStr($strVal, $strType, $minChar=2, $maxChar = 1000) {
if(strlen($strVal) < intval($minChar)) {
$this -> setError($strType, ucfirst($strType)." must be at least {$minChar} characters long.");
} elseif (strlen($strVal) > intval($maxChar)) {
$this -> setError($strType, ucfirst($strType)." must be less than {$maxChar} characters long.");
} else {
// validate data entry
$pattern = "#^[\s\x{0621}-\x{063A}\x{0640}-\x{0691}\x{0698}-\x{06D2}\x{06F0}-\x{06F9}\x{0661}-\x{0669}0-9\n\r\\'\-\_\.\:\,0-9a-zA-Z]+$#u";
if (!preg_match($pattern, $strVal)) {
$this -> setError($strType, ucfirst($strType)." must be from letters, dashes, spaces and must not start with dash");
}
}
}

public function isValidEmail($emailVal) {
if(strlen($strVal) < 0 ) {
$this -> setError('email', 'E-mail Address cannot be blank');
} else {
// validate data entry
$pattern = "/^[^0-9][A-z0-9_]+([.][A-z0-9_]+)*[@][A-z0-9_]+([.][A-z0-9_]+)*[.][A-z]{2,4}$/";
if (!preg_match($pattern, $emailVal)) {
$this -> setError('email', 'Please enter valid E-mail Address');
}
}
}


public function isValidURL($urlVal) {
if(!empty($urlVal)) {
$pattern = "#^http(s)?://[a-z0-9-_.]+\.[a-z]{2,4}#i";
if (!preg_match($pattern, $urlVal)) {
$this -> setError('url', 'Please enter valid URL Address with http://');
}
}
}


public function setError($key, $value) {
$this -> errors[$key] = $value;
}

public function getError($key) {
if ($this -> errors[$key]) {
return $this -> errors[$key];
} else {
return false;
}
}


public function errCount() {
return (count($this -> errors) > 0) ? count($this -> errors) : false;
}
}

?>



این هم فایل
68637

Mr.Moghadam
سه شنبه 23 فروردین 1390, 21:28 عصر
خط

public $errors = array();
رو به صورت زیر بنویس


var $errors = array();

sargardoon
سه شنبه 23 فروردین 1390, 21:42 عصر
خط

public $errors = array();
رو به صورت زیر بنویس


var $errors = array();

ممنونم دوست عزیز از راهنمایی، من این که گفتید رو امتحان کردم باز این پیام خطا را داد

Parse error: syntax error, unexpected T_STRING, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}' in /home/webnegas/public_html/phptut/validation.class.php on line 7

تمام کلمات public را پاک کردم جواب داد. شما دلیلش رو میدونید چیه؟

sargardoon
سه شنبه 23 فروردین 1390, 21:56 عصر
یه سوالی دیگه ای که داشتم چرا روی لوکال هاست
__construct کار نمیکنه؟ من به جای این هم اسم کلاس گذاشتم کار کرد.

Mr.Moghadam
سه شنبه 23 فروردین 1390, 22:46 عصر
پیغام های بالا به خاطر اینه که ورژن پی اچ پی که داری استفاده میکنی قدیمیه احتمالا 5.1
که باید به 5.3 به بعد (اگه اشتباه نکنم) ارتقا بدی تا با اینجوری مشکلات توی شی گرایی بر نخوری

sargardoon
سه شنبه 23 فروردین 1390, 22:53 عصر
پیغام های بالا به خاطر اینه که ورژن پی اچ پی که داری استفاده میکنی قدیمیه احتمالا 5.1
که باید به 5.3 به بعد (اگه اشتباه نکنم) ارتقا بدی تا با اینجوری مشکلات توی شی گرایی بر نخوری

ورژن PHP version 5.2.14 استفاده میکنم، من توی گوگل سرچ کردم بیشتر برای وژن 5 به پایین این مشکل رو داشت. (البته برای پیغام بالایی)
برای اینکه امنیت کلاسها بالا بره باید چه کار کرد؟ از protected که نتونستم استفاده کنم پیغام خطا میداد.

sargardoon
چهارشنبه 24 فروردین 1390, 12:25 عصر
کسی دلیل این رو نمیدونه؟