NYCPHP Meetup

NYPHP.org

[nycphp-talk] Simple form-based selection and cookie-setting/g etting

Sexton, David David.SextonJr at ubs.com
Thu Jul 31 15:39:05 EDT 2003


You are trying to execute PHP code on the client. What you would want to do
is have Javascript submit the form
(onClick="document.mediaplayerchoice.submit();"). Then have your setcookie
call at the top of the processing page... like this:
 
setcookie("preferredmediaplayer",
$_POST['preferredmediaplayer'],time()+60*60*24*30,"/player/","cmj.com",0);
 
Basically, if you view the source of the web page after it loads as it is
now, there will be no code for the onClick event since the PHP code is
parsed beforehand and does not output anything. What you will have is the
cookie value always set to 'wmp' since you are overwriting it each time a
user hits this form.
 
HTH... let me know if it's still unclear.
 

-----Original Message-----
From: Robert Dumas [mailto:rdumas at cmj.com]
Sent: Thursday, July 31, 2003 2:43 PM
To: 'NYPHP Talk'
Subject: RE: [nycphp-talk] Simple form-based selection and cookie-setting/g
etting



Okay, here's essentially what I have for the launcher. 

<form name="mediaplayerchoice" id="mediaplayerchoice" method="post"
action="<?=$PHP_SELF?>?go=1"> 
        Preferred Media Player:<br /> 
        <label><input type="radio" name="preferredmediaplayer" value="real"
onclick="<?php
setcookie("preferredmediaplayer","real",time()+60*60*24*30,"/player/","cmj.c
om",0); ?>" /> RealOne Player</label><br />

        <label><input type="radio" name="preferredmediaplayer" value="wmp"
onclick="<?php
setcookie("preferredmediaplayer","wmp",time()+60*60*24*30,"/player/","cmj.co
m",0); ?>" /> Windows Media Player</label>

</form> 

So why doesn't it prompt me to save a cookie (i have "prompt for cookie"
enabled in my browser) when i press the radio input?

By the way, thanks for all the help. I appreciate it. 

--RD 

-----Original Message----- 
From: Sexton, David [ mailto:David.SextonJr at ubs.com
<mailto:David.SextonJr at ubs.com> ] 
Sent: Thursday, July 31, 2003 2:25 PM 
To: 'NYPHP Talk' 
Subject: RE: [nycphp-talk] Simple form-based selection and 
cookie-setting/g etting 


Say you named a cookie 'player_type' in another script and assigned a value 
of 'real' or 'wmp' to it... 
Reading the value back would go something like this... 
  
if(isset($_COOKIE['player_type'])) { 
    if($_COOKIE['player_type'] == "wmp") { 
        //...statements/output for WMP 
    } 
    else { 
        //...statements/output for REAL player 
    } 
} 
  
else { 
    // Cookie doesn't exist... do whatever... 
} 

-----Original Message----- 
From: Robert Dumas [ mailto:rdumas at cmj.com <mailto:rdumas at cmj.com> ] 
Sent: Thursday, July 31, 2003 2:00 PM 
To: 'NYPHP Talk' 
Subject: RE: [nycphp-talk] Simple form-based selection and cookie-setting/g 
etting 



There's really no need for me to save the user's state on the server side of

things; all I need to do is set (and then, later, read) the cookie. 

I've read the feature on php.net about cookies, but it simply talks about 
creating them. What I'll need to do is have a PHP script in the popup player

that reads the cookie and outputs the code for the correct media player. 
How do I do this? 

-----Original Message----- 
From: Sexton, David [ mailto:David.SextonJr at ubs.com
<mailto:David.SextonJr at ubs.com>  
< mailto:David.SextonJr at ubs.com <mailto:David.SextonJr at ubs.com> > ] 
Sent: Thursday, July 31, 2003 1:14 PM 
To: 'NYPHP Talk' 
Subject: RE: [nycphp-talk] Simple form-based selection and 
cookie-setting/g etting 


Sounds like a plan... unless you foresee a use for maintaining state info 
down the line, and reliability isn't important (since clearing your cookies 
will wipe out your preference), then it's not worth the work, as Rolan 
suggested. Then again, if reliability isn't an issue, is it worth any effort


at all in trying to retain the pref? That's your preference... :) 

-----Original Message----- 
From: Robert Dumas [ mailto:rdumas at cmj.com <mailto:rdumas at cmj.com>  <
mailto:rdumas at cmj.com <mailto:rdumas at cmj.com> > ] 
Sent: Thursday, July 31, 2003 1:03 PM 
To: 'NYPHP Talk' 
Subject: RE: [nycphp-talk] Simple form-based selection and cookie-setting/g 
etting 



register/login is way morethan i need here; a simple cookie with the stored 
preference will do. If they don't choose a preferred player, they don't get 
the player. Simple as that. 

--RD 

-----Original Message----- 
From: Sexton, David [ mailto:David.SextonJr at ubs.com
<mailto:David.SextonJr at ubs.com>  
< mailto:David.SextonJr at ubs.com <mailto:David.SextonJr at ubs.com> >  
< mailto:David.SextonJr at ubs.com <mailto:David.SextonJr at ubs.com>  <
mailto:David.SextonJr at ubs.com <mailto:David.SextonJr at ubs.com> > > ] 
Sent: Thursday, July 31, 2003 12:41 PM 
To: 'NYPHP Talk' 
Subject: RE: [nycphp-talk] Simple form-based selection and 
cookie-setting/g etting 


...or require them to register/login, which would be more reliable since you



can store/retrieve the prefs server-side using sessions. Maybe you already 
have an existing login process, which would make it that much easier to 
implement. 


-----Original Message----- 
From: Rolan [ mailto:rolan at datawhorehouse.com
<mailto:rolan at datawhorehouse.com>  
< mailto:rolan at datawhorehouse.com <mailto:rolan at datawhorehouse.com> >  
< mailto:rolan at datawhorehouse.com <mailto:rolan at datawhorehouse.com>  <
mailto:rolan at datawhorehouse.com <mailto:rolan at datawhorehouse.com> > > ] 
Sent: Thursday, July 31, 2003 12:25 PM 
To: NYPHP Talk 
Subject: Re: [nycphp-talk] Simple form-based selection and 
cookie-setting/getting 


cookies. 
http://www.php.net/manual/en/features.cookies.php
<http://www.php.net/manual/en/features.cookies.php>  
< http://www.php.net/manual/en/features.cookies.php
<http://www.php.net/manual/en/features.cookies.php> >  
< http://www.php.net/manual/en/features.cookies.php
<http://www.php.net/manual/en/features.cookies.php>  
< http://www.php.net/manual/en/features.cookies.php
<http://www.php.net/manual/en/features.cookies.php> > >  

Robert Dumas wrote: 

> Hi all: 
> 
> I'm new to the list and I have a question. 
> 
> I'm building a streaming media player that opens in a pop-up (a 
> requested one, thank goodness) and I want to do it in PHP. Basically, 
> I want the user to select their preferred media player -- Real (ugh) 
> or WMP (double-ugh) -- and hit a link which saves their media player 
> preference and pops open the player.  Popping open the player is, of 
> course, no problem; but retrieving their preference is kind of sticky. 
> Does anyone know of a good example of a simple way to do this? 
> 
> Cheers 
> 
> Robert Dumas 
> 
>------------------------------------------------------------------------ 
> 
>_______________________________________________ 
>talk mailing list 
>talk at lists.nyphp.org 
> http://lists.nyphp.org/mailman/listinfo/talk
<http://lists.nyphp.org/mailman/listinfo/talk>  
< http://lists.nyphp.org/mailman/listinfo/talk
<http://lists.nyphp.org/mailman/listinfo/talk> >  
< http://lists.nyphp.org/mailman/listinfo/talk
<http://lists.nyphp.org/mailman/listinfo/talk>  
< http://lists.nyphp.org/mailman/listinfo/talk
<http://lists.nyphp.org/mailman/listinfo/talk> > >  



Please do not transmit orders or instructions regarding a UBS account by 
email. The information provided in this email or any attachments is not an 
official transaction confirmation or account statement. For your protection,


do not include account numbers, Social Security numbers, credit card 
numbers, passwords or other non-public information in your email. Because 
the information contained in this message may be privileged, confidential, 
proprietary or otherwise protected from disclosure, please notify us 
immediately by replying to this message and deleting it from your computer 
if you have received this communication in error.  Thank you. 

UBS Financial Services Inc. 
UBS International Inc. 

_______________________________________________ 
talk mailing list 
talk at lists.nyphp.org 
http://lists.nyphp.org/mailman/listinfo/talk
<http://lists.nyphp.org/mailman/listinfo/talk>  
< http://lists.nyphp.org/mailman/listinfo/talk
<http://lists.nyphp.org/mailman/listinfo/talk> >  



Please do not transmit orders or instructions regarding a UBS account by 
email. The information provided in this email or any attachments is not an 
official transaction confirmation or account statement. For your protection,

do not include account numbers, Social Security numbers, credit card 
numbers, passwords or other non-public information in your email. Because 
the information contained in this message may be privileged, confidential, 
proprietary or otherwise protected from disclosure, please notify us 
immediately by replying to this message and deleting it from your computer 
if you have received this communication in error.  Thank you. 

UBS Financial Services Inc. 
UBS International Inc. 

_______________________________________________ 
talk mailing list 
talk at lists.nyphp.org 
http://lists.nyphp.org/mailman/listinfo/talk
<http://lists.nyphp.org/mailman/listinfo/talk>  



Please do not transmit orders or instructions regarding a UBS account by
email. The information provided in this email or any attachments is not an
official transaction confirmation or account statement. For your protection,
do not include account numbers, Social Security numbers, credit card
numbers, passwords or other non-public information in your email. Because
the information contained in this message may be privileged, confidential,
proprietary or otherwise protected from disclosure, please notify us
immediately by replying to this message and deleting it from your computer
if you have received this communication in error.  Thank you.

UBS Financial Services Inc.
UBS International Inc.




More information about the talk mailing list