I have a chunk of PHP given to me to put into a web page... the code looks like this:
<?php
$SVQuerystring = "";
foreach (($_GET) as $SVGetKey => $SVGetValue) {
....
?>
Problem is, everything after the '>' in the 3rd line gets printed as html text, so the php is being exited there. I can't find a similar issue anywhere, and I have never worked with PHP before. Any suggestions on what is wrong, or where to look? Any help would be greatly appreciated :)
I would seriously question whether the PHP is getting executed in the first place.
Try this code to make sure it is executing without any of your code.
<?php
phpinfo();
?>
If you see a bunch of output pertaining to PHP and your server then there is some other problem. If you don't see any new output, then PHP is not correctly installed on your server.
Related
I am pretty new to PHP. I am going through a website and am trying to find a source of some of the content and have come across what looks like where the source is, but I cannot decipher the code. Can someone help me understand what this means?
<?php
if (is_file($office_file))
include($office_file);
echo do_shortcode(ob_get_clean());
?>
Thanks!
I have copied your code and added comments that (hopefully) explain what is going on.
<?php
if (is_file($office_file)) // check if $office_file is a valid file
include($office_file); // the check passes, so now include the contents of that file inline
echo do_shortcode(ob_get_clean()); // not enough context to know really what this does, but it looks like its printing the result of parsing 'shortcode' from an output buffer
?>
Really puzzled on this, probably simple but it is the day after New Years.
I have one line of php 'inline' code that fails to execute on the server before the server sends the page to the browser.
Here's the code:
<div>
Server says this: <?php "DOOSH"; ?>
</div>
That's all I have in the body of my html test page. I'm expecting the inline php to put 'DOOSH' there into the html then send the html over the client. Not happening.
All I see in the browser is "Server says this:" and nothing else.
The reason this has me confused is -- I KNOW the php executes on the server BEFORE the html above is sent over, so why is the DOOSH not being sent? I have tried 'DOOSH', "DOOSH", I even tried writing a php function in the file to return "DOOSH" and nothing works -- do I have a syntax problem here?
(NOTE: Doesn't have much to do with my problem here, but I can successfully click on the "Server says this =>" link and I see thePhpFile.php successfully load, as expected.)
You need to echo it.
<?php echo "DOOSH"; ?>
Or the shorthand way,
<?="DOOSH";?>
I think the syntax you may be looking for is
<?="DOOSH";?>
Right now, you just have a statement which contains the string "DOOSH" but doesn't do anything with it. You either have to use the syntax above or echo it.
<? echo "DOOSH"; ?>
Or maybe I"m totally misunderstanding...
<?php echo "DOOSH"; ?>
Or
<?= "DOOSH"; ?>
I apologize if this has been answered, but I haven't been able to find anything about it. I've been having trouble with a certain block of PHP code on my server and have finally realized that it doesn't like single line comments. With this code, the method get_all_articles is never called.
<?php
$article_class = new Articles();
// Fetch all articles
$articles = $article_class->get_all_articles();
?>
However, removing the comment or converting it to a block comment allows the page to render perfectly. I realize that I've already figured out what's causing the problem, but what I'm looking for is why or how I might be able to fix it. Any help would be greatly appreciated. Thanks!
Maybe the formatting is getting lost on upload to where line breaks are being deleted? Try downloading the PHP file after you've uploaded it and see if the line breaks are still intact.
This can be frustrating... One time I had an if statement that would ALWAYS execute, no matter what the values were...
Started out as this, where $x was equal to 5 (I verified this with debugging)
if($x > 10);
{
....
}
Eventually, I had it down to this:
if(false);
{
echo("This should never happen");
echo("but it does!!!!!!!");
}
After much loss of hair, I realized that I had a semi-colon at the end of the if() line, therefore translating into:
if(false)
/*do nothing*/;
{
//Nice block that always executes
}
The moral of this story is that while the problem you percieve is actually giving you a problem, it is not a PHP problem. Try to find out the root cause by first verifying that the actual code that is executing is EXACTLY what you typed. Re-download the file, publish with different protocol, publish as binary, check sha1sum() on files to make sure the same... Look and look and you will find it.
Let us know.
i have place javascript inside php code, like this
<?php if(condition) { ?><script>do some scripting here</script><?php } ?>
it works perfect when i run it in local.
but when i upload it to the server it doesnt run..
the javascript doesnt work.
Can anyone please help.
thanks,
Devan
First, I'm pretty sure you have to do either:
<?php if (condition) { ?> ** script stuff ** <?php } ?>
or
<?php if (condition) : ?> ** script stuff ** <?php endif; ?>
(Your script has no scope on the if statement, although that could be a copy/paste error).
Second, it could be your script (perhaps one of the Javascript files such as jQuery isn't on your server).
Your problem is pretty vague...
Here's all the things I would review first :
are you sure php runs on your distant server ?
do you have anything on screen when running your script ?
when you view the source code from the generated page : do you see your javascript code ?
did you check for javascript error messages ?
Another batch of questions after the comments :)
Did you try to change your JS code with a "basic" one, such as "alert('my code works');" ? (in order to see if your javascript code is triggered)
If the basic alert code does not produce a popup, then you should see your browser's setup with javascript. It may not be enabled
if it works (and you don't have any JS error messages) : try to place some more "alert" popups along your own code, in order to find where your code stops to work)
This will not provide you a direct answer to your problem, but will help you to find more details on your problem, and will help us find an answer
I've to make a website works and I don't know what to do right now. I can run it in a virtual machine with Ubuntu, on my company's server in Debian, on a WAMP... but I can't get it working in a server from a client.
I think the problem is with the gets. The form that I can't modify is sended by get, using the next url:
http://domain.com/SGAP/dades_proj_edit.php?idedit=2011854&id=&projectname=afsdfasdf&comptitle=asasfdafsdafs&codarea=ECIV&grauimp=1&codtipus=2&codsubtipus=6&subtipusdef=fdsaafasfddfs&codpais=8&clientid=2&promotor=asdfa&entfin=fsdafadsfds&impcontract=2&initdate=21%2F01%2F2011&findate=30%2F01%2F2011&uteflag=false&utepartic=&utepercent=0&descprelim=fdsadasdadfsadfs&codprojstatus=1&statusstamp=25%2F01%2F2011&cruserid=&action=update
Firefox shows a blanc page with no error. I've tried to force to show all errors with error_reporting(E_ALL) and ini_set("error_reporting", E_ALL) to show if something happens but the wait page is showed with 0 errors.
I supposed that was a $_GET error and I tried to put on the top of the page and in the end of it a <?php if($_GET["test"]) echo "Works"; ?> and call the webpage with: domain.com/SGAP/dades_proj.edit.php?test=testing and it works from top to end... I don't know where is the error.
What I can check to figure where is the white page comming? Thank you in advance!
Here's what I would do.
Start at the top of the file/stack, and add this code:
<?
$myUniqueCounter = 0;
error_log(++$myUniqueCounter . ', line ' . __LINE__ );
Then, copy and paste the error_log line all over the file/stack, and see where it stops logging.
I have occasionally seen php die without a blank output. Generally, the only way to solve this is to remove everything from the file, and then add code back in one line at a time. When it stops working, you know that whatever you just added caused the fault. You can try running php with the -l flag, to check the syntax, but this might not find the problem; the only sure way really is to just to add or remove things until the output changes.
I know this isn't much help, but there is no other way to debug the problem, short of executing php itself with a debugger... actually, you could do that; can you run php from gdb? That might help you find what is causing the issue, but no guarantees.