Turn on suggestions
Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.
Showing results for
Simple(?) PHP problem - Echo not working
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Plusnet Community
- :
- Forum
- :
- Help with my Plusnet services
- :
- Everything else
- :
- Simple(?) PHP problem - Echo not working
Simple(?) PHP problem - Echo not working
27-03-2012 11:18 AM
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Report to Moderator
Hi,
Should be straightforward but the PHP Echo or Print commands are not working with my ISP (Freezone).
I want to use:
<?php
echo file_get_contents('lastupd.log');
?>
where lastupd.log is a text file with a string in it, eg, Tuesday 27th March 2012.
I have a few PHP scripts running which are fine - they use echo "document.write......"
I have tried a simple Echo "hello world" but it will not display.
I have embedded the command in my html page use <?php and ?>.
I have also saved the command within a php script and called it from the html page.
For testing purposes I have set permissions to the max.
Could it be a setting on the ISP's server ?
Hopefully it is something very silly that I am not doing.
Thanks in anticipation.
Peter
Should be straightforward but the PHP Echo or Print commands are not working with my ISP (Freezone).
I want to use:
<?php
echo file_get_contents('lastupd.log');
?>
where lastupd.log is a text file with a string in it, eg, Tuesday 27th March 2012.
I have a few PHP scripts running which are fine - they use echo "document.write......"
I have tried a simple Echo "hello world" but it will not display.
I have embedded the command in my html page use <?php and ?>.
I have also saved the command within a php script and called it from the html page.
For testing purposes I have set permissions to the max.
Could it be a setting on the ISP's server ?
Hopefully it is something very silly that I am not doing.
Thanks in anticipation.
Peter
Message 1 of 5
(16,576 Views)
4 REPLIES 4
Re: Simple(?) PHP problem - Echo not working
27-03-2012 3:13 PM
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Report to Moderator
Are you sure you are using echo "document.write......" in a PHP section? That looks more like JavaScript to me.
Do Freezone require all CGI scripts (which includes .php ones) to be located in the cgi-bin directory? Did you create the file using a plain text editor (eg Notepad), and upload it in ASCII mode? The .php file might need file permissions 0755 but Freezone's help guides should explain what is required.
David
Do Freezone require all CGI scripts (which includes .php ones) to be located in the cgi-bin directory? Did you create the file using a plain text editor (eg Notepad), and upload it in ASCII mode? The .php file might need file permissions 0755 but Freezone's help guides should explain what is required.
David
David
Message 2 of 5
(1,987 Views)
Re: Simple(?) PHP problem - Echo not working
27-03-2012 5:51 PM
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Report to Moderator
Hi David - thank you for your response.
Firstly I should point out that, although I program a lot with VisualBasic, I am a 'copy & paste' programmer for PHP.
Freezone does not require scripts to be stored in the cgi-bin directory. My successful php files are in the root (httpdocs) directory.
I created the file using Notepad. I use FileZilla FTP and it is set to auto for transfers. I can successfully edit the script on the server using the built in ASCII editor.
As a temporary measure I have given all the files permission 0777.
I quote below the successful php file that uses "document.write":
<?php
//Assign variables to check script is called from within web site
$check_referer = 1;
$referers = array ("localhost","peterashby.com");
//Assign variable for counter
$log_name = "index";
// If $check_referer is 1 and if HTTP_REFERER is a value then check refering site
if ($check_referer == 1 && !(empty($_SERVER['HTTP_REFERER'])))
{
check_referer($_SERVER['HTTP_REFERER']);
}
//Get log name and style
$logfile = "logs/index.log";
// If the log file doesn't exist we start count from 1 ...
if (! @$file = fopen($logfile,"r+"))
{
$count="1";
}
// If the log file exist lets read count from it
else
{
$count = @fread($file, filesize($logfile)) or $count=0;
fclose($file);
}
// Print out code and exit
for ($i=0;$i<strlen($count);$i++) {
$digit=substr("$count",$i,1);
// Build the image URL ...
$src = "counter/style/" . $digit . "." . "gif";
echo "document.write('<img src=\"$src\" border=0>');\n";
}
// Exit script
exit();
// Function to check refering URL
function check_referer($thisurl)
{
global $referers;
for ($i=0;$i<count($referers);$i++)
{
if (preg_match("/$referers[$i]/i",$thisurl))
{
return true;
}
}
die("Error 4215 - Unauthorised script access!");
}
?>
Thanks again,
Peter
Firstly I should point out that, although I program a lot with VisualBasic, I am a 'copy & paste' programmer for PHP.
Freezone does not require scripts to be stored in the cgi-bin directory. My successful php files are in the root (httpdocs) directory.
I created the file using Notepad. I use FileZilla FTP and it is set to auto for transfers. I can successfully edit the script on the server using the built in ASCII editor.
As a temporary measure I have given all the files permission 0777.
I quote below the successful php file that uses "document.write":
<?php
//Assign variables to check script is called from within web site
$check_referer = 1;
$referers = array ("localhost","peterashby.com");
//Assign variable for counter
$log_name = "index";
// If $check_referer is 1 and if HTTP_REFERER is a value then check refering site
if ($check_referer == 1 && !(empty($_SERVER['HTTP_REFERER'])))
{
check_referer($_SERVER['HTTP_REFERER']);
}
//Get log name and style
$logfile = "logs/index.log";
// If the log file doesn't exist we start count from 1 ...
if (! @$file = fopen($logfile,"r+"))
{
$count="1";
}
// If the log file exist lets read count from it
else
{
$count = @fread($file, filesize($logfile)) or $count=0;
fclose($file);
}
// Print out code and exit
for ($i=0;$i<strlen($count);$i++) {
$digit=substr("$count",$i,1);
// Build the image URL ...
$src = "counter/style/" . $digit . "." . "gif";
echo "document.write('<img src=\"$src\" border=0>');\n";
}
// Exit script
exit();
// Function to check refering URL
function check_referer($thisurl)
{
global $referers;
for ($i=0;$i<count($referers);$i++)
{
if (preg_match("/$referers[$i]/i",$thisurl))
{
return true;
}
}
die("Error 4215 - Unauthorised script access!");
}
?>
Thanks again,
Peter
Message 3 of 5
(1,987 Views)
Re: Simple(?) PHP problem - Echo not working
27-03-2012 7:01 PM
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Report to Moderator
You have not said what the name of this file is? For the php code to be interpreted it must have a file extension of .php and not .htm or .html
Also document.write is javascript not HTML. You can't just write it out to the browser as it will not be understood.
what you will end up with is the following:
The browser will either ignore it or just show the exact text above.
All javascript that is not in-line (i.e. in an HTML tag) must be surrounded by <script type="javascript"> and </script> so the browser knows to interpret it as javascript. (ignore the end code text, this is a forum bug!
However I don't think that is actually what you are trying to do and it is completely meaningless in it's context to the broswer.
I suggest you start with something simple... just put the following into a file called test.php and put it in your document root folder (httpdocs in your case)
This should show a lot of info about php. If this does not work you have a fundamental problem somewhere.
Then change your code to not use document.write but just echo our the image tag text
You will also notice I have added the missing closing image tag (there is a single quote followed by semi-colon at the end of that line).
That will put an image tag into your page.
However, you have also missed a lot of HTML code to define the page
DOCTYPE.....
<html>
<head>
</head>
<body>
</body>
</html>
Your image tag needs to go within the <body></body> section.
I guess it comes down to not actually understanding what the pghp code is actually doing. The result of the php code is to produce the necessary HTML code, along with other HTML code not within the PHP code, to produce a file of HTML tags that the brpwser can interpret. Any mistakes in the generation HTML tags will often result in nothing shown to you.
So a lot to think about and try.
- Peter[/code]
Also document.write is javascript not HTML. You can't just write it out to the browser as it will not be understood.
what you will end up with is the following:
document.write('<img src="counter/style/1.gif" border=0>');\n";
document.write('<img src="counter/style/2.gif" border=0>');\n";
document.write('<img src="counter/style/3.gif" border=0>');\n";
document.write('<img src="counter/style/4.gif" border=0>');\n";
document.write('<img src="counter/style/5.gif" border=0>');\n";
...
The browser will either ignore it or just show the exact text above.
All javascript that is not in-line (i.e. in an HTML tag) must be surrounded by <script type="javascript"> and </script> so the browser knows to interpret it as javascript. (ignore the end code text, this is a forum bug!
<script type="javascript">
document.write("some text here");
</script>
[/code>]
[code]
However I don't think that is actually what you are trying to do and it is completely meaningless in it's context to the broswer.
I suggest you start with something simple... just put the following into a file called test.php and put it in your document root folder (httpdocs in your case)
<?php
// Show all information
phpinfo();
?>
This should show a lot of info about php. If this does not work you have a fundamental problem somewhere.
Then change your code to not use document.write but just echo our the image tag text
<script>
echo '<img src="$src" border=0></image>';
</script>
You will also notice I have added the missing closing image tag (there is a single quote followed by semi-colon at the end of that line).
That will put an image tag into your page.
However, you have also missed a lot of HTML code to define the page
DOCTYPE.....
<html>
<head>
</head>
<body>
</body>
</html>
Your image tag needs to go within the <body></body> section.
I guess it comes down to not actually understanding what the pghp code is actually doing. The result of the php code is to produce the necessary HTML code, along with other HTML code not within the PHP code, to produce a file of HTML tags that the brpwser can interpret. Any mistakes in the generation HTML tags will often result in nothing shown to you.
So a lot to think about and try.
- Peter[/code]
Message 4 of 5
(1,987 Views)
Re: Simple(?) PHP problem - Echo not working
30-03-2012 6:12 PM
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Report to Moderator
Peter,
Thanks for you response.
Having read through it a few times I think I now understand the problem I have encountered - basically having HTML in a php file works whereas having php lines in a HTML files does not. PHPINFO runs fine.
I have, however, found a Javascript method of achieving what I want. Rather than reading the content of the text file (which has the day and date of last update typed in it), I now use the date the file was last modified. This in effect gives me the information I want to show on my page.
Thank you once again - I really appreciate you taking the time to assist me.
Peter
Thanks for you response.
Having read through it a few times I think I now understand the problem I have encountered - basically having HTML in a php file works whereas having php lines in a HTML files does not. PHPINFO runs fine.
I have, however, found a Javascript method of achieving what I want. Rather than reading the content of the text file (which has the day and date of last update typed in it), I now use the date the file was last modified. This in effect gives me the information I want to show on my page.
Thank you once again - I really appreciate you taking the time to assist me.
Peter
Message 5 of 5
(1,987 Views)
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Plusnet Community
- :
- Forum
- :
- Help with my Plusnet services
- :
- Everything else
- :
- Simple(?) PHP problem - Echo not working