Why my localhosted files appear like this?
http://109.236.82.36/upload/
Everything is undefined, the defined variables aren't working.
Am I supposed to enable a plugin in xampp to get it to work?
PHP short tags must be disabled. If you check the source of your generated page, you'll notice that the img tags have src values like
<?=$website?>/images/hitpoints.gif
You have two options here. Either change the code to
<?php echo $website ?>/images/hitpoints.gif
or enable short tags in php.ini. You can get help on the second option using google.
I strongly suggest the first one as short tags are going to be chucked in future versions of PHP incompatible with XML documents and make code less portable.
Related
I've some strange issues with some php code.
if ($user->userType=='admin'){
If I use the above command, the php engine just stop interpreting and display the code in plain text on my browser. On the other hand if I use the below method it works:
if ($user['userType']=='admin'){
Again here also:
$_SESSION['currentUser']->id
If I use the above code it just displays the rest of code as plain text:
id); // fail user }else{ $authentication="failed"; $noAuthPresentation="loginForm"; }
Why this is happening? It's a big project and I don't want to change every line where there is an occurrence of ->.
Do I need to change some setting somewhere? I'm using WAMP server with php 5.5.12.
Any help ? Thanks!
You're mixing up types, user is an array, and not an object. Something in your php config is doing something strange to your error display it seems. Right click on the page that has the errors, and view source if possible.
Does login.php contain html and php code by chance?
Long ago, this code used to work but now it seems something is going on preventing it from functioning properly. I'm hoping somebody can tell me whats going on. I'm concerned upgrades to PHP have killed this code. Or has it?
I use this code (posted below) to check and to see if an html file exists, and if it does it'll use it. If not, it will use the file index2.html.
<?php if ((file_exists("$id.html")) == true) { require ("$id.html"); } else { require ("index2.html"); } ?>
I use this code on my homepage, index.php. However for some odd reason, when I type in a link: example: index.php?id=exampleurlhere, the code isn't checking to see if the file exists and is automatically using the index2.html file, despite my code telling that if the file exists (which it does), then it's required to use it. Why is it now ignoring my command?
Been using this code for years and never had any problems with it until recently it seems. Any suggestions to fix it?
I think the problem lies in the "register_globals" setting. This used to be on by default in the (very) older versions of PHP, but has been removed in the newer versions, as this caused a lot of variable injection attacks in the old PHP.
Your $id came directly from the value in the URL. Now that it no longer auto registers, you can add in a line "$id=$_GET['id'];" just above that line to get it to work again.
This is just a quick fix. I suggest you rewrite the program so that there will not be any change of users accessing files illegally using the URL.
I create a PHP page with the following content:
<?php session_start(); ?>
<?php require_once(./classes/MaterialUtil.class.php);
$mUtil = new MaterialUtil();
?>
I put the MaterialUtil.class.php file in D:\xampp\htdocs\drupal\sites\all\themes\zeropoint\classes, but I get the following error message:
Parse error: syntax error, unexpected '.' in D:\xampp\htdocs\drupal\modules\php\php.module(80) : eval()'d code on line 7
Could you please tell me what I do wrong?
The error is caused from the fact you didn't use a string for the filename, and PHP understood the dot as being the concatenation operator; as such, because there wasn't any value before the operator, PHP gave you an error saying it found the concatenation operator in the wrong place.
As kalabro said, the correct code is the following one:
<?php session_start(); ?>
<?php require_once('./classes/MaterialUtil.class.php');
$mUtil = new MaterialUtil();
?>
This is the part of the answer that is not strictly related to Drupal.
What you are doing is not what I would suggest to do, for two reasons:
You are putting the "classes" directory in the wrong place. Those files are not related to the theme being enabled, but they are related to the page being viewed. Even if you have a single theme, and users are not allowed to select a theme for themselves, it still wrong to put those files in a theme directory.
Putting the files in the directory containing a theme, which will needs to be updated when a new version is available, could cause you to lose the additional files you added, if you are not careful.
Executing PHP through eval() to, e.g., get content to show in a node is not something that you should do. This is because:
As you have used the PHP filter for the node, the node becomes only editable to a restricted group of users. (I would not suggest to allow untrusted users to use PHP as input format)
When you have PHP code that you need to execute, it is always better to create a custom module that is enabled for the site.
If you were trying to include a PHP file from inside a module, then you should use module_load_include(), instead of require_once(), as already suggested by marcvangend.
XAMP server does not run on windows file system format. You must write your file location like localhost/xyz/abc ..
I am new to php and would like to know if there are any differences between these server tags :
<?php
?>
and
<?
?>
The first is a safe open and close tag variation, the second is the so called short-open tag. The second one is not always available, use the first option if it's possible.
You could check the availability of short open tags in php.ini, at the short_open_tag.
The problem with short open tags is that the following:
<?xml version="1.0" ?>
will cause problems if you're allowed to use short tags (i.e. <? and ?>). <?php is less open to misinterpretation.
Whether or not you're allowed to use short tags is defined by the ini directive short_open_tag.
Also I think shorttags are being removed in one of the upcomming releases.
Edit: I was wrong.
Farewell <% They will remove support
for the ASP style tags, but the PHP
short-code tag will remain - so
to those on php general who reckon the
short-tag is 'depreceated' - hah! ;)
http://phpmysqldev.blogspot.com/2007/05/php-6.html
Nothing AFAIK, however I have had servers (shared) where the settings do not support shorthand tags <? ?>, so I usually stick with the <?php ?> for good measure.
There is no difference.
The ability to use <? ?> is defined in your php.ini file - usually accessed only by the server host.
You can find more information here
Note short_open_tag = Off did not effect the <?= shorthand tag, which is equivalent to <?php echo
As #erenon explained here: https://stackoverflow.com/a/1808372/1961535
The difference is that short_open_tag in some cases isnt available. You can check the status by accessing the php.ini file but in case of shared hosting server, the host does not always allow edits to php.ini file.
You can easily print the phpinfo as explained here:
https://www.php.net/manual/en/function.phpinfo.php
phpinfo();
search for short_open_tag as shown below
It is always better to use full tag because that will always be supported in every version of PHP weather old file or new.
I've been using Textmate for Ruby/Python scripting for awhile and now have a need to hack on some PHP. I'm having some troubles with the bundle:
The code-highlighting doesn't support HTML...
When I type php + tab TM spits out:
?><?php>
instead of:
<?php ?>
Anyone know where I could possibly be going wrong? Thanks in advance...
Change your file type to HTML (even if you are editing a .php file!) would solve the problem.
The reason for this is documented at http://wiki.macromates.com/Troubleshooting/PHPSyntaxHighlight
No, the best way is to set language to "HTML" in the bottom status bar.
you can still have the file name ended with php