Re: Newbie question

From: Date: Fri, 02 May 2003 00:56:18 +0000
Subject: Re: Newbie question
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-146036@lists.php.net to get a copy of this message
on 02/05/03 11:36 AM, Michael Lewis (michael@nichestaffing.com) wrote: > PHP - <?php if (stristr($_SERVER['HTTP_USER_AGENT'],'MSIE')) : ?> > MSIE code > <?php elseif (stristr($_SERVER['HTTP_USER_AGENT'],'Mozilla/5')) : ?> > Mozilla/5 code > <?php elseif (stristr($_SERVER['HTTP_USER_AGENT'],'Mozilla/4')) : ?> > Mozilla/4 code > <?php else: ?> > Generic code > <?php endif; ?> Try this: <? if (stristr($_SERVER['HTTP_USER_AGENT'],'MSIE')) { ?> MSIE CODE <? } elseif (stristr($_SERVER['HTTP_USER_AGENT'],'Mozilla/5')) { ?> Mozilla/5 code <? } elseif (stristr($_SERVER['HTTP_USER_AGENT'],'Mozilla/4')) { ?> Mozilla/4 code <? } else { ?> Generic Code <? } ?> In other words, the PHP syntax is: <? if(...) { ... } elseif(...) { ... } else { ... } ?> ... and all you're doing is escaping in and out of PHP to avoid echo'ing everything. Justin French > One question I have is, how do you test for a property or a cookie? > In DTML it would be: > <dtml-call "REQUEST.has_key('property or cookie')"> > Enter block of code > <dtml-else> > Enter another block of code > </dtml-if> > Is ther a way to do this in PHP without having to echo each line? I've > tried <?php if (isset[property or cookie]) ; ?> > Enter Block of Code > <?php endif; ?> > But that errors out. > > Another question I have is can a cookie be set within the HTML and how > would I do it? In DTML you can set them anywhere within the document you > want: > <dtml-call "RESPONSE.setCookie(cookieName, 'value', > path='/')"> > > I have figured out how to set cookies in PHP but only before the html > starts, otherwise I get an error. > <?php setcookie('testCookie', 'value','path'); ?> > > Any help, suggestions or pointers would be appreciated. > > Michael

« previous php.general (#146036) next »