Wordpress not showing up when using PHP via plugin? - php

I have installed a plugin (use PHP in posts) for Wordpress, and am having some issues.
Here is my code (though I don't think its the issue)
$usertoget = $_GET['player'];
$partone = "http://website.co.uk/path/to/php/file.php";
if(strlen($usertoget) != 0) {
$parttwo = "&player=";
$partthree = $usertoget;
$finalurl = $partone . $parttwo . $partthree;
print '<iframe src="$finalurl"></iframe>';
}
else {
print "<iframe src='/path/file.php'>";
}
The iframe gets printed perfectly and does what the target file should, but as you can see from this picture, messes up the formatting:
No sidebar;
No footer;
No floating header.
I have noticed that the page source finishes the iframe and does nothing else except close (</body></html>). There is a lot of stuff after it that should appear but doesn't.
Another issue is, using GET requests (/page/hello?player=9 and /page/hello/?player=9) returns a 404. Any ways to resolve this issue?
Does anybody know how I can fix this? I can post any more code if required :)
Any help would be appreciated :D Thanks!

If PHP suddenly stops sending the expected output, it usually means there's a PHP error. Is there anything in your logs? Have you tried turning WP_DEBUG on?
I'm surprised you say the iframe gets printed perfectly. This line
print '<iframe src="$finalurl"></iframe>';
looks wrong to me (though it won't cause PHP to error). If you have single quotes around a string, variables won't be evaluated. See this question for a little more detail.

You have mistake in concatenation of $finalurl .you can check you html its print the $finalurl variable as it is.Its didn't outputted its values .I had check it.So you just have to concatenate the $finalurl variable correctly .Here is your code which i had made corrected.
$usertoget = $_GET['player'];
$partone = "http://website.co.uk/path/to/php/file.php";
if(strlen($usertoget) != 0) {
$parttwo = "&player=";
$partthree = $usertoget;
$finalurl = $partone . $parttwo . $partthree;
print '<iframe src='.$finalurl.'></iframe>';
}
else {
print "<iframe src='/path/file.php'>";
}
if you have any query please comment bellow.

Related

Paginated PHP web scraper

Hi there I'm new here.
Trying to make this little code to loop over pages. And scrape off links of headings .
Scraping part works just fine but i cant make it to loop to the next page. It keeps looping on the same page.
<?php
include('../simple_html_dom.php');
// start at page 1
$xder = 1;
do {
// web page + page number (should change with every loop)
$html = file_get_html('https://webpage.com/stuff/page/$xder');
foreach($html->find('h3') as $h3)
{
foreach($h3->find('a') as $element)
{
echo $element->href . '<br>';
}
}
$xder++;
} while ($xder <= 5);
?>
I'm expecting to get list of links from all 5 pages, but I only get list of links from 1st page repeating 5 times.
I think the problem is here "/stuff/page/$xder');" I'm not sure how to add a variable to the back of an URL it doesn't appear to work.
Tried methods here:
Converting an integer to a string in PHP
Getting frustrated with this. Not sure what I'm missing here. Thanks for any thoughts :)
Php variables are treated as variables only if you use ", and not '
Change
$html = file_get_html('https://webpage.com/stuff/page/$xder');
to
$html = file_get_html("https://webpage.com/stuff/page/{$xder}");

Why are <br> tags duplicated when using the 'for' php function?

This code is supposed to help me in limiting the amount of characters seen in the timeline page. If the post is too long, (more than 400 characters), it should display a 'see more...' which should take the reader to a new page (posts.php?post=XXX). When I use this function, the second part after 'else' works fine. However, the first part seems to duplicate all the tags, and the spaces in this page appear twice bigger than the ones in posts.php. I can't trace the problem, someone please help me.
function display_content($long_text, $link, $page='posts', $page_ext = 'post'){
if(strlen($long_text) >= 400){
for($i=0; $i<=400; $i++){
echo nl2br($long_text[$i]);
}
echo "...<br /><a href='{$page}.php?{$page_ext}={$link}'>Read more...</a>";
} else echo nl2br($long_text);
}// I have taken care of all security issues.
Instead of parsing all characters of your text :
for($i=0; $i<=400; $i++){
echo nl2br($long_text[$i]);
}
Why don't you use :
echo nl2br(substr($long_text, 0, 400));
?

this PHP code functions in XAMPP but AZURE shows code in browser

<?php
require_once('functions.php');
//display links from xml
$links = simple_load_file('links.xml');
foreach($links as $link){
$name = $link['name'];
$ref = $link->loc;
echo "<a href='".$ref."' class='navigation'>".$name."</a>";
}
//Display login boxes if user hasnt logged in
if((!isset($_SESSION['validUser'])) || ($_SESSION['validUser'] != true))
{
?>
//code for showing boxes.....
In the browser, it displays the folowing ;
loc; echo " ".$name." ";} //Display loginboxes.........all the way to != true)) { ?>
When I test this on XAMPP locally it works as intended, but using Azure it produces this.
It appears as if it's reading the '->' as a closing tag for my php. Anyne encounter something like this?
I never did get to find the exact problem, as the project was abandoned. however, as suggested it is most likely a configuration issue from within Windows Azure.

php with preg_match_all() generates no results

I'm trying to use this php script in order to locate a stock quote from yahoo finance. The problem I'm having is that when the script is run it generates no results. This leads me to believe that my regular expression is incorrect, but when I use the same regex on myregextester.com it shows the results that I expect with the given input. Any help will be greatly appreciated. Also, my php may be incorrect for what I'm trying to do.
<html>
<head>
<title>Stock Quote from Nasdaq</title>
</head>
<body>
<?php
// choose stock to look at
$symbol = 'AMZN';
echo "<h1> Stock Quote for $symbol </h1>";
//echo 'this printed (1)<br />';
$theurl = 'http://finance.yahoo.com/q?s=AMZN';
//echo 'this printed (2)<br />';
$contents = file_get_contents($theurl);
//find the part of the page we want and output it
if (preg_match_all('/amzn">([0-9]+\.[0-9]+)/', $contents, $matches)) {
echo "The price for $symbol: ".$matches[1][0];
} else {
echo "No Results";
}
?>
</body>
</html>
What you are searching for is:
<span id="yfs_l10_amzn">221.37</span>
Your regex would succeed for that.
So your actual problem is retrieving the page. Besides the obnoxious $theurl variable name, you should just use file_get_contents instead of fread etc.
$contents = file_get_contents($theurl);
Worked in your snippet.
I just downloaded the url http://finance.yahoo.com/q?s=AMZN and looked at the page source. Done a seach for /amzn. One match. That was <a href="/marketpulse/AMZN">Market Pul.... Hence no match.
Need to have a rethink.
Escape the >
try this:
preg_match_all('/amzn"\>[0-9]+\.[0-9]+/',$contents, $matches);

PHP Check if page contains

I'm looking for a quick code/function that will detect if a page contains a certain thing.
It's for a new project I'm working on.
Basically, the user will paste a simple javascript code into their pages, but I need to make sure they do.
I need a code that will scan through a specific webpage url and find the code I provided.
Thanks!
You want to scan through a webpage, not an URL! You get to the webpage through an URL. :)
<?php
$contents = file_get_contents("http://some.site/page.html");
$search = <<<EOF
<script type="text/javascript">
alert('They must have this!');
</script>
EOF;
if (strpos($contents, $search) === FALSE) {
echo "Naughty webpage!";
}
?>
Note, though, that programmatically skimming pages like this is generally considered bad form.
You can get the contents of a URL as a string, and search the contents for that code:
<?php
function check_url($url) {
$page = file_get_contents($url);
$code = '<script src="http://example.com/test.js"></script>';
if (strpos($page, $code) === FALSE) {
return false;
} else {
return true;
}
}
?>
You may want to swap that simple strpos out for a regular expression, but this will do the trick.
You need to do the 2 things:
1) get the content of remote url
2) check if the content contains your string:
if ( stristr($content, 'your_desired_string') )
{
echo ' Yes, found';
}
there are great libraries for crawling websites like cURL but in your case it seems to be an overkill to use it. If you want to use the cURL library I recommend the Snoopy-class to you which is very simple to use.
Felix

Categories