Php Script displaying source on browser instead of executing it

Started on the old forum in June 2013 · view the original in the archive · old links redirect here

19 replies · 1,153 views · started 13 years ago · 1 min read

10 participants
wapdxoo Junior · 11 posts #1

i was just testing a script i made, but it didn't display design or any html..

Instead, it showed all my codes in highlighted format. Meanwhile, some scripts work perfectly alright, but few still gives me problem..

Any help?

something else Fellow · 2,296 posts #2

without seeing the script and also not knowing exactly what the problem is - there is no way of helping apart from guessing

chelios Junior · 13 posts #3

Browser show source code if your php is not properly formated BAD WAY TO FORMAT PHP,SOME SERVERS DO NOT RECOGNIZE FORMATING AND OUTPUTS SOURCE CODE

<? 
print "Bad formating";
?> 

Corect way to do it

<?php
print "Corect formating";
?>
phoenix90 Developer · 113 posts #4

chelios wrote: Browser show source code if your php is not properly formated BAD WAY TO FORMAT PHP,SOME SERVERS DO NOT RECOGNIZE FORMATING AND OUTPUTS SOURCE CODE

<? 
print "Bad formating";
?> 

Corect way to do it

<?php
print "Corect formating";
?>

This is most probably your problem, you have to setup a server to accept shorthand code, if not it will be commented/printed to screen. General rule of thumb is to always start php code with <?php and NOT <?

phoenix90 Developer · 113 posts #6

Please copy your whole source here so that we can inspect

Viewing the sourcecode from browser I see there is a tag after body "<code>", not sure why that was done but remove it, if that doesn't solve your issue please upload the php so that we can properly check

charith7788 Developer · 51 posts #7

wapdxoo wrote: i was just testing a script i made, but it didn't display design or any html..

Instead, it showed all my codes in highlighted format. Meanwhile, some scripts work perfectly alright, but few still gives me problem..

Any help?

show us ur script or check your script again

chelios Junior · 13 posts #8

wapdxoo wrote: Thanks your your replies.. But, i've done evrytin needed to be done.. Pls see http://nxsite.t15.org/forum

Check this php files for errors ..

require("../inc/engine.php");

Reason why to check engine.php is that if there is no errrors , but error is in

  // Main 
main();

anything should be in order until main() function is called

metulj Super moderator Principal · 1,726 posts #10

chelios wrote: Browser show source code if your php is not properly formated BAD WAY TO FORMAT PHP,SOME SERVERS DO NOT RECOGNIZE FORMATING AND OUTPUTS SOURCE CODE

<? 
print "Bad formating";
?> 

Corect way to do it

<?php
print "Corect formating";
?>

phoenix90 wrote: This is most probably your problem, you have to setup a server to accept shorthand code, if not it will be commented/printed to screen. General rule of thumb is to always start php code with <?php and NOT <?

I wonder how you two PRO's manage to run your sites... FYI, both ''formating'' are perfectly correct ! It is just a matter of server setting php.ini => short_open_tag = on ! then there is absolutely NO difference between <? and <?php

wapdxoo wrote: Thanks your your replies.. But, i've done evrytin needed to be done.. Pls see http://nxsite.t15.org/forum

your way to solution is in arnage's reply... most likely you are looking for code like this(or similar):

<?php 
function string_syntax_xhtml( $string, $return = false ) {
	$highlight = highlight_string( $string, true );
	$replace   = str_replace(
		array( '<font color="', '</font>' ),
		array( '<span style="color: ', '</span>' ),
		$highlight 
	);
	if( $return ) {
		return $replace;
	}
	echo $replace;
	return true;
}
function file_syntax_xhtml( $path, $return = false ) {
	return string_syntax_xhtml( file_get_contents( $path ), $return );
}
echo '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"><html><head><title></title></head><body>';
string_syntax_xhtml( file_get_contents( 'index.php' ) );
echo '</body></html>';
?>

It's better to keep your mouth shut and give the impression that you're stupid, than to open it and remove all doubt. ⓣⓗⓔ ⓠⓤⓘⓔⓣⓔⓡ ⓨⓞⓤ ⓑⓔ©ⓞⓜⓔ, ⓣⓗⓔ ⓜⓞⓡⓔ ⓨⓞⓤ ⓐⓡⓔ ⓐⓑⓛⓔ ⓣⓞ ⓗⓔⓐⓡ ! ιη тнєσяу, тнє ρяα¢тι¢є ιѕ α яєѕυℓт σƒ тнє тнєσяу, вυт ιη ρяα¢тι¢є ιѕ тнє σρρσѕιтє.

キノgんイノ刀g 4 ア乇ムc乇 ノ丂 レノズ乇 キucズノ刀g 4 √ノ尺gノ刀ノイリ!

phoenix90 Developer · 113 posts #11

metulj.

No difference? Your kidding right? So if one needs additional setup to work correctly (which I did mention in my post if you read it) the how are they not different? Seriously

Oh and btw. < ? Is used for xml and thats why short_open_tag is disabled by default.

So please PRO tel us 2 noobs how they are still exactly the same.

GumSlone Administrator Principal · 1,690 posts #12

dont know which system you have used, but for me short open tags were always enabled by default, if you put xml in php file you can do it like this

<? echo '<?xml version="1.0" ?>'; ?>

Advertise your mobile site for FREE with AdTwirl

External image (may be gone)

phoenix90 Developer · 113 posts #13

GumSlone wrote: dont know which system you have used, but for me short open tags were always enabled by default, if you put xml in php file you can do it like this

<? echo '<?xml version="1.0" ?>'; ?>

I honestly have always have that disabled from our local servers to hostgator.

But apparently those shortags will be deprecated in the next major release of php, but instead they suggest <?= ?> for the people that prefer shortags, as per the PSR-1 coding standards

metulj Super moderator Principal · 1,726 posts #14

phoenix90 wrote: metulj. No difference? Your kidding right? So if one needs additional setup to work correctly (which I did mention in my post if you read it) the how are they not different? Seriously Oh and btw. < ? Is used for xml and thats why short_open_tag is disabled by default. So please PRO tel us 2 noobs how they are still exactly the same.

like i said...

<? ...

is equal to

<?php ...

and also

<?= ...

is equal to

<? echo ...

The problem with this whole discussion lies in the use of PHP as a templating language. No one is arguing that tags should be used in application source files.

However PHP's embeddable syntax allows it to be used as a powerful template language, and templates should be as simple and readable as possible. Many have found it easier to use a much slower, add-on templating engine like Smarty, but for those purists among us who demand fast rendering and a pure code base, PHP is the only way to write templates.

The ONLY valid argument AGAINST the use of short tags is that they aren't supported on all servers. Comments about conflicts with XML documents are ludicrous, because you probably shouldn't be mixing PHP and XML anyway; and if you are, you should be using PHP to output strings of text. Security should never be an issue, because if you're putting sensitive information like database access credentials inside of template files, well then, you've got bigger issues!

Now then, as to the issue of server support, admittedly one has to be aware of their target platform. If shared hosting is a likely target, then short tags should be avoided. But for many professional developers (such as myself), the client acknowledges (and indeed, depends on the fact) that we will be dictating the server requirements. Often I'm responsible for setting up the server myself.

And we NEVER work with a hosting provider that does not give us absolute control of the server configuration -- in such a case we could count on running to much more trouble than just losing short tag support. It just doesn't happen.

So yes -- I agree that the use of short tags should be carefully weighed. But I also firmly believe that it should ALWAYS be an option, and that a developer who is aware of his environment should feel free to use them.

source: coding style - Are PHP short tags acceptable to use? - Stack Overflow Im noob, but obviously i could teach PROs like you, things or two...

It's better to keep your mouth shut and give the impression that you're stupid, than to open it and remove all doubt. ⓣⓗⓔ ⓠⓤⓘⓔⓣⓔⓡ ⓨⓞⓤ ⓑⓔ©ⓞⓜⓔ, ⓣⓗⓔ ⓜⓞⓡⓔ ⓨⓞⓤ ⓐⓡⓔ ⓐⓑⓛⓔ ⓣⓞ ⓗⓔⓐⓡ ! ιη тнєσяу, тнє ρяα¢тι¢є ιѕ α яєѕυℓт σƒ тнє тнєσяу, вυт ιη ρяα¢тι¢є ιѕ тнє σρρσѕιтє.

キノgんイノ刀g 4 ア乇ムc乇 ノ丂 レノズ乇 キucズノ刀g 4 √ノ尺gノ刀ノイリ!

phoenix90 Developer · 113 posts #15

metulj

You know what I give up!! I came here to teach beginners proper ways of going forward and to be future ready, NOT just to do it now and worry later on when it gets deprecated kind of attitude (not that I am saying you have that type of attitude), I am not here to argue with you or anyone else, information I posted here was straight from the developers of PHP.

After all, I started here 6 years ago as a complete "noob" as they call it, I went on to learn and study loads of different coding languages, so just trying to give back to the community..

But to each their own.. 🤝

Anyways, lets get back on topic..

wapdxoo

have you managed to fix your problem?

metulj Super moderator Principal · 1,726 posts #16

phoenix90 wrote: metulj You know what I give up!! I came here to teach beginners proper ways of going forward and to be future ready, NOT just to do it now and worry later on when it gets deprecated kind of attitude (not that I am saying you have that type of attitude), I am not here to argue with you or anyone else, information I posted here was straight from the developers of PHP. After all, I started here 6 years ago as a complete "noob" as they call it, I went on to learn and study loads of different coding languages, so just trying to give back to the community.. But to each their own.. 🤝 Anyways, lets get back on topic..

wapdxoo have you managed to fix your problem?

I'm not arguing, and I'm not saying which PHP tag is better, but the simple fact is that

<? ...

is exact same as

<?php ...

if you dont understand that, then that is your problem and your lack of knowledge.

It's better to keep your mouth shut and give the impression that you're stupid, than to open it and remove all doubt. ⓣⓗⓔ ⓠⓤⓘⓔⓣⓔⓡ ⓨⓞⓤ ⓑⓔ©ⓞⓜⓔ, ⓣⓗⓔ ⓜⓞⓡⓔ ⓨⓞⓤ ⓐⓡⓔ ⓐⓑⓛⓔ ⓣⓞ ⓗⓔⓐⓡ ! ιη тнєσяу, тнє ρяα¢тι¢є ιѕ α яєѕυℓт σƒ тнє тнєσяу, вυт ιη ρяα¢тι¢є ιѕ тнє σρρσѕιтє.

キノgんイノ刀g 4 ア乇ムc乇 ノ丂 レノズ乇 キucズノ刀g 4 √ノ尺gノ刀ノイリ!

wapdxoo Junior · 11 posts #18

Thanks for all your comments on this.. I've been out for a while, i'll upload the script on a paid host this time.. Get back to y'all soon. Thanks

subzero Super moderator Fellow · 3,954 posts #19

chmond problem.

And file format reading when saving a file.

Save the file as TEXT not assr

Visit: Chat4u.mobi - The New Lay Of being a site of your dreams! Visit: WapMasterz Coming Back Soon!


SCRIPTS FOR SALE BY SUBZERO Chat4u Script : coding-talk.com/f28/chat4u-mobi-script-only-150-a-17677/ - > Best Script for your site no other can be hacked by sql or uploaders. FileShare Script : coding-talk.com/f28/file-wap-share-6596/ -> Uploader you will never regret buying yeah it mite be old now but it still seems to own others... _______…

wapdxoo Junior · 11 posts #20

iThink the problem came from the previous host. Its now perfect!. Thanks y'all.

Sign in to reply.

Similar topics

Keyboard shortcuts

g f
Go to forums
g h
Go to your feed
g m
Go to messages
r
Reply (in a topic)
/
Search
j
Next post
k
Previous post
?
This list
Ctrl/⌘ + Enter
Send what you are writing
Ctrl/⌘ + B / I
Bold / italic while writing
Esc
Close