Forum Moderators: coopster
NOTE: $res variable gets populated from the result of [ $res = `/usr/bin/curl -m 120 -d "$data" '$url' `; ]
I cant get this part to work [ echo "array[2] <-- >$line[2]<BR>"; ] etc.
I need to echo the ccdata.txt file.
please help
<?
$fp = fopen("ccdata.txt","w");
if(!$fp) {
print "error! The file could not be opened";
exit;
}
fwrite($fp, $res);
$fp = @fopen($ccdata.txt, 'r');
if ($fp) {
$array = explode("\n", fread($fp, filesize($filename)));
}
echo "array[2] <-- >$line[2]<BR>";
echo "array[3] <-- >$array[3]<BR>";
echo "array[4] <-- >$array[4]<BR>";
echo "array[5] <-- >$array[5]<BR>";
echo "array[6] <-- >$array[6]<BR>";
echo "array[7] <-- >$array[7]<p>";
?>
Note: After the above code excutes, the ccdata.txt file contains the following:
-----ccdata.txt starts here------
<?xml version="1.0" encoding="UTF-8"?>
- <response>
<status>2</status>
<result>105</result>
<msg>Error authenticating user</msg>
<error>com.consilience.portal.PortalException: Invalid username/password combination</error>
</response>
-----ccdata.txt ends here------
Where is the "Invalid username/password combination" coming from?
I can only guess that $res seems somehow unavailable.
I don't really get why you are writing and reading in the same piece of code to the same file. I would also think that opening the same file twice with out closing it seems strange. You could just open it for read/write the first time or close it in between.
Mitch888 [webmasterworld.com] wrote at 06:30 on Feb. 08, 2003 in message #1 [webmasterworld.com]
<?
$fp = @fopen($ccdata.txt, 'r');
if ($fp) {
$array = explode("\n", fread($fp, filesize($filename)));
}
This code will only do what you expect if $ccdata and $filename are defined and contain the string "ccdata". If that is not the case then the call to [url=http://www.php.net/fopen]fopen() [php.net][/url] will silently fail since the parser sees the variable $ccdata followed by the concatenation operator and the bareword txt. Since txt is no reserved word it will be interpreted as a string. So if $ccdata is not defined the filename will be "txt" and PHP will try to open this file which will probably not exist.
Even if $ccdata contained the right string [url=http://www.php.net/fread][url=http://www.php.net/fread]fread() [php.net][/url][/url] would fail unless $filename contained "ccdata.txt". If that´s not the case [url=http://www.php.net/filesize][url=http://www.php.net/filesize]filesize() [php.net][/url][/url] will return false which is not of type int which is what [url=http://www.php.net/fread][url=http://www.php.net/fread]fread() [php.net][/url][/url] expects as its second parameter.
While testing a script do not use the @ to suppress error messages.
jatar_k [webmasterworld.com] wrote at 04:10 on Feb. 08, 2003 in message #2 [webmasterworld.com]
Where is the "Invalid username/password combination" coming from?
That´s the result of the call to /usr/bin/curl in backticks and mentioned in Mitch´s post.
Andreas
[edited by: andreasfriedrich at 4:57 pm (utc) on Feb. 8, 2003]
didn't know
But you do now? :)
The same could be done using PHP´s CURL [php.net] interface.
Andreas
I thought I can writr the result into a text file (done it successfully) and then read it into array but for some reason I can't display the array
echo "array[2] <-- >$line[2]<BR>";
echo "array[3] <-- >$array[3]<BR>";
echo "array[4] <-- >$array[4]<BR>";
echo "array[5] <-- >$array[5]<BR>";
echo "array[6] <-- >$array[6]<BR>";
echo "array[7] <-- >$array[7]<p>";