Viewing code and html page content - php

I'm looking for a way where you can write something normal text, ie content / problem for snakes code, for example in [div] [/ div] code could stand without problems where it does not appear or anything,
Therefore I search for a way to make that I can make normal html text but contemporaries do some code if you have problem
right moment, I use tiny mce to make some text, but when I should have known it since I do like this,
<?php echo strip_tags($tekst);?>
how come it appears on the page:
<?php echo \"Hello\";?>
what I want is just here on this page about writing some text and some code to the problem or the like, I'm thinking if I can fix it the same way or look like?

Related

best way for dividing dynamic(php) content from static content(html) for web design?

Until this day I have been using notepad++ for website developing. my codes are like:
...
<div><?php
$han=mysql_query("Blah blah ...");
$row=mysql_fetch_array($han);
// and so many codes to process text ..
echo $something;
?></div>
...
But maintenance of this kind of code is really hard. Now I see that everything is changing on webdesign. Everybody is going to make their websites responsive. I wish I could change my html code without seeing dynamic codes.
for example think I have have html file like this(static.html):
<div>#{content_here}</div>
and also a separate php file like this:
<?
$static_content=file_get_contents("static.html");
$han=mysql_query("Blah blah ...");
$row=mysql_fetch_array($han);
// and so many codes to process text ..
$content_here=$something;
echo str_replace("#{content_here}",$content_here,$static_content);
?>
This way I can separate static content from dynamic content. But this is all my innovation. And every time I invent something then I find that there is even a better and more extensive thing already invented.
So is there already IDEs that support this kind of web development? possibly get contents generated by php in json format and then blend it with Html content.

Execute the Code in a PHP Page And Echo the HTML Output

I absolutely don't post a question here in SO unless I really can't find a way to solve my problem myself. I did a lot of googling and was not able to find a solution for this one problem I am about to describe.
Here is the problem. I am creating a templated php website. With templated I mean something like below:
<?php include("header.php");?>
<div id="content">
<div id="main">
<h2><?php echo($page_title);?></h2>
<?php
echo ($page_content);
?>
</div>
<?php include("sidebar.php");?>
</div>
<?php include("footer.php");?>
As you can see here page template ECHOES the content of the $page_content variable between header and footer sections to build the page.
To keep the code clean and separated (in my own way) I have been placing the html content in .txt files (let's say page1_content.txt) and assigning the txt content to this variable ($page_content) as below:
$page_content = file_get_contents("page1_content.txt");
My problem starts when I place some php code in page1_content.txt, lets' call this file page2_content.php (yes, I change the file from .txt to .php). Then I assign the content of this file to $page_content variable as below as usual:
$page_content = file_get_contents("page2_content.php");
Now, when the page template ECHOES page2_content.php contents the php code in it is also echoed as string and not executed, but I am trying to query a database and do some stuff in this file with some php code. I mean, I want the php code inside page2_content.php to be executed and the cumulative html code to be echoed by the "echo" line inside the template file.
How can I achieve this?
Please ask me any questions if you need more info/clarification.
Thanks
EDİT:
As many people here suggested the solution was including the file. Actually, I tried including the file before but it didn't look like it was working, it broke my template, so I though I was on the wrong track and quit the "include" way of doing this. Since everybody here is advising to use include I tried that again. I replaced the php code in "page2_content.php" with a basic 1-line code just to see if it gets executed before adding generated html code without breaking the template and it worked. Apparently my php code had a problem at first place and hence broke my template execution.
Now I have changed the template structure slightly and pages using the template, and it seems to work nicely. Thanks a lot everybody. I have up-voted every answer suggesting that I use include :)
As #Ali suggested, you could include the files. The other option which I highly suggest you do not use is the eval() function.
I think what you want to do is to include your content PHP file, not echo it (as you are doing with header.php and footer.php).
echo($page_content);
Would become as below:
include("page2_content.php");
You've already done this in your footer and sidebar, just use include()

how to input a chunk of html with php

I am currently working on a website that uses a login system I made.
I have a div that holds a bar that goes on the top of the website. This bar is supposed to change depending if you're a guest, logged in, or a admin. (Therefor there are three separate divs - guestmode, membermode and adminmode)
I have tried to make php print the html when wanted, and it worked. The only problem is that it's messy and not at all easy to edit.
Is it possible for php to print html without using 'echo' or 'print', but copying from another file?
Basically I want to copy normal html syntaxed-code from a file somewhere and turn it into something that php can print, then of course print it.
Is there something out there that can do that?
Thanks in advance!
For PHP, use something like:
echo file_get_contents('path/to/my_html_snippet.my_ext'); // echo instantly
$stored = file_get_contents('path/to/my_html_snippet.my_ext'); // or save it for later in a string
Create a file at path/to/my_html_snippet.my_ext that contains the HTML you want to print.
Its seems like you need a templates.
See mustache (examples and docs - https://github.com/bobthecow/mustache.php)

Hidden spam/ad links in Joomla template

I just found some hidden links when i was looking in the source code for a site i am building i Joomla when i found som hidden spam links.
I have used an hour trying to find them within some of the template files without luck. the links are following (from html source code):
<div id="jxtc-zt"><a href="http://magical-place.ru/" target="_blank"
title="достопримечательности Европы">достопримечательности Европы</a></br><a
href="http://joomla-master.org/" target="_blank" title="шаблоны Joomla 3.5">шаблоны Joomla
3.5</a></div>
And this:
</div><div id="jxtc-zt"><a href="http://battlefield4.com.ua/" target="_blank"
title="Battlefield 4">Battlefield 4</a><br><a href="http://www.absolut.vn.ua/"
target="_blank" title="минеральные воды">минеральные воды</a></div></div></div>
Have you any suggestions how to find out where they are created?
It is probably obfuscated in some way?
Thanks
Had the same problem, but found the solution.
The code is indeed hidden within the template under template_name\html\com_content\article\default.php. The text is encoded using base64 and I had 2 instances in mine, 1 for before the article and one at the end. The code used is:
<?php if (!$params->get('show_intro')) :
echo $this->item->event->afterDisplayTitle;
endif; ?><?php
$mgp='PGRpdiBpZD0iamItYmYiPjxhIGhyZWY9Imh0dHA6Ly9tYWdpY2FsLXBsYWNlLnJ1LyIgdGFyZ2V0PSJfYmxhbmsiIHRpdGxlPSLQvtGC0LfRi9Cy0Ysg0YLRg9GA0LjRgdGC0L7QsiI+0L7RgtC30YvQstGLINGC0YPRgNC40YHRgtC+0LI8L2E+PGJyPjxhIGhyZWY9Imh0dHA6Ly9qb29tbGEtbWFzdGVyLm9yZy8iIHRhcmdldD0iX2JsYW5rIiB0aXRsZT0i0YDQsNGB0YjQuNGA0LXQvdC40Y8gSm9vbWxhIDMuNSI+0YDQsNGB0YjQuNGA0LXQvdC40Y8gSm9vbWxhIDMuNTwvYT48L2Rpdj4=';
echo base64_decode($mgp);?>
I simply removed the code from the 2nd
<?php ~ through to ?>
in both links.
If you can't find word "Battlefield" in any of site's documents, try searching for (without quotes) :
"QmF0dGxlZmllbGQ=" (Base64 representation),
"426174746c656669656c64" (Hexademical representation),
"Battlefield" (ASCII).
These would be most common ways to encode it.
If still no luck, then locate the code manually: delete small chunks of code in the main template file ( index.php most commonly ) and watch, if the unwanted link disappeared after delete. If it did - you have found the code, that is responsible for it.
For those who have similar problems, I'd like to suggest a thorough solution.
A binary searching tool, like "Text-Crawler" or "String Finder" (for windows) comes handy, and then search for the "most uncommon word from the whole unwanted text" in the root folder.
Next as "Jevgeni Boga~" pointed out in the above answer, try to search for the hashed form of those strings, which could be base64,hexadecimal,aasci.
Now if you are still not able to zero in on the exact code, there is quiet a possibility that the hidden code is being fetched from te database rather than a file, so your next place to search is your database, and its quiet easy to perform a string search through "phpmyadmin" .
All you need to do is go the "phpmyadmin home" then select "your database" then select "search"....
Words or values to search for :=> "most uncommon word from the injected code"
Find:=> Leave default (at least one of the words)
Inside tables :=> Choose Select All
Inside column:=> Leave blank..
Now if your "unwanted code" was hidden inside database, then you most probably shall get to it.
Now there is also a possibility as someone stated above, that the code as being injected by some script after the loading of the page, well you could be sure that this isn't the case, by disabling the javascript in your browser...
There are various other things to look out for... Like to check whether the code is in text format or is it just an image of the text... then if thats the case maybe then you have to look for that file like .jpg or .png... furthermore the image could also be parsed from the CSS using the "URLdata:image/png;base64" method...
or Lastly just search for the "iframe" tag, maybe that's iframed from some other source.

Wordpress disable code editor formatting for a page

So I have a wordpress page where I need to paste a block of html code, but when I output using the_content() you know that wp wraps things in <p> and so on, so I want for THAT PAGE to echo out the exact code that I paste in the editor without that auto formmating, is there a function or something, I've searched and found wpautopbut doesn't work.
You can switch from the WYSIWYG-View to the HTML-View by clicking the tab at top right corner of the editor window.
There you can inset your raw code surrounded by <pre> </pre> tags.
If you mean you want code that will execute, and not be seen, then you might try stampede design's solution.
There is also a raw HTML plugin that might help.

Categories