I am trying to load a JS file with cURL, but the result is getting truncated. I also tried file_get_contents and it still truncates.
But I can access .js file directly from browser. There isn't anything in the request headers except user agent and referer, which I included in curl request.
What is going on? Is the server messing with me?
The issue was that the browser wasn't showing full code. I echoed the output inside <script> tag, and it was appending DOM elements. Then I split the output into parts and was sure it wasn't being truncated.
Related
I'm using PHP to do some processing then pass along variables to an shtml file that is included with virtual(). Yes, I have to use this file and cannot simply do all the processing in php.
In Chrome if I use echo " "; before I call virtual(), it displays the page properly, but displays a blank page if I don't use echo.
In other browsers it displays no content.
Is there something I'm missing? I've tried playing with the headers set by php but I've had no luck so far.
I made a bitly url shrinker, and I currently have a Soundcloud Javascript API that outputs a url link of a song. Im trying to shrink it using my shrinker. The shrinker works using this:
<?php echo $bitly->shorten('http://google.com'); ?> //Equals google.com in short url format
The javascript code I'm trying to implement it in is this: Ill go ahead and give you what I tried to do already, that didn't work.
Before I edited:
container.find('span.player-actions').html(
'Soundcloud | Download'
);
After I tried:
container.find('span.player-actions').html(
'Soundcloud | Download'
);
Any suggestions, I'm open to anything. And would love to make this work!
That has been already explained but in case you're new to this concept, there is a simplified explanation.
<?php tags in your code are processed on server before your page is sent to user's browser. Actually browser never receives those tags - they're replaced with PHP output on server and then the resulting page is sent to user.
As a result of some mistake sometimes PHP code makes into user's browser but it behaves as any other non-standard tag - content between <?php and ?> would be invisible to visitor.
JavaScript, on the other hand, operates in user browser with (in our case) what PHP has already output. When you change the page with JavaScript, it's not sent back to server - actually, server is totally unaware of that, so it can't execute the PHP code you're outputting by your JavaScript.
In order to achieve a similar result you need to send an AJAX request from your JavaScript code. It'll basically be another "page request" initiated by your JavaScript, but happening at the background with PHP output not replacing your current page, but arriving into your JavaScript code. This way your JavaScript is outputting PHP output and not PHP code, that's why it is possible.
You cannot call PHP on a string that is generated via javascript since PHP is server side and executed before JavaScript which is client side.
If you want to shorten this string, you'll have to make an ajax call to a php page that will return the shrunk url.
I am going to write a parser that is going to get information from a website.
However something is wrong with this website and soon as i fetch the information and put it in a file, it's all gibberish.
The website is anidb.net
Could anyone tell me why i get gibberish instead of the HTML?
My code
<?php
$url = 'http://anidb.net/perl-bin/animedb.pl?show=anime&aid=854';
file_put_contents("file.txt", file_get_contents($url));
?>
May i also add that using the browser's View Source function i see the HTML.
I checked the headers on the page that you specified and it's returning:
Content-Encoding: gzip
That means the 'gibberish' you're seeing is indeed gzip encoded. Here's another thread that should help you out:
Decode gzipped web page retrieved via cURL in PHP
Okay, so I have an issue with an AJAX request. I currently have this URL:
http://www.google.com/images?hl=en&safe=off&gbv=2&tbs=isch%3A1&sa=1&q=cars+imagesize%3A500x500&aq=f&aqi=&aql=&oq=&gs_rfai=&start=0
I then pass it to my proxy script by modifying the string to this:
proxy.php?url=http://www.google.com/images?hl=en&safe=off&gbv=2&tbs=isch%3A1&sa=1&q=cars+imagesize%3A500x500&aq=f&aqi=&aql=&oq=&gs_rfai=&start=0
I need to use the PHP proxy script to grab that page's HTML so that I can then parse through it with javascript. However, the problem is that the headers in that URL are also being sent to the proxy script, and as a result, I get a 'malformed or illegal request' error. I'm pretty sure the two different sets of headers are the problem, because if I just replace the original URL string with 'http://wwww.google.com', the proxy returns the HTML of the page correctly.
So basically, I don't know how to fix this. I'm a complete PHP noob, and I tried escaping the original URL before I appended it to the 'proxy.php?url=', but that doesn't fix anything. Any ideas?
Thanks!
Figured it out- you need to use encodeURIComponent() on the original URL string before you append it to the proxy string.
I have the following:
$imageurl = "<img class='item_thumb'
src='getimagethumbnail.php?imagename=".urlencode($product_image)."&from=".$prodimagedir."'
min-width='150' min-height='150' border='0' class='item_thumb'>";
Which creates the following html:
<img class="item_thumb" border="0" min-height="150" min-width="150"
src="getimagethumbnail.php?imagename=productsmall_1248886833bloggingbok.jpg&
from=products/"/>
However, the image does not show up. I point my browser to that src link and it gives me a bunch of unreadable text which I am assuming is the image meaning that the script getimagethumbnail is working fine. (I am guessing).
But as I said, the image is not appearing at all. What is wrong and what steps can I take to determine the problem?
Just to add, when I point my browser to that src link: It also gives me:
Warning: Cannot modify header information - headers already sent by
(output started at /home/dji/public_html/getimagethumbnail.php:35) in
/home/dji/public_html/includes/functions.php on line 4953
I am assume this is because of the output?? This script was working fine and I have made no changes to it as far as I am aware!
Thanks
You are trying to send the header('Content-Type') command, after outputting whitespace/characters.
You need to make sure that the header command is before anything is printed on the page.
This will work:
header('Content-Type: ....');
readfile('file.png');
This won't
readfile('file.png');
header('Content-Type: ....');
This is because the header command tells the browser what to look for in the content. All of the headers must be sent before any content because that is how the connections works. The browser can't be told what to expect after the content has already been sent.
Open Connection With Server -> Get Headers -> Get Content -> Close Connection
One of the big reasons behind this is encoding. As the content comes through, the browser has to decode it properly. If you send a header in the middle of the page telling the browser that the encoding type is a, when it was processing it like b, things can get really confusing.
So, in order to send the headers properly, you must put the header command before any output.
That error is caused when you print stuff to the output and then attempt to use the header() method. You shouldn't be outputting anything until after you do what you need with header(). Nothing should precede this, not even white-space.
You already have produced some output (on line 35) before setting the header for the image type. This might simply be a whitespace between php tags, or something you forgot to remove.
Your getimagethumbnail.php script is not generating a valid image; it's including text in it (the warning message you quote), which prevents browsers from rendering it. Judging by the error text, I'd guess this is due to changes made either to getimagethumbnail.php or functions.php.
Fundamentally, the problem is that functions.php is attempting to call header() after output has already been sent to the browser, which just plain won't work. You need to check both files and make sure that any calls to header() come before anything else that sends data to the browser.
You may want to turn off the display_errors setting, as any code which generates any warning or error for any reason will cause the problem you're seeing if the warning/error occurs before your header() calls. (Just make sure you have error logging on, so you can still see what's going wrong!)