I am creating site with php.
On localhost all works well.
On my hosting all looks good too, but on top of page i see "?>". In my code these symbols are absent.
What is this?
It could be that your code uses short open tags (<? instead of <?php) and your hosting provider has short open tags turned off. That would mean, however, that your PHP code is not interpreted at all. It could also mean that your hosting provider doesn't support PHP at all, or only for certain file types.
Take a look into the page's source code to check whether that is the case.
The fact that you see that on top of the page could mean one or more things.
It seems you have typed in ?>
outside of a php block
You may be using short tags <?
instead of long <?php and the host
has short tags turned off
Out of these its most likely you have a closing ?> in your code without a corresponding open <?php tag
Are you sure yu're seeing ?> and not something like >>? ?
Otherwise, this smells like a PHP-EndTag which was never opened...check your code.
If you have a empty lines in your sourcefile before the opening <?php-tag, then those empty lines could get outputted unintenionally. If your script should start with <?php on top, remove all the empty lines above it.
Related
I have this situation trying to disable a sequence into a .php file (the black commented lines, back-to-top text button);
I've read about block commenting in notepad ++ and setting the language of the file but the comment it looks like is not implemented properly.
What I've done :
-File / Open the .php file,
(already it looks like it is viewed in php language judging by the colors)
-Selection between 355-359 lines and Block Comment (ctrl+shift+Q).After that, I've added the text but it doesn't look like the other existing comments.
Any thoughts? Thanks,
PHP comments only work when you are inside PHP mode (between <?php and ?>).
When you are outputting HTML, you need HTML comments which take the form <!-- comment which does not include two adjacent hyphens -->.
The PHP within an HTML comment will still execute and the results will be output to the browser. It looks like your PHP only outputs data and doesn't do any significant processing, so that will probably be sufficient. You might, especially in other cases, be better off simply deleting the code and then restoring it from your version control system's history later.
For that part of code you should comment using:
<!-- your comment -->
As you are using html (you closed the part of your php code by ?> )
I'm trying to create a block of PHP code within HTML such that when the user loads the page, it displays their IP address and time/date as the user in an email address.
I'm using apache on fedora21, and have enabled PHP (tested with phpinfo() function in the same HTML file).
Here is the code I'm trying to execute:
<? echo '<a href="mailto:'.$REMOTE_ADDR.'_'.date('y-m-j').'-#example.com" title="There is no spoon">For stupid spambots'; ?>
It just prints For stupid spambots'; ?> without printing the generated email address.
<? echo 'For stupid spambots'; ?>
Need to close <a href at first, and if you want to return IP its $_SERVER['REMOTE_ADDR'] not $REMOTE_ADDR except you define that variable before.
Judging from the fact that you can see closing ?>, I deduce that your PHP code doesn't run at all and is interpreted like regular HTML.
There might be several reasons why (badly configured Apache being one of them), but my prime suspect is that you have disabled short PHP tags. Try using <?php instead of <?.
You used the syntax of an html anchor wrong. Consider this:
<?php
$address = sprintf('%s_%s-#example.com', $_SERVER['REMOTE_ADDR'], date('y-m-j'));
echo sprintf('%3$s: %1$s',
$address,
'There is no spoon',
'For stupid spambots');
?>
You have to print the address into the visible text content of the anchor definition if you want it to be visible. You only but the "For stupid spambots" string in there which is what got displayed.
( Note that I just used the sprintf() calls to keep the lines short and readable. Obviously this also works with traditional string concatenation. )
I'm trying to get some PHP example code to work on PHP version 5.3.4, Apache 2.2.17 on Windows.
The example says I need PHP 4.0 and above with CURL and contains:
<?
$function = $_GET['function-if-exist'];
$test = "Test";
?>
<? =$test ?>
I don't understand why I'm getting the following errors:
My PHP doesn't understand <? and wants <?PHP instead.
My PHP doesn't like <? =$test ?> and wants something like
<?PHP echo $test ?>
$function = $_GET['function-if-exist']; causes the error "Undefined index" but presumably works for the folks that developed it.
Can anyone help me understand why their code is not working for me?
1) <? is the "short tag". Most servers are configured to not allow short tags. This can be changed in php.ini.
2) Again, short tags. Also I think you can't have a space before the =, but the main problem is the short tags setting.
3) $_GET accesses the query string, so when loading your script you need myscript.php?function-if-exist=something
It is more ideal to check if the parameter is set before continuing to prevent errors being thrown, e.g.
if(isset($_GET['function-if-exist']))
{
$functionexists = $_GET['function-if-exist'];
}
the short tag notation is disabled in your php.ini
you need to remove the space before your equal sign
your _get array contains not the expected index, what url do you enter to access the page?
I don't understand why I'm getting the following errors:
My PHP doesn't understand
To be able to use short tags you will have to enable them via config ... http://www.tomjepson.co.uk/tutorials/35/enabling-short-tags-in-php.html
My PHP doesn't like and wants something like
Once you switch on the short tags you will be able to echo using ... important the equals signs must be touching the ? not variable.
$function = $_GET['function-if-exist']; causes the error "Undefined index" but presumably works for the folks that developed it.
The $_GET is populated according to what is in the url. To get a value in $_GET['function-if-exist'] the url accessing the script should be something like mydemo.php?function-if-exist=hello
Hope this helps you
Quick answers to 1 and 2 are enable the short_open_tag option into the php.ini file, for the last one is set the error_reporting to a less strict mode.
The reasons of not to adopt such measures are:
the short tag clashes with the xml declaration and is disabled on different host, if you need to manipulate xml or if you need to write portable code is better to resort to the long tag syntax. You lose the ability to echoing data with = but it is a small annoyance to me.
Warning and notices, as php forgive a lot the programmer for missing variables declaration are a blessing for debug. Keep then raised and you will address a lot of mispellings.
Are you sure that function-if-exist is a correct index for your hash? I would check the index first the access them. If the index don't exists is a probable hint that something is going wrong with your code and you should check the reason of the missing.
Better to stop now, as anyone can write a book on this topic, and several ones already done ;)
hi i am working on a project of my college but my college server admin told me that we don’t use short_open_tag in our code what’s its mean? what is short open tag and what is alternate of it
thanks
Normally you write PHP like so: <?php PHP CODE HERE ?>. However if allow_short_tags directive is enabled you're able to use: <? PHP CODE HERE ?>. Also sort tags provides extra syntax: <?= $var ?> which is equal to <?php echo $var ?>.
Short tags might seem cool but they're not. They causes only more problems. Oh... and IIRC they'll be removed from PHP6.
You can try the tool at:
http://blog.eezgu.com/php-short-open-tag-sorunu-ve-cozumu.html
This is a PHP command line tool that converts short tags to normal PHP tags.
The page is not English but you can click the link in the post and download the tool.
While working on an existing Drupal site I've noticed a strange glitch that causes any PHP operator with > in it to act like a ?> tag. This is happening in in Drupal pages that I create that have a 'Input Format' of 'PHP code'.
For example this line of code
foreach($array as $key => $value){
results in a very broken page that prints out
$value){
Does any one know what could be causing this? My Dev environment is XAMPP. Drupal version is 6.15. PHP version is 5.2.9.
UPDATE: Short tags are OFF and when the PHP is rewritten so that it contains no > char it works as expected. I'll have to test more to get additional information.
Check if your php.ini has short tags enabled. If not, make sure you always begin every php block with <?php
If you look in the source, I bet you see the rest of the foreach in there. It's treating > as an HTML end delimiter (and it found a < earlier in the script). Ensure PHP is being parsed. If it isn't being parsed, see if it's because the script requires short tags. If the script uses long tags, make sure PHP itself is up and running properly in the web server.
are you sure there is <?php infront of the foreach()? some server need the <?php and not just <?