You are on page 1of 4

Prcticas en Php

1.- Este cdigo muestra un formulario que se enviar por correo electrnico al webmaster o al
administrador del sitio.
Indicar que es lo que hace en cada lnea.
<html>
<head>
<title> un pequeo mailer para recopilar la opinin</title>
<meta http-equiv="content-type" content="text/html;charset=ISO-8859-1" >
</head>
<body>
<h1>Feedback-Mailer</h1>
<p>Enviame un e-mail!</p>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
Tu direccin de e-mail: <br>
<input type="text" name="Mail" ><br>
Tu comentario: <br>
<textarea name="message" cols="50" rows="5">
</textarea><br>
<input type="submit" value="Enviar">
</form>
<?php
$receiverMail = "tudireccion@tudominio.es"; // escribe aqui tu direccin
if (isset($_POST['Mail']) && $_POST['Mail'] != "") {
if (mail ($receivermail, "Tienes correo nuevo!", $_POST['message'], "From:
$_POST[Mail]")) {
echo "<p>Gracias por enviarme tu opinin.</p>\n";
} else {
echo "<p>Lo siento, ha ocurrido un error.</p>\n";
}
}
?>
</body>
</html>

Observaciones:____________________________________________________________________________
________________________________________________________________________________________
________________________________________________________________________________________
________________________________________________________________________________________

2.-Este cdigo hace un contador de visitas para un sitio web.


<html>
<head>
<title>Contador Sencillo</title>
</head>
<body>
<h1>Contador Sencillo</h1>
<p>Cantidad de visitas:
<b>
<?php
$fp = fopen("counter.txt", "r+");
$counter = fgets($fp, 7);
echo $counter;
$counter ++;
rewind($fp);
fputs($fp, $counter);
fclose($fp);
?>
</b></p>
</body>
</html>

Contesta las siguientes preguntas:


1.- Qu hace la funcin fopen?
2.- Qu hace la funcin fgets?
3.- Qu hace rewind?
4.- Qu hace la funcin fputs?

Observaciones:____________________________________________________________________________
________________________________________________________________________________________
________________________________________________________________________________________
________________________________________________________________________________________

3.-Capturar el siguiente cdigo que realiza una encuesta y guarda el resultado en un archivo txt.
Explicar que hace cada lnea
<?php
setcookie("check", 1);
if (isset($_POST['submit'])) {
setcookie("vote", 1);
}
?>
<html>
<head>
<title>Encuesta de opinion</title>
<meta http-equiv="content-type" content="text/html;charset=iso-8859-1">
</head>
<body>
<h1>Encuesta</h1>
<h3>Que opinas de este curso de php?</h3>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
<input type="radio" name="reply" value="0">
Excelente, he aprendido mucho.<br>
<input type="radio" name="reply" value="1">
Mas o menos, es muy complicado.<br>
<input type="radio" name="reply" value="2">
Buu! para que quiero aprender php
<br> <br>
<?php
if (empty($_POST['submit']) && empty($_COOKIE['voted'])) {
?>
<input name="submit" type="submit" value="vota!">
<?php
} else {
echo "<p>Gracias por tu voto.</p>\n";
if (isset($_POST['reply']) && isset($_COOKIE['check']) && empty($_COOKIE['voted'])) {
$file="results.txt";
$fp=fopen($file, "r+");
$vote=fread($fp, filesize($file));
$arr_vote = explode("," , $vote);
$reply = $_POST['reply'];
$arr_vote[$reply]++;
$vote = implode(",", $arr_vote);
rewind($fp);
fputs($fp, $vote);
fclose($fp);
}
}
?>

Observaciones:____________________________________________________________________________
________________________________________________________________________________________
________________________________________________________________________________________
________________________________________________________________________________________
________________________________________________________________________________________

You might also like