为什么在我的网站上 运行 这个 php 脚本时我收到这个 'php parse error'?
Why am I receiving this 'php parse error' when running this php script on my website?
我正在使用一个在单独的论坛上提供的示例脚本,它允许我将票证提交表单嵌入到我的一个网页中。
我下载了示例脚本并替换了相关数据。问题是当我 运行 脚本时我收到一个错误。错误保存在脚本所在目录中的文件中。
我收到的错误是:
[13-Jan-2015 17:07:37 Europe/London] PHP Parse error: syntax error, unexpected ';', expecting ')' in /home/sinergqx/public_html/pages/new_ticket.php on line 46
当我收到错误时,我认为这只是提供的脚本中的错字,所以我完全按照错误消息的描述进行操作,并将 ;
替换为 )
.这仍然没有什么区别。
我不太确定是什么问题。我的知识非常有限php,所以我很难自己解决很多问题。
我在 Internet 上搜索了该错误,但没有找到说明在这种情况下该怎么做的线程。
如果对我之前看的帖子有帮助,那么您可以点击here查看。
最后,我提供了我正在使用的代码。这是我上传到我的网站的确切脚本。如下:
#!/usr/bin/php -q
<?php
#
# Configuration: Enter the url and key. That is it.
# url => URL to api/task/cron e.g # http://yourdomain.com/support/api/tickets.json
# key => API's Key (see admin panel on how to generate a key)
# $data add custom required fields to the array.
#
# Originally authored by jared@osTicket.com
# Modified by ntozier@osTicket / tmib.net
// If 1, display things to debug.
$debug="0";
// You must configure the url and key in the array below.
$config = array(
'url'=>'http://support.sinergycraft.net/api/cron.php', // URL to site.tld/api/tickets.json
'key'=>'I WOULD PUT MY API HERE' // API Key goes here
);
# NOTE: some people have reported having to use "http://your.domain.tld/api/http.php/tickets.json" instead.
if($config['url'] === 'http://your.domain.tld/api/tickets.json') {
echo "<p style=\"color:red;\"><b>Error: No URL</b><br>You have not configured this script with your URL!</p>";
echo "Please edit this file ".__FILE__." and add your URL at line 18.</p>";
die();
}
if(IsNullOrEmptyString($config['key']) || ($config['key'] === 'PUTyourAPIkeyHERE')) {
echo "<p style=\"color:red;\"><b>Error: No API Key</b><br>You have not configured this script with an API Key!</p>";
echo "<p>Please log into osticket as an admin and navigate to: Admin panel -> Manage -> Api Keys then add a new API Key.<br>";
echo "Once you have your key edit this file ".__FILE__." and add the key at line 19.</p>";
die();
}
# Fill in the data for the new ticket, this will likely come from $_POST.
# NOTE: your variable names in osT are case sensiTive.
# So when adding custom lists or fields make sure you use the same case
# For examples on how to do that see Agency and Site below.
$data = array(
'name' => 'John Doe', // from name aka User/Client Name
'email' => 'john@gmail.com', // from email aka User/Client Email
'phone' => '1234567890', // phone number aka User/Client Phone Number
'subject' => 'Test API message', // test subject, aka Issue Summary
'message' => 'This is a test of the osTicket API', // test ticket body, aka Issue Details.
'ip' => $_SERVER['REMOTE_ADDR'], // Should be IP address of the machine thats trying to open the ticket.
'topicId' => '1'; // the help Topic that you want to use for the ticket --L46
//'Agency' => '58', //this is an example of a custom list entry. This should be the number of the entry.
//'Site' => 'Bermuda'; // this is an example of a custom text field. You can push anything into here you want.
'attachments' => array()
);
# more fields are available and are documented at:
# https://github.com/osTicket/osTicket-1.8/blob/develop/setup/doc/api/tickets.md
if($debug=='1') {
print_r($data);
die();
}
# Add in attachments here if necessary
# Note: there is something with this wrong with the file attachment here it does not work.
$data['attachments'][] =
array('file.txt' =>
'data:text/plain;base64;'
.base64_encode(file_get_contents('/file.txt'))); // replace ./file.txt with /path/to/your/test/filename.txt
#pre-checks
function_exists('curl_version') or die('CURL support required');
function_exists('json_encode') or die('JSON support required');
#set timeout
set_time_limit(30);
#curl post
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $config['url']);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));
curl_setopt($ch, CURLOPT_USERAGENT, 'osTicket API Client v1.8');
curl_setopt($ch, CURLOPT_HEADER, FALSE);
curl_setopt($ch, CURLOPT_HTTPHEADER, array( 'Expect:', 'X-API-Key: '.$config['key']));
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, FALSE);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
$result=curl_exec($ch);
$code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
if ($code != 201)
die('Unable to create ticket: '.$result);
$ticket_id = (int) $result;
# Continue onward here if necessary. $ticket_id has the ID number of the
# newly-created ticket
function IsNullOrEmptyString($question){
return (!isset($question) || trim($question)==='');
}
?>
唯一与我上传时不同的是,我删除了 api 密钥并将其替换为 I WOULD PUT MY API HERE
。
此外,虽然在代码的注释部分它说 link 到 http://your.domain.tld/api/http.php/tickets.json
,但我的任何目录中都不存在,所以我 link 将其编辑为 http://your.domain.tld/api/http.php/cron.php
。我这样做是因为它在顶部的评论部分说 url => URL to api/task/cron e.g # http://yourdomain.com/support/api/tickets.json
.
有谁知道我做错了什么,因为我已经按照错误消息中的说明做了,但我没有任何运气。
感谢任何人的帮助,非常感谢,因为我是 php 的真正初学者。
编辑:
我确实查看了第 46 行并看到 ;
并将其替换为 )
,错误消息向我提示这是错误的,但它没有解决问题。
更改此行:
'topicId' => '1';
对此:
'topicId' => '1',
//^ You have to use a comma to separate each array element
有关数组的更多信息,请参阅手册:http://php.net/manual/en/language.types.array.php
引自那里:
An array can be created using the array() language construct. It takes any number of comma-separated key => value pairs as arguments.
也作为一个很好的参考,哪个错误意味着什么看到这个:Reference - What does this error mean in PHP?
'topicId' => '1'; // the help Topic that you want to use for the ticket
它在数组定义的中间,所以它应该是 ,
,而不是 ;
或 )
。
刚刚阅读你的代码我发现有一个';'在第 46 行。
查看第 46 行我是 ';'哪里需要一个','。我怎么知道呢?因为它是一个数组,查看数组中变量的另一端行,您会看到从一个值到另一个值需要一个“,”来分隔它们。
这是您更正后的代码:
#!/usr/bin/php -q
<?php
#
# Configuration: Enter the url and key. That is it.
# url => URL to api/task/cron e.g # http://yourdomain.com/support/api/tickets.json
# key => API's Key (see admin panel on how to generate a key)
# $data add custom required fields to the array.
#
# Originally authored by jared@osTicket.com
# Modified by ntozier@osTicket / tmib.net
// If 1, display things to debug.
$debug="0";
// You must configure the url and key in the array below.
$config = array(
'url'=>'http://support.sinergycraft.net/api/cron.php', // URL to site.tld/api/tickets.json
'key'=>'I WOULD PUT MY API HERE' // API Key goes here
);
# NOTE: some people have reported having to use "http://your.domain.tld/api/http.php/tickets.json" instead.
if($config['url'] === 'http://your.domain.tld/api/tickets.json') {
echo "<p style=\"color:red;\"><b>Error: No URL</b><br>You have not configured this script with your URL!</p>";
echo "Please edit this file ".__FILE__." and add your URL at line 18.</p>";
die();
}
if(IsNullOrEmptyString($config['key']) || ($config['key'] === 'PUTyourAPIkeyHERE')) {
echo "<p style=\"color:red;\"><b>Error: No API Key</b><br>You have not configured this script with an API Key!</p>";
echo "<p>Please log into osticket as an admin and navigate to: Admin panel -> Manage -> Api Keys then add a new API Key.<br>";
echo "Once you have your key edit this file ".__FILE__." and add the key at line 19.</p>";
die();
}
# Fill in the data for the new ticket, this will likely come from $_POST.
# NOTE: your variable names in osT are case sensiTive.
# So when adding custom lists or fields make sure you use the same case
# For examples on how to do that see Agency and Site below.
$data = array(
'name' => 'John Doe', // from name aka User/Client Name
'email' => 'john@gmail.com', // from email aka User/Client Email
'phone' => '1234567890', // phone number aka User/Client Phone Number
'subject' => 'Test API message', // test subject, aka Issue Summary
'message' => 'This is a test of the osTicket API', // test ticket body, aka Issue Details.
'ip' => $_SERVER['REMOTE_ADDR'], // Should be IP address of the machine thats trying to open the ticket.
'topicId' => '1', // the help Topic that you want to use for the ticket
//'Agency' => '58', //this is an example of a custom list entry. This should be the number of the entry.
//'Site' => 'Bermuda'; // this is an example of a custom text field. You can push anything into here you want.
'attachments' => array()
);
# more fields are available and are documented at:
# https://github.com/osTicket/osTicket-1.8/blob/develop/setup/doc/api/tickets.md
if($debug=='1') {
print_r($data);
die();
}
# Add in attachments here if necessary
# Note: there is something with this wrong with the file attachment here it does not work.
$data['attachments'][] =
array('file.txt' =>
'data:text/plain;base64;'
.base64_encode(file_get_contents('/file.txt'))); // replace ./file.txt with /path/to/your/test/filename.txt
#pre-checks
function_exists('curl_version') or die('CURL support required');
function_exists('json_encode') or die('JSON support required');
#set timeout
set_time_limit(30);
#curl post
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $config['url']);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));
curl_setopt($ch, CURLOPT_USERAGENT, 'osTicket API Client v1.8');
curl_setopt($ch, CURLOPT_HEADER, FALSE);
curl_setopt($ch, CURLOPT_HTTPHEADER, array( 'Expect:', 'X-API-Key: '.$config['key']));
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, FALSE);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
$result=curl_exec($ch);
$code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
if ($code != 201)
die('Unable to create ticket: '.$result);
$ticket_id = (int) $result;
# Continue onward here if necessary. $ticket_id has the ID number of the
# newly-created ticket
function IsNullOrEmptyString($question){
return (!isset($question) || trim($question)==='');
}
?>
我正在使用一个在单独的论坛上提供的示例脚本,它允许我将票证提交表单嵌入到我的一个网页中。
我下载了示例脚本并替换了相关数据。问题是当我 运行 脚本时我收到一个错误。错误保存在脚本所在目录中的文件中。
我收到的错误是:
[13-Jan-2015 17:07:37 Europe/London] PHP Parse error: syntax error, unexpected ';', expecting ')' in /home/sinergqx/public_html/pages/new_ticket.php on line 46
当我收到错误时,我认为这只是提供的脚本中的错字,所以我完全按照错误消息的描述进行操作,并将 ;
替换为 )
.这仍然没有什么区别。
我不太确定是什么问题。我的知识非常有限php,所以我很难自己解决很多问题。
我在 Internet 上搜索了该错误,但没有找到说明在这种情况下该怎么做的线程。
如果对我之前看的帖子有帮助,那么您可以点击here查看。
最后,我提供了我正在使用的代码。这是我上传到我的网站的确切脚本。如下:
#!/usr/bin/php -q
<?php
#
# Configuration: Enter the url and key. That is it.
# url => URL to api/task/cron e.g # http://yourdomain.com/support/api/tickets.json
# key => API's Key (see admin panel on how to generate a key)
# $data add custom required fields to the array.
#
# Originally authored by jared@osTicket.com
# Modified by ntozier@osTicket / tmib.net
// If 1, display things to debug.
$debug="0";
// You must configure the url and key in the array below.
$config = array(
'url'=>'http://support.sinergycraft.net/api/cron.php', // URL to site.tld/api/tickets.json
'key'=>'I WOULD PUT MY API HERE' // API Key goes here
);
# NOTE: some people have reported having to use "http://your.domain.tld/api/http.php/tickets.json" instead.
if($config['url'] === 'http://your.domain.tld/api/tickets.json') {
echo "<p style=\"color:red;\"><b>Error: No URL</b><br>You have not configured this script with your URL!</p>";
echo "Please edit this file ".__FILE__." and add your URL at line 18.</p>";
die();
}
if(IsNullOrEmptyString($config['key']) || ($config['key'] === 'PUTyourAPIkeyHERE')) {
echo "<p style=\"color:red;\"><b>Error: No API Key</b><br>You have not configured this script with an API Key!</p>";
echo "<p>Please log into osticket as an admin and navigate to: Admin panel -> Manage -> Api Keys then add a new API Key.<br>";
echo "Once you have your key edit this file ".__FILE__." and add the key at line 19.</p>";
die();
}
# Fill in the data for the new ticket, this will likely come from $_POST.
# NOTE: your variable names in osT are case sensiTive.
# So when adding custom lists or fields make sure you use the same case
# For examples on how to do that see Agency and Site below.
$data = array(
'name' => 'John Doe', // from name aka User/Client Name
'email' => 'john@gmail.com', // from email aka User/Client Email
'phone' => '1234567890', // phone number aka User/Client Phone Number
'subject' => 'Test API message', // test subject, aka Issue Summary
'message' => 'This is a test of the osTicket API', // test ticket body, aka Issue Details.
'ip' => $_SERVER['REMOTE_ADDR'], // Should be IP address of the machine thats trying to open the ticket.
'topicId' => '1'; // the help Topic that you want to use for the ticket --L46
//'Agency' => '58', //this is an example of a custom list entry. This should be the number of the entry.
//'Site' => 'Bermuda'; // this is an example of a custom text field. You can push anything into here you want.
'attachments' => array()
);
# more fields are available and are documented at:
# https://github.com/osTicket/osTicket-1.8/blob/develop/setup/doc/api/tickets.md
if($debug=='1') {
print_r($data);
die();
}
# Add in attachments here if necessary
# Note: there is something with this wrong with the file attachment here it does not work.
$data['attachments'][] =
array('file.txt' =>
'data:text/plain;base64;'
.base64_encode(file_get_contents('/file.txt'))); // replace ./file.txt with /path/to/your/test/filename.txt
#pre-checks
function_exists('curl_version') or die('CURL support required');
function_exists('json_encode') or die('JSON support required');
#set timeout
set_time_limit(30);
#curl post
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $config['url']);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));
curl_setopt($ch, CURLOPT_USERAGENT, 'osTicket API Client v1.8');
curl_setopt($ch, CURLOPT_HEADER, FALSE);
curl_setopt($ch, CURLOPT_HTTPHEADER, array( 'Expect:', 'X-API-Key: '.$config['key']));
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, FALSE);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
$result=curl_exec($ch);
$code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
if ($code != 201)
die('Unable to create ticket: '.$result);
$ticket_id = (int) $result;
# Continue onward here if necessary. $ticket_id has the ID number of the
# newly-created ticket
function IsNullOrEmptyString($question){
return (!isset($question) || trim($question)==='');
}
?>
唯一与我上传时不同的是,我删除了 api 密钥并将其替换为 I WOULD PUT MY API HERE
。
此外,虽然在代码的注释部分它说 link 到 http://your.domain.tld/api/http.php/tickets.json
,但我的任何目录中都不存在,所以我 link 将其编辑为 http://your.domain.tld/api/http.php/cron.php
。我这样做是因为它在顶部的评论部分说 url => URL to api/task/cron e.g # http://yourdomain.com/support/api/tickets.json
.
有谁知道我做错了什么,因为我已经按照错误消息中的说明做了,但我没有任何运气。
感谢任何人的帮助,非常感谢,因为我是 php 的真正初学者。
编辑:
我确实查看了第 46 行并看到 ;
并将其替换为 )
,错误消息向我提示这是错误的,但它没有解决问题。
更改此行:
'topicId' => '1';
对此:
'topicId' => '1',
//^ You have to use a comma to separate each array element
有关数组的更多信息,请参阅手册:http://php.net/manual/en/language.types.array.php
引自那里:
An array can be created using the array() language construct. It takes any number of comma-separated key => value pairs as arguments.
也作为一个很好的参考,哪个错误意味着什么看到这个:Reference - What does this error mean in PHP?
'topicId' => '1'; // the help Topic that you want to use for the ticket
它在数组定义的中间,所以它应该是 ,
,而不是 ;
或 )
。
刚刚阅读你的代码我发现有一个';'在第 46 行。
查看第 46 行我是 ';'哪里需要一个','。我怎么知道呢?因为它是一个数组,查看数组中变量的另一端行,您会看到从一个值到另一个值需要一个“,”来分隔它们。
这是您更正后的代码:
#!/usr/bin/php -q
<?php
#
# Configuration: Enter the url and key. That is it.
# url => URL to api/task/cron e.g # http://yourdomain.com/support/api/tickets.json
# key => API's Key (see admin panel on how to generate a key)
# $data add custom required fields to the array.
#
# Originally authored by jared@osTicket.com
# Modified by ntozier@osTicket / tmib.net
// If 1, display things to debug.
$debug="0";
// You must configure the url and key in the array below.
$config = array(
'url'=>'http://support.sinergycraft.net/api/cron.php', // URL to site.tld/api/tickets.json
'key'=>'I WOULD PUT MY API HERE' // API Key goes here
);
# NOTE: some people have reported having to use "http://your.domain.tld/api/http.php/tickets.json" instead.
if($config['url'] === 'http://your.domain.tld/api/tickets.json') {
echo "<p style=\"color:red;\"><b>Error: No URL</b><br>You have not configured this script with your URL!</p>";
echo "Please edit this file ".__FILE__." and add your URL at line 18.</p>";
die();
}
if(IsNullOrEmptyString($config['key']) || ($config['key'] === 'PUTyourAPIkeyHERE')) {
echo "<p style=\"color:red;\"><b>Error: No API Key</b><br>You have not configured this script with an API Key!</p>";
echo "<p>Please log into osticket as an admin and navigate to: Admin panel -> Manage -> Api Keys then add a new API Key.<br>";
echo "Once you have your key edit this file ".__FILE__." and add the key at line 19.</p>";
die();
}
# Fill in the data for the new ticket, this will likely come from $_POST.
# NOTE: your variable names in osT are case sensiTive.
# So when adding custom lists or fields make sure you use the same case
# For examples on how to do that see Agency and Site below.
$data = array(
'name' => 'John Doe', // from name aka User/Client Name
'email' => 'john@gmail.com', // from email aka User/Client Email
'phone' => '1234567890', // phone number aka User/Client Phone Number
'subject' => 'Test API message', // test subject, aka Issue Summary
'message' => 'This is a test of the osTicket API', // test ticket body, aka Issue Details.
'ip' => $_SERVER['REMOTE_ADDR'], // Should be IP address of the machine thats trying to open the ticket.
'topicId' => '1', // the help Topic that you want to use for the ticket
//'Agency' => '58', //this is an example of a custom list entry. This should be the number of the entry.
//'Site' => 'Bermuda'; // this is an example of a custom text field. You can push anything into here you want.
'attachments' => array()
);
# more fields are available and are documented at:
# https://github.com/osTicket/osTicket-1.8/blob/develop/setup/doc/api/tickets.md
if($debug=='1') {
print_r($data);
die();
}
# Add in attachments here if necessary
# Note: there is something with this wrong with the file attachment here it does not work.
$data['attachments'][] =
array('file.txt' =>
'data:text/plain;base64;'
.base64_encode(file_get_contents('/file.txt'))); // replace ./file.txt with /path/to/your/test/filename.txt
#pre-checks
function_exists('curl_version') or die('CURL support required');
function_exists('json_encode') or die('JSON support required');
#set timeout
set_time_limit(30);
#curl post
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $config['url']);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));
curl_setopt($ch, CURLOPT_USERAGENT, 'osTicket API Client v1.8');
curl_setopt($ch, CURLOPT_HEADER, FALSE);
curl_setopt($ch, CURLOPT_HTTPHEADER, array( 'Expect:', 'X-API-Key: '.$config['key']));
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, FALSE);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
$result=curl_exec($ch);
$code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
if ($code != 201)
die('Unable to create ticket: '.$result);
$ticket_id = (int) $result;
# Continue onward here if necessary. $ticket_id has the ID number of the
# newly-created ticket
function IsNullOrEmptyString($question){
return (!isset($question) || trim($question)==='');
}
?>