I have a website hosted on my local server (http://localhost/), which uses url_rewriting.
When I access a page with the browser, no issue, it's loading.
But when I access the same url with PHP cUrl, I get a 404.
Example:
URL with mod_rewrite: http://localhost/site/test
Real page: http://localhost/site/test.php
Loading http://localhost/site/test from Firefox: Working
Loading using cUrl:
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "http://localhost/site/test");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
$output = curl_exec($ch);
curl_close($ch);
$output -> 404 page from apache
Anybody knows why cUrl returns a 404 message?
Turns out this has nothing to do with mod_rewrite.
One of the directory in the URL had a space in it, that I was not encoding when calling the cUrl function.
Once replaced all space by %20, everything worked fine.
Subject closed.
Related
I am trying to load an XML file, but for some reason I can't use a URL.
allow_url_fopen is set to On.
I used this, which didn't work:
$xml = simplexml_load_file("https://example.corn/test.xml");
But this does work:
$xml = simplexml_load_file("../test.xml");
I also tried file_get_contents:
$xml = file_get_contents("https://example.corn/test.xml");
and even cURL:
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://example.corn/test.xml");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$xml = curl_exec($ch);
curl_close($ch);
For each example I am displaying the output with var_dump($xml);, which always shows bool(false) when using a URL and shows the correct XML data when using a local path.
I would just use the local path, but this is just for a test and the actual XML file I am going to fetch is from a different site.
I tested it on a local server and it worked, but on my hosted server, it doesn't work at all. They are using the same php.ini. My hosted server is using php-fpm, I'm unsure if that could be a factor, or if there is something that has to be changed with it.
This might be a configuration error that I am unaware of, because the code should work, and the link definitley exists, because I can click on it and see the correct xml in the browser.
What could be causing this issue?
Turns out that I had my openssl.cafile property set to some location that didn't exist.
For some reason no errors were showing when using the commands above.
I think the specified url is not valid or doesn't exist
Read about curl in the PHP docs
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "http://www.example.com/");
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_exec($ch);
curl_close($ch);
i have some problems.
I need to keep data from coinmarketcap. When I was developing on localhost it worked well.
But on third level domain coinfollow.altervista.org i can not receive the data
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://api.coinmarketcap.com/v1/ticker/");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
$output = curl_exec($ch);
curl_close($ch);
$outputdecoded = json_decode($output, true);
echo $outputdecoded;
I try in another domain mywebsite.com and it worked. I think that the problem is coinfollow.altervista.org domain.
I need to save coinmarketcap data into my database with a simple query.
Does anyone know a solution?
It sounds like there is a server config issue on coinfollow.altervista.org, such as curl not being enabled for php.
You can run phpinfo(); to see if curl is installed.
If it is installed try running echo curl_error($ch) to see if there are any errors returning from curl
I have been using cURL code to access Beanstream for awhile now, and all of a sudden it stopped working as of yesterday. I have determined that this has to do with accessing the HTTPS URL for Beanstream processing, as if I test that same code and just go to the HTTP URL, it works (of course it returns an insecure connection code).
Prior to the below code I was setting VERIFYPEER / VERIFYHOST to FALSE, which was working up until yesterday.
$url = 'https://www.google.com';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 30);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
curl_setopt($ch, CURLOPT_CAINFO, "/xxxx/public_html/_cert/GeoTrustGlobalCA_google.crt");
$getResponse = (curl_exec($ch));
curl_close($ch);
print_r($getResponse);
I have setup the above test code to try and access Google via HTTPS. I had read that a proper connection requires the VERIFYPEER / CAINFO options to be set, which I have done and grabbed the Google .crt and placed it on the web server as well.
I still get a 503 Service Unavailable error back though.
The server is temporarily unable to service your request due to maintenance downtime or capacity problems. Please try again later.
Additionally, a 503 Service Unavailable error was encountered while
trying to use an ErrorDocument to handle the request.
iam using that php code in the localhost and working fine
$ch = curl_init($src);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_NOBODY, true);
curl_exec($ch);
$url = curl_getinfo($ch, CURLINFO_EFFECTIVE_URL);
when i move it to the remote server the script ignores that code
and doesn't give me a result (still giving me the original url )
note: i use cURL here to give me the true url after redirect
Maybe there is some difference in the configuration of the remote server.
phpinfo();
Shows the configuration of php and of the curl module
I am using the curl function on my site if I use the url http://www.markettrendsignal.com/v1/market/header_cal.php it is showing the error not found else if I removed the www in front of the error it is working fine but I want the www in the url. How can I resolve it. I check the url it is working fine with www and without www. I am using the curl function in the same doamin.It is showing the following error.
"Not Found
The requested URL /v1/market/header_cal.php was not found on this server.
Apache/2.2.3 (Red Hat) Server at www.markettrendsignal.com Port 80"
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'http://www.markettrendsignal.com/v1/market/header_cal.php');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$contents = curl_exec ($ch);
print_r($contents);
curl_close ($ch);
use CURLOPT_FOLLOWLOCATION on curl_setopt function. It will follow the link even in redirect. This is caused because for your htacces file. Domain hosted without www and you putting the link www so the page redirected as 301. See the available option http://www.php.net/manual/en/function.curl-setopt.php
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "http://www.markettrendsignal.com/v1/market/header_cal.php");
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
$curled=curl_exec($ch);
curl_close($ch);
print_r($curled);
It is working well on my side, please use this