Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Php issue

Status
Not open for further replies.

Netwrkengeer

IS-IT--Management
Apr 4, 2001
184
US
I just wrote some code, and I'm getting an error

Warning: Failed opening '/usr/home/jbh/htdocs/codetest.phtml' for inclusion (include_path='.:/usr/local/lib/php') in /usr/home/jbh/htdocs/pagetest.phtml on line 9

Fatal error: Call to undefined function: codetest() in /usr/home/jbh/htdocs/pagepost.phtml on line 14

/*
this is the pagetest.phtml code
*/
<?php

include(&quot;codetest.phtml&quot;);

$d[&quot;foo&quot;] = &quot;some&quot;;
$d[&quot;bar&quot;] = &quot;data&quot;;

$Result = PostIt($d, &quot;
if (isset($Result[&quot;errno&quot;])) {
$errno = $Result[&quot;errno&quot;]; $errstr = $Result[&quot;errstr&quot;];
echo &quot;<B>Error $errno</B> $errstr&quot;;
exit;
}
else {
while (list($key, $val) = each($Result)) echo $val;
}
?>

/*
this is the codetest.phtml code
*/
<?php

function codetest($DataStream, $URL) {

// Strip http:// from the URL if present
$URL = ereg_replace(&quot;^ &quot;&quot;, $URL);

// Separate into Host and URI
$Host = substr($URL, 0, strpos($URL, &quot;/&quot;));
$URI = strstr($URL, &quot;/&quot;);

// Form up the request body
$ReqBody = &quot;&quot;;
while (list($key, $val) = each($DataStream)) {
if ($ReqBody) $ReqBody.= &quot;&&quot;;
$ReqBody.= $key.&quot;=&quot;.urlencode($val);
}
$ContentLength = strlen($ReqBody);

// Generate the request header
$ReqHeader =
&quot;POST $URI HTTP/1.1\n&quot;.
&quot;Host: $Host\n&quot;.
&quot;User-Agent: PostIt\n&quot;.
&quot;Content-Type: application/x- &quot;Content-Length: $ContentLength\n\n&quot;.
&quot;$ReqBody\n&quot;;

// Open the connection to the host
$socket = fsockopen($Host, 80, &$errno, &$errstr);
if (!$socket) {
$Result[&quot;errno&quot;] = $errno;
$Result[&quot;errstr&quot;] = $errstr;
return $Result;
}
$idx = 0;
fputs($socket, $ReqHeader);
while (!feof($socket)) {
$Result[$idx++] = fgets($socket, 128);
}
return $Result;
}
?>

/*
thanks Rob
*/
 
This is kind of strange. Are you sure you are showing all the code from these two pages?

The error message refers to &quot;undefined function: codetest()&quot;, in pagetest.phtml, but I don't see where pagetest.phtml is trying to call that function.

pagetest.phtml is also calling for a function called PostIt(), which is not defined anywhere, so it should be generating an error message.

Also, the include error is at line 9, but I see pagetest.phtml calling for the include at line 3.

Anyway, your PHP include path is &quot;/usr/local/lib/php&quot;, from your php.ini file, which means that when you reference an include without full path information, that file should be in &quot;/usr/local/lib/php&quot;. If you want to reference an include from any other location on your system, you need to provide the full path, such as
Code:
include(&quot;/usr/home/jbh/htdocs/codetest.phtml&quot;)
.

There is a PHP forum in Tek-Tips, in case you need more help with PHP.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top