Re: Newbie question
| From: | Michael Lewis | Date: | Fri, 02 May 2003 05:36:42 +0000 |
| Subject: | Re: Newbie question | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-146062@lists.php.net to get a copy of this message | ||
Thanks for your help Justin. Right now, I just created a test page to
see if I could set a cookie in PHP. I had to do it before the <html>
tag though. The code I used was <?php setcookie('NoFrames',
'12765342'); ?>
I was, however, reading about being able to pass additional values after
the initial header is passed using output buffering ie: ob_start(); .
The example they gave was:
<?php
// send a header
header ("Pragma: no-cache");
// send some output
print "Welcome to the Matrix, Neo";
// send another header
// this will generate an error
header ("Content-Type: text/html");
?>
This will produce an error because you're sending a header
twice. But, if you use the following code it is supposed to work:
<?php
// start buffering the output
ob_start();
// send a header
header ("Pragma: no-cache");
// print some output
print "Welcome to the Matrix, Neo";
// send another header
// in this case, since the output is being stored in a buffer
// and not being printed, no error will be generated
header ("Content-Type: text/html");
// print the contents of the buffer
ob_end_flush();
?>
Do you think this could be used, to possibly set a cookie
inside <noframes>?? It looks like it has possibilities,
but like I said, I'm a newbie
u, 2003-05-01 at 20:39, Justin French wrote:
> This simple test works for me, and could be easily transferred to what
> you're doing (assuming PHP >= 4.1.0):
>
> <?
> setcookie("noFrames", 1);
> if($_COOKIE['noFrames'])
> {
> echo "these are my links";
> }
> else
> {
> // no need for links
> }
> ?>
>
> So, I guess you need to show us your set cookie code, and even manually
> confirm you ARE setting a cookie, and then bug track it down from there.
>
> Are you setting it with PHP (which you can't do inside a <noframes> tag) or
> with javascript?
>
>
> Justin French
>
>
>
>
>
>
>
>
> on 02/05/03 12:54 PM, Michael Lewis (michael@nichestaffing.com) wrote:
>
> > On Thu, 2003-05-01 at 18:56, Justin French wrote:
> >> on 02/05/03 11:36 AM, Michael Lewis (michael@nichestaffing.com) wrote:
> >>
> >> 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
> >
> > The code for the browser test that I mentioned works as is. The problem
> > I'm having is testing for cookies. I am doing a new site for my church
> > and I'm using frames. I wanted to see if I could set a cookie inside
> > the <noframe> tag that I could test for on all the other pages to
> > determine if I should display page links or not. In the framesets, all
> > of the links are in the header and footer frames. If a user is not in
> > frames, I want to display the links on the individual pages so they can
> > navigate, but hide them if they are in frames. I tested your suggestion
> > and it didn't error, but hides the links even if the cookie is set. The
> > code is below.
> >
> > <?
> > if (isset($NoFrames))
> > {
> > ?>
> >
> > <tr>
> > <td valign="top" align="center"> </td>
> > </tr>
> > <tr>
> > <td valign="middle" align="center">
> > <font face="verdana,helvetica,arial,sans-serif"
> > color="#cccccf"size="2"><b>
> > <a href="main.php">Home Page</a> |
> > <a href="believe.html">Who We Are</a> |
> > <a href="coffee.html">Coffee
> > House</a> |
> > <a href="community.html">Outreaches</a><br><img
> > src="trans.gif"
> > width="200"
> > height="3"><br>
> > <a href="house.html">House
> > Ministry</a> |
> > <a href="calendar.html">Calendar</a> |
> > <a href="getSaved.html">Get Saved</a> |
> > <a href="index.html">Saturday Night Church</a>
> > </b></font></td>
> > </tr>
> > <?
> > }
> > ?>
> >
> >
> >>
> >
--
Michael Lewis <michael@nichestaffing.com>
NicheStaffing.com