FUDforum
Fast Uncompromising Discussions. FUDforum will get your users talking.

Home » Imported messages » comp.lang.php » script php with <img scr...../>
Show: Today's Messages :: Polls :: Message Navigator
Return to the default flat view Create a new topic Submit Reply
Re: script php with <img scr...../> [message #180225 is a reply to message #180224] Thu, 31 January 2013 20:42 Go to previous messageGo to previous message
Jerry Stuckle is currently offline  Jerry Stuckle
Messages: 2598
Registered: September 2010
Karma:
Senior Member
On 1/31/2013 3:37 PM, The Natural Philosopher wrote:
> On 31/01/13 18:11, sferreira1979(at)gmail(dot)com wrote:
>> Hi,
>>
>> i'm a portuguese's student and i'm trying to learn php by myself (with
>> books and php.net) but i'm experiencing a problem on one of my test:
>> i have two files: registar_mail.php and captcha.php
>> captcha.php display an image witch should appear on my file
>> registar_mail.php using
>> <img src="captcha.php"/> but the image doesn't appear :(
>> i have been looking for a solution in forums but i don't find anything
>> witch works with me... i'm working with netbeans and xampp
>>
>> ////// script registar_mail.php//////////
>> !DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
>> "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
>> <html xmlns="http://www.w3.org/1999/xhtml">
>> <head>
>> <meta http-equiv="Content-Type" content="text/html;
>> charset=iso-8859-1" />
>> <title>MAILING LIST</title>
>> <style type="text/css">
>> @import url("estilo_mailinglist.css");
>> </style>
>> </head>
>> <body>
>>
>>
>> <?php
>> // Ligação à base de dados
>> //phpinfo();
>> include("ligacao_bd.php");
>>
>> // verifica se foi clicado o botão de registar
>> if(isset($_REQUEST['registar'])) {
>>
>> // verifica se o código captcha está correto
>> if($_SESSION['codigo'] == $_POST['codigo']){
>>
>> // verifica se o campo de email está por preencher
>> if (empty($_POST['email'])) {
>> echo "<tr>O campo de endereço de correio eletrónico está vazio!
>> </tr>";
>> echo "<tr><a href='registar_mail.php'>Clique para tentar de
>> novo!</a></tr>";
>> }
>> else {
>>
>> // verifica se endereço de correio eletrónico esta correto
>> $email = $_POST['email'];
>> if(filter_var($email, FILTER_VALIDATE_EMAIL)){
>>
>> // regista o email
>> $sql = "INSERT INTO emails(endereco_email, data_registo) VALUES (
>> '$email' , NOW() ) ";
>> $consulta = mysql_query($sql);
>>
>> echo "<table>";
>> echo "<tr>Obrigado por se registar!</tr>";
>> echo "<tr><a href='registar_mail.php'>Clique para voltar à página
>> principal!</a></tr>";
>>
>> } else {
>> echo "<tr>O endereço de correio eletrónico não é válido! </tr>";
>> echo "<tr><a href='registar_mail.php'>Clique para tentar de
>> novo!</a></tr>";
>> } } } }
>> ?>
>> <table width="800 px" border="0" align="center" class="tabela_geral"
>> cellspacing="0">
>> <form id="form_registo" name="form_registo" action="registar_mail.php"
>> method="POST">
>> <tr class="tabela_geral">
>> <td> Introduza o seu endereço de correio eletrónico para se registar
>> na nossa<i> mailing list</i>!
>> </td>
>> </tr>
>> <tr><td class="tabela_geral">
>> Endereço de correio eletrónico: <input type="text" size=40 name="email">
>> </td><tr>
>> <td>
>> <img scr='captcha.php' alt="imagem ausente"/> <input type="text"
>> name="codigo"/>
>> <img src="imagens/imagemcaptcha.png" width="230" height="50"
>> alt="imagemcaptcha"/>
>>
>> </td>
>> </tr>
>> <td>
>> <input type="submit" name="registar" value="Registar">
>> <input type="reset" name="apagar" value="Apagar"></td>
>> </form>
>> </table>
>> </body>
>> </html>
>>
>> /////script captcha.php//////////////////
>> <?php
>> //inicia sessão
>> session_start();
>
> Bad move. Nio sessions pelae!
>>
>> //definição do tipo de imagem a gerar
>> header("Content-type:image/png");
>>
>> //geração da chave
>> $chave=rand(0,500);
>>
>> //codificação da chave e apresentacao de 8 carateres
>> $codigo=substr(sha1($chave),0,8);
>>
>> $_SESSION['codigo']=$codigo;
>>
>> //definicao imagem e cor
>> $imagem= imagecreatefrompng("imagens/imagemcaptcha.png");
>> $cores= imagecolorallocate($imagem, 255, 55, 0);
>>
>> //centrar código na figura
>> imagestring($imagem, 5, 75, 20, $codigo, $cores);
>>
>> //gerar imagem:Outputs or saves a PNG image from the given image.
>> imagepng($imagem);
>>
>> //DESTRUIR IMAGEM
>> imagedestroy($imagem);
>>
>> ?>
>>
>> could someone help me to understand what is the problem???
>>
>> thanks :)
>>
>
>
> The simplest php script to send a picture is this
> <? php5
> header("Content-Type: image/jpeg");
> $fh = fopen("myfile.jpg", "r");
> fpassthru($fh);
> flose($fh)';
>
> // and leave the ?> OUT of things.
> // and sessions.
>
>

Which has nothing to do with his problem (or a solution to it).

And in your example, the simplest way to do it is to not use PHP at all.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex(at)attglobal(dot)net
==================
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: compatibility between php 5.3.21 and 5.3.15 for pgsql
Next Topic: change a string where have number after a word
Goto Forum:
  

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ]

Current Time: Fri Sep 20 05:32:10 GMT 2024

Total time taken to generate the page: 0.03675 seconds