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

Home » Imported messages » comp.lang.php » newbie question
Show: Today's Messages :: Polls :: Message Navigator
Return to the default flat view Create a new topic Submit Reply
Re: newbie question [message #170961 is a reply to message #170957] Sun, 12 December 2010 10:13 Go to previous messageGo to previous message
Helmut Chang is currently offline  Helmut Chang
Messages: 22
Registered: September 2010
Karma:
Junior Member
Am 12.12.2010 03:06, schrieb justaguy:

> The redirection is ok but the email capture failed. It seems that the
> logMessage isn't called.

Yes, it isn't.

> How can we fix it?

In calling the function. As you already said: you declare the function,
but you don't call it:

> <?php
> $email = $_POST['email'];
> // $email = $HTTP_POST_VARS['email'];
> echo "$email<br />";

This is the declaration of the function:

> function logMessage($email)
> // debug
> echo "email recording function called.";
> {
> $myFile = "Log.txt";
> $contentsOld = file_get_contents($myFile, true);
> $fh = fopen($myFile, 'w') or die("couldnt locate log file");
>
> $stringData = date("l F j, Y, g:i:s a") . "\nEmail: " . $email . "\n
> \n";
> fwrite($fh, $contentsOld);
> fwrite($fh, $stringData);
> fclose($fh);
> }
>
> // debug
> // echo "email has been processed.";

But if you want to run the function, you must call it:

logMessage($email);

> header( 'Location: http://www.mysite.com/newlocation.html' ) ;
> ?>

That's the purpose of a function: you define/declare it once and then
you can call it anytime you want with different values for the parameters:

<?php

/**
* Writes the provided $email to a log file.
*/
function logMessage($email) {
...
}

$email = $_POST['email'];
logMessage($email);

$email2 = 'foo(at)example(dot)com';
logMessage($email2);

logMessage('bar(at)example(dot)com');

?>

It's the same as with PHP's native functions, as in your script:

fwrite($fh, $contentsOld);
fwrite($fh, $stringData);

And I strongly suggest to do some validation in your script!

Helmut
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: Use of Includes
Next Topic: Stats comp.lang.php (last 7 days)
Goto Forum:
  

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

Current Time: Fri Nov 22 20:32:43 GMT 2024

Total time taken to generate the page: 0.04631 seconds