|
Posted by Rik Wasmus on 08/31/07 09:15
On Fri, 31 Aug 2007 10:50:33 +0200, <pete.brooker@gmail.com> wrote:
> On Aug 23, 4:21 pm, Jerry Stuckle <jstuck...@attglobal.net> wrote:
>> pete.broo...@gmail.com wrote:
>> > Being new to PHP & cookies, I am looking to write an email form, wh=
ere
>> > a user can choose their name from a drop down list, fill in the
>> > content of the email and hit send and the email will be from that
>> > user.
>>
>> > Then the next time they visit the page, I want to be able to read t=
hat
>> > cookie and preset the From part of the email from the cookie.
>>
>> > But I have no clue where to start and can't find any examples of th=
e
>> > web.
>>
>> > If anyone can help out or point me at a script that has this I'd be=
>> > very grateful.
>>
>> > Many thanks
>> > Pete
>>
>> It's pretty easy - you can start at:
>>
>> http://us.php.net/manual/en/features.cookies.php
>>
>> Just keep in mind you can't control cookie behavior on the browser en=
d.
>> For instance, my browser is set up to destroy all cookies when I cl=
ose
>> it (except for sites I specify).
(topposting fixed)
> Do you have any example code or give me some pointers.
>
> Pretty new to this and not so sure where to start...
In the 'form page':
$from =3D isset($_COOKIE['from']) ? htmlspecialchars($_COOKIE['from']): =
'';
echo '<input name=3D"from" value=3D"'.$from.'">';
In the page that sends the email:
if(isset($_POST['from']) && !isset($_COOKIE['from'])) =
setcookie('from',$_POST['from'],time() + (60 * 60 * 24 * 60), '/');
Keep in mind that the setcookie() function can only be used before ANY =
OTHER output. No starting HTML tags, no whitespace, nothing can be sent =
=
before this function.
-- =
Rik Wasmus
My new ISP's newsserver sucks. Anyone recommend a good one? Paying for =
quality is certainly an option.
Navigation:
[Reply to this message]
|