reload php-image
Moderator: General Moderators
- julian_lp
- Forum Contributor
- Posts: 121
- Joined: Sun Jul 09, 2006 1:00 am
- Location: la plata - argentina
reload php-image
I've, inside an html page, an image which is created through a php file :
<img src="<?php echo 'captcha.php'; ?>">
file captcha.php, sends
header("Content-type: image/png");
and assign a value to an a session variable
All works fine, but I need to reload the image (a new captcha code should be generated) without reloading the enitre page. Are there any solution? It seems to be a javascript related question...
I'm working on a "post comment" form using ajax.
<img src="<?php echo 'captcha.php'; ?>">
file captcha.php, sends
header("Content-type: image/png");
and assign a value to an a session variable
All works fine, but I need to reload the image (a new captcha code should be generated) without reloading the enitre page. Are there any solution? It seems to be a javascript related question...
I'm working on a "post comment" form using ajax.
- daedalus__
- DevNet Resident
- Posts: 1925
- Joined: Thu Feb 09, 2006 4:52 pm
Why wouldn't you just say
?
It's the same as echoing it. You might want to say
Have it do something a tad bit different every time?
Code: Select all
<img src="captcha.php" />It's the same as echoing it. You might want to say
Code: Select all
echo '<img src="captcha.php?v='.$random_letter.'" />';- daedalus__
- DevNet Resident
- Posts: 1925
- Joined: Thu Feb 09, 2006 4:52 pm
- julian_lp
- Forum Contributor
- Posts: 121
- Joined: Sun Jul 09, 2006 1:00 am
- Location: la plata - argentina
Great thread. Sadly, even though I've read it, I cant get the job done. While I re-read that post entirely, could someone give me any hint?
This is how I generate, when the page loads, the captcha image (works well)
Code: Select all
<img id="mainimage" src="simplecaptcha/captcha.php" alt="CAPTCHA">Note that I tried both with absolute and relative paths to the php file
Code: Select all
<a href="javascript:void(0)" onclick="ReloadCaptcha();">give me an easier one!</a>
<script type="text/javascript">
function ReloadCaptcha(){
alert ('ReloadCaptcha');
///document.getElementById('mainimage').src='simplecaptcha/captcha.php';
document.getElementById('mainimage').src='http://REALPATH/captcha.php';
return false;
}
</script>Try
It's an ages old trick used to force picture to be re-requested from server.
Code: Select all
document.getElementById('mainimage').src='http://REALPATH/captcha.php?' + Math.random();
- julian_lp
- Forum Contributor
- Posts: 121
- Joined: Sun Jul 09, 2006 1:00 am
- Location: la plata - argentina
Weirdan wrote:TryIt's an ages old trick used to force picture to be re-requested from server.Code: Select all
document.getElementById('mainimage').src='http://REALPATH/captcha.php?' + Math.random();
Let me tell you something in one word:
It_works_like_a_charm
I'd like to know why though
many thanks Weirdan