I'm using kohana 3.0 with kolanos-kohana-captcha-2ba7a6a module from earlier versions. Everything works fine, but I can't figure out one thing: how do I create new captcha image for current form? For example user can't read characters and clicks 'new image'. The ajax is sent, but the response is (almost always) the same image. In the controller, I tried the following:
echo new Captcha_Basic;
Captcha::instance()->__destruct();
echo Captcha::instance();
echo $captcha->generate_challenge();
and even some more, but it's almost(??) always the same image. I even tried to delay image loading on client-side, but nothing works. Any suggestions?
I had the same problem and I have solved it by simply editing system/libraries/drivers/Captcha.php file. I have changed the image_render() function so that a random string is passed as a GET parameter in the src attribute's url.
I reckon that though ajax is not caching, the browser is caching the image's src url. Every ajax call to generate a new image does indeed generate a new image. However, the src attribute the CAPCHA library returns is always the same, causing the browser to simply show the same image it has cached. Including a randomly generated string as a GET parameter causes the browser to fetch the new image.
Related
Here is my method in a Controller:
/**
* #Route("/bilgi/agr", name="user_agreement")
*/
public function agr(): Response
{
$response = new BinaryFileResponse(__DIR__ . '/../../public/docs/User_Agreement.pdf');
$response->setContentDisposition(ResponseHeaderBag::DISPOSITION_INLINE, $response->getFile()->getFileName());
return $response;
}
I'm expecting to see Page title as User_Agreement.pdf, but instead it is agr. Which is not appropriate. I can't change the route because it is being used on several other classes/files.
Is there any way I can set a custom title or at least the file name? When I save the file I see the file name as User_Agreement.pdf so the file name is also correct.
If that is not possible is there workaround to show it in twig/html?
You can't. <title>" is an HTML element, not a PDF one.
If a browser renders a PDF directly (as many/most do nowadays), the only thing they could use for a "title" is the URL for the request. agr in your case.
It's basically something the server side has no control of. It just sends the response, and the browser decides how to show it, and what to show in the space usually reserved for the <title> element.
With the Content-Disposition header you can hint the browser about what name they should suggest for the file to the end-user, but that's all.
If you absolutely need this, yes, you could send a regular HTML response and somehow show the PDF inlined/embedded on the page.
I've created a dropzone showing existing files on the server. I've added remove links which work. My problem is that when I remove a file with its remove link, the default "Drop files here to upload" message appears in the dropzone even though there are still thumbnails remaining.
I've followed this tutorial and updated with
myDropzone.emit("addedfile", mockFile);
// And optionally show the thumbnail of the file:
myDropzone.emit("thumbnail", mockFile, "/image/url");
// Make sure that there is no progress bar, etc...
myDropzone.emit("complete", mockFile);
from Enyo's FAQ.
Why would this be happening?
On a dropzone with no existing files, this message only appears when the last file is removed.
All help appreciated.
Cheers,
Tane
Ok I've figured it out, no need to add code to manually change class names. Just add this when you're adding your mockfiles.
mydropzone.files.push(mockFile);
This files array is what dropzone is using to determine if the dropzone is empty or not. And when I was just changing the length property, code was crashing trying to access an array that was never filled.
It would be great if you provide some working code, for example on jsfiddle.net, to have better understanding what are you trying to describe here.
If I got it right, you need to catch event that there are no files to show, which is whenever you data variable is empty in init function on javascript side when the dropzone is loaded.
Also this should be handled in events thumbnail or addedfile and with removedfile. Here you can count how many files are currently available.
I've made an img editor which works fine in 99.9% of the situations.
However, in that rare 0.1% something weird happends, my session remember doesn't the proper value.
I have this in the page that inits the class:
$imgScreen = new img4crop();
// And here some settings like $imgScreen->setExtraJs($extraJs);
In this class I have a functions to save the $this data to an array:
private function save(){
$_SESSION['cropper'][$this->uniqid] = serialize($this);
}
In init-page.php I open a fancybox, loading the settings back into the class:
$info = unserialize($_SESSION['cropper'][$_GET['id']]);
// Should now be the same as $imgScreen
The problem
Sometimes $_SESSION['cropper'][$_GET['id']] is set to NULL. I have no clue why. This only happens very rarely. The key is set.
When I debug, and appendecho $_SESSION['cropper'][$this->uniqid]; to the save() function, it gives me the value I want it to have.
So, where does my session value go, only in that rare occation? Why isn't it there in the fancybox screen?
After 1st comment: It is possible for the init-page to start multiple instances, they each get their own value in $_SESSION['cropper']. In the situation above, they all work, just that one doesnt. On reload, I start new instances and the exact same screen doesnt work, even though I now has a new, fresh id
Edit: It gets weirder: If the location where the image has a file with the same name as the class will use, there are no problems. Weird part: The whole class has no code regarding to files, apart from the final step (the screen has 3 steps), where I use ImageMagick.
Important to know: When I installed the page where this occurs, the targetfile didn't exist either, started blank.
When you are serializing objects you have to make sure you load the base class (prototype) before unserializing the object. For PHP native objects you don't have to do anything, it will load the base classes.
Your variable $this is an instance of a class. In order for $this to exist the base class need to exist. Perhaps it's working most of the time because of an autoloader or the particular sequence you are loading items.
Turns out the solution was, as to be expected, a quircky little something unrelated to the actual code:
In my index.php I do $_SESSION['cropper'] = array(); to reset the array, then let the function which shows an editorscreen set new settings to the cropper, this works perfectly fine.
In that html I have an image with an anti cache:
echo '<img src="'.$image_url.'?'.time.'" />';
The problem occured when $image_url is empty/undefined, resulting in a source something like the following: ?1420793438. It starts with a ?, so it's effectively calling index.php?1420793438.
And at the beginning of that index.php we reset, resulting in an empty array.
I'm using PHP to generate the following image element:
<img id="uploaded-image" src="http://localhost/gonzo/plans/image/123/tablemap.png" />
This image URL is routed through my PHP MVC framework to the following function, which grabs the image from my db and prints it:
public function image($hexCode='',$fileName) {
if (!$this->validRequest('get')) return false;
Framework::loadModel('plan_model.php');
$plan = new PlanModel();
// Return image data from Blob field in db.
$image = $plan->getImage('123');
if ($image) {
header("Content-Type: image/png");
print $image;
die;
} else {
echo 'error';
}
}
The request generates a 302, with the wrong location and content-type headers:
The browser does not display the image where this image tag is on the page. But, when the image URL is typed directly into the address bar, the image is displayed.
Why would my server be generating a 302 when loading the image into an tag, but generating a 200 when the image URL is typed directly into the address bar? I'm running Apache on Windows.
The described behavior isn't possible at all - since the server doesn't know a bit about how an URL is embedded in a web-page.
Provide more details of the actual call of the PHP-script: Print environmental details - $_GET, $_POST and $_SERVER - to a log file.
It might be helpful to register a tick-function and trace each executed statement to a log-file.
Check your PHP sources.
It turns out that this was caused by a strange concurrency problem. My framework was still processing the first request (which generated the page containing the img element) while the browser requested the image.
In other words, when the browser requested the image, it was still receiving output from the first request to the script. This made things go wacky.
Output buffering didn't solve the problem, but possible solutions are:
Pause execution of the second (image request) script for a sufficient amount of time to let the first one complete.
Host the image serving script on a separate subdomain.
I have implemented a image gallery where in each image is differentiated by its record id . the like button works properly for rest of images only for two images its not working as intended , this is the post content sent by the image that is working properly
connect_text 0
edge_type like
fb_dtsg AQC7N-EB
href http://www.mydomain.com/images/p.php?id=2422
iframe_referer http://www.mydomain.com/index.php
is_personalized false
layout button_count
lsd
node_type link
now_connected true
page_id
post_form_id 7500ee8867c2d00acc75d7b6dfe2c733
post_form_id_source AsyncRequest
ref
and the facebook response for this is :
for (;;);{"__ar":1,"payload":{"requires_login":false,"error_info":null,"show_error":false,"node_type":"ExternalLink","node_id":"10150246004339081","edge_type":"ExternalLinkLike","connect_text":0,"success":true,"already_connected":true,"user_profile":{"name":"Mamamia","profile_url":"http:\/\/www.facebook.com\/profile.php?id=100002607508082","pic_square":"http:\/\/profile.ak.fbcdn.net\/static-ak\/rsrc.php\/v1\/yo\/r\/UlIqmHJn-SK.gif"},"story_fbid":107571802673069,"is_admin":false,"admin_url":""},"invalidate_cache":[0]}
while for the faulty image post data is
connect_text 0
edge_type like
fb_dtsg AQC7N-EB
href http://www.mydomain.com/images/p.php?id=2420
iframe_referer http://www.mydomain.com/index.php
is_personalized false
layout button_count
lsd
node_type link
now_connected true
page_id
post_form_id 7500ee8867c2d00acc75d7b6dfe2c733
post_form_id_source AsyncRequest
ref
and its response is
for (;;);{"__ar":1,"payload":{"requires_login":false,"success":false,"already_connected":false,"is_admin":false,"show_error":false,"error_info":null}}
can any body tell me why like buttons are working on some images are not working on others t ? the images content is brought from database and is linked in the page by looping the array in foreach condition so hyperlinks are same except for the id of image,the hyperlink is
http://www.facebook.com/plugins/like.php?href=http://www.mydomain.com/images/p.php?id=<?php echo $array[id]; ?>
thanks in advance
Not a proper answer, so sorry for that. But I'm experiencing the same problem exactly. It looks like facebook simply has a problem with certain GET variables in URLs. I can't think of any other explanation, it works for some and not others. The ones it doesn't work for appear to be random.
I think this must be a facebook bug. The only thing I can think to do is to either submit the bug or sit tight and hope they've spotted the problem and are working on it! Pain in the arse, mind.
EDIT: Well, I've got a workaround. Just add a random GET variable to your URL string. I went with 's=true' and that worked. Weird stuff, it must mistake URLs ending in certain numbers as character entities.
I had the same error in my header. It seems the url (domain) did not
pass the validation by facebook. In my case, i had 2 dots in it.
www.somedomain.net16.net (just a working domain)
To see if facebook can retreive data from your site use this url:
http://developers.facebook.com/tools/debug/
To test it, just type www.google.nl and you get all kind of information back.
Use facebook's iframe suggested code which can be obtained here
http://developers.facebook.com/tools/lint/