I have a script that gets and displays part of an external website.
https://pentiger.com/wycieczki.php
<?php
$config['base_url'] = 'www.ampolinc.com/';
$curl = curl_init('http://www.ampolinc.com/wycieczki.php');
curl_setopt($curl, CURLOPT_RETURNTRANSFER, TRUE);
$page = curl_exec($curl);
if(curl_errno($curl)) // check for execution errors
{
echo 'Scraper error: ' . curl_error($curl);
exit;
}
curl_close($curl);
$regex = '/<td width=\"694\" bgcolor=\"#FFFFFF\">(.*?)<table width=\"709\"
cellpadding=\"0\" cellspacing=\"0\" border=\"0\" style=\"margin:5px 0px 0px 167px;\">.<tr><td>/s';
if ( preg_match($regex, $page, $list) )
{
$list= str_replace('plan','print',$list);
<base href="http://ampolinc.com/">
echo "<font size = \"9\">";
echo $list[0]; //prints it to your page
echo "</font>";
}
else
print "Not found";
?>
but the images in Chrome do not display, when I click copy image url it copies fine.
I tried in Safari and images display. Any idea why? thanks.
How it looks in Chrome
How it looks on Safari
Related
I'm trying to make a locally hosted website for any experiments I want to do, but I also got the idea to add all the random web tools I may need, such as a tool to tell me my public ip because I can never remember it. I want to embed the admin login page for my network, but I can't seem to get it to work with ip addresses.
I tried a bunch of other embed methods, but none of them showed anything aside from a blank white page.
Here's a few of my attempts:
Attempt 1:
<object data=http://192.168.1.1 width="100%" height="100%">
<embed src=http://192.168.1.1 width="100%" height="100%"></embed> Error: Embedded data could not be displayed.
</object>
Shows the error message.
Attempt 2:
<?php
$URL = "http://192.168.1.1";
$base = '<base href="'.$URL.'">';
$host = preg_replace('/^[^\/]+\/\//', '', $URL);
$tarray = explode('/', $host);
$host = array_shift($tarray);
$URI = '/' . implode('/', $tarray);
$content = '';
$fp = #fsockopen($host, 80, $errno, $errstr, 30);
if(!$fp) { echo "Unable to open socked: $errstr ($errno)\n"; exit; }
fwrite($fp,"GET $URI HTTP/1.0\r\n");
fwrite($fp,"Host: $host\r\n");
if( isset($_SERVER["HTTP_USER_AGENT"]) ) { fwrite($fp,'User-Agent: '.$_SERVER
["HTTP_USER_AGENT"]."\r\n"); }
fwrite($fp,"Connection: Close\r\n");
fwrite($fp,"\r\n");
while (!feof($fp)) { $content .= fgets($fp, 128); }
fclose($fp);
if( strpos($content,"\r\n") > 0 ) { $eolchar = "\r\n"; }
else { $eolchar = "\n"; }
$eolpos = strpos($content,"$eolchar$eolchar");
$content = substr($content,($eolpos + strlen("$eolchar$eolchar")));
if( preg_match('/<head\s*>/i',$content) ) { echo( preg_replace('/<head\s*>/i','<head>'.
$base,$content,1) ); }
else { echo( preg_replace('/<([a-z])([^>]+)>/i',"<\\1\\2>".$base,$content,1) ); }
?>
Shows a blank screen, no error message because I have no clue what I'm doing and couldn't find a spot to put said error message without screwing it up.
And finally, attempt 3:
<iframe src="/http://192.168.1.1" width="100%" height="300">
<p>Your browser does not support iframes.</p>
</iframe>
You can probably guess what showed up :/
i'm trying to display some custom facebook feeds on my website from a facebook fan page.
This is a summary sample of the php I used, and it works fine.
[...html code...]
// include the facebook sdk
require_once('resources/facebook-php-sdk-master/src/facebook.php');
// connect to app
$config = array();
$config['appId'] = 'MY_APP_ID';
$config['secret'] = 'MY_SECRET_CODE';
$config['fileUpload'] = false; // optional
// instantiate
$facebook = new Facebook($config);
// set page id
$pageid = "MY_PAGE_ID";
// access to the graph, starting with the feed
$pagefeed = $facebook->api("/" . $pageid . "/feed");
[...html code...]
$i = 0;
foreach($pagefeed['data'] as $post) {
// check if post type is a photo and catch the various part of the graph
if ($post['type'] == 'photo') {
//grab the thumbnail url in the graph
$picture_url = $post['picture'];
//get true sized photo by manipulating its url
$picture_url_big = str_replace("s130x130/","", $picture_url);
echo "<p><img class=\"img-icon\" src=\"" . $post['icon'] . "\"></p>";
echo "<h2 class=\"data-post\">" . date("j-n-Y", (strtotime($post['created_time']))) . "</h2>";
//displaying the photo
echo "<div class=\"img-thumb\"><img src=\"" . $picture_url_big . "\"></div>";
echo "<p class=\"manda-a-capo\"></p>";
if (empty($post['story']) === false) {
echo "<p>" . $post['story'] . "</p>";
} elseif (empty($post['message']) === false) {
echo "<p>" . $post['message'] . "</p>";
}
echo "<p><u><b>Vedi foto</b></u></p>";
echo "<p class=\"manda-a-capo\"></p>";
if ($post['shares']['count'] != "") {
echo "<p class=\"manda-a-capo share-num\">" . $post['shares']['count'] . " condivisioni.</p>";
}
}
$i++;
}
[...other code...]
The facebook graph contains only the thumb url of the photos, that is 130x130px. I discovered that some thumbs have an "/s130x130/" parameter in the url and, if you delete this parameter, you get the photo in its actual size.
So this explains this part of code (as above):
//grab the thumbnail url in the graph
$picture_url = $post['picture'];
//get true sized photo by manipulating its url
$picture_url_big = str_replace("s130x130/","", $picture_url);
//then displaying the photo
echo "<div class=\"img-thumb\"><img src=\"" . $picture_url_big . "\"></div>";
Unfortunately I noticed that not all photos from the page have this parameter and some of them have even a different url structure.
So the final result is that I can reach only few photos in their actual size, others remain a broken link.
Is there a way to manipulate the url to get all the photos in their own actual size?
Any advices?
Thanks.
P.S.
Here's the php to view the fb graph:
<?php
echo "<pre>";
print_r($pagefeed);
echo "</pre>";
?>
I found a temporary solution. In order to display the missing links I've added a php function that checks if the image url exist or not.
function checkRemoteFile($picture_url_big)
{
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$picture_url_big);
// don't download content
curl_setopt($ch, CURLOPT_NOBODY, 1);
curl_setopt($ch, CURLOPT_FAILONERROR, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
if(curl_exec($ch)!==FALSE)
{
return true;
}
else
{
return false;
}
}
And a control just above the "echo"
if (checkRemoteFile($picture_url_big)) {
//echo "image exist ";
$check = true;
$picture_url_big;
} else {
//echo "image does not exist ";
$check = false;
$picture_url_big = $picture_url;
}
I'm trying to print a website's favicon, as an image, not as a link to it.
I have a php script in which I extract the favicon, but now I want to show it as it is.
Here is what I've tried.
//extract favicon
$url = $_POST['url'];
$doc = new DOMDocument();
$doc->strictErrorChecking = FALSE;
$doc->loadHTML(file_get_contents($url));
$xml = simplexml_import_dom($doc);
$arr = $xml->xpath('//link[#rel="shortcut icon"]');
echo "<br>";
//echo "favicon:";
if( $arr)
{
$src = $arr[0]['href'];
echo "<img src = "$src">";//as I can see, the parameter here cannot be a variable
//second thing that I've tried: echo "<img src = "$arr[0]['href']""; it doesn't work either
}
This is what my script is echoing right now. http://i.stack.imgur.com/Wkoyj.jpg
Instead of the link to the favicon, I want the actual favicon to be displayed. I hope I explained myself correctly.
Your error is with the code:
echo "<img src = "$src">";//as I can see, the parameter here cannot be a variable
It should be
echo '<img src="'.$src.'">';
Or even
echo "<img src=\"$src\">";
I have stored images path in database and images in project folder. Now i am trying to view all IMAGES with their PRODUCTS in my HTML template. I have written the following code and its given me an empty images box in the output and when i open that image box in the new tab, it opens the following URL.
http://localhost/cms/1
Kindly tell me the way of referring images in 'img src ' tag.
include 'connect.php';
$image_query = "select * from product_images";
$image_query_run = mysql_query($image_query);
$image_query_fetch = mysql_fetch_array($image_query_run);
if (!$query=mysql_query ("select product_id,name from products")) {
echo mysql_error();
} else {
while ($query_array = mysql_fetch_array($query)) {
echo '</br><pre>';
$product_id = $query_array['product_id'];
echo "<a href='single_product.php?product_id=$product_id' >";
print_r ($query_array['name']);
echo "</a>";
echo "<img src=". $image_query_fetch
['images'] ." alt=\"\" />";
echo '</pre>';
}
}
} else {
echo "You need to Log in to visit this Page";
}
Add your local image path before source
example
echo "<img src='http://localhost/cms/1/". $image_query_fetch['images'] .'" alt=\"\" />";
*Use PHP *
<?php echo "http://" . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']; ?>
You can use the HTML base tag to set a base URL that relative URLs will be resolved from.
See -> http://www.w3schools.com/tags/tag_base.asp
The script I am using 'gets' a html page and parses is showing only the .jpg images within, but I need to make some modifications and when i do it simply fails...
This works:
include('simple_html_dom.php');
function getUrlAddress() {
$url = $_SERVER['HTTPS'] == 'on' ? 'https' : 'http';
return $url .'://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];
}
$html = file_get_html($url);
foreach($html->find('img[src$=jpg]') as $e)
echo '<img src='.$e->src .'><br>';
However, there are some problems... I only want to show images over a certain size, plus some site do not display full URL in the img tag and so need to try to get around that too... so I have done the following:
include('simple_html_dom.php');
function getUrlAddress() {
$url = $_SERVER['HTTPS'] == 'on' ? 'https' : 'http';
return $url .'://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];
}
$html = file_get_html($url);
foreach($html->find('img[src$=jpg]') as $e)
$image = $e->src;
// check to see if src has domain
if (preg_match("/http/", $e->src)) {
$image = $image;
} else {
$parts = explode("/",$url);
$image = $parts['0']."//".$parts[1].$parts[2].$e->src;
}
$size = getimagesize($image);
echo "<br /><br />size is {$size[0]}";
echo '<img src='.$image.'><br>';
This works, but only returns the first image.
On the example link below there are 5 images, which the first code shows but does not display them as the src is without the leading domain
Example link as mentioned above
Is there a better way to do this? And why does the loop fail?
You seem to be missing a {:
foreach($html->find('img[src$=jpg]') as $e) {
You forgot your brackets:
foreach($html->find('img[src$=jpg]') as $e){
$image = $e->src;
// check to see if src has domain
if (preg_match("/http/", $e->src)) { $image = $image; }
else {
$parts = explode("/",$url);
$image = $parts['0']."//".$parts[1].$parts[2].$e->src;
}
$size = getimagesize($image);
echo "<br /><br />size is {$size[0]}";
echo '<img src='.$image.'><br>';
}