Re: [PHP] Re: setting cookie doesn't work

2009-08-03 Thread Ashley Sheridan
On Mon, 2009-08-03 at 20:44 +0200, Grega Leskovsek wrote:
> I made two files now of the program: (the main one and the one where I
> set the cookie and open pdf)and I noticed that it doesn't work setting
> the cookie the first time I call the file where I set the cookie but
> only after the second header  redirection.
> How do I refresh the page in php?
> 
> Thanks in advance, Grega from Slovenia
> 
> 2009/8/3 Grega Leskovsek :
> > And here is the objective:
> > Alter your Acme, Inc. download interface from the previous lesson(I
> > had to not to allow users on computers straing IP with 202 and allow
> > only IE for Win and FF for Mac to download file) so that each user
> > must register her email address in order to download the file. Use
> > cookies to detect whether the user has already registered, and to
> > ensure that the user downloads the file only once within 7 days of
> > registering.
> >
> > As always, validate the forms, comment your code, and explain your results!
> >
> >
> > 2009/8/3 Grega Leskovsek :
> >> Here is one of my final objectives at PHP introductory course ot
> >> O'Reilly. The strange thing that setting a cookie in that program
> >> les13uadownload.php doesn't work. I don't have a clue - sometimes in
> >> other programs when I run them they set cookies and sometimes not. To
> >> see the full functionality of this "program" I had to set cookie
> >> sevendays in another program. Please check where is my bug. Thanks in
> >> advance, Grega from Slovenia
> >>
> >>  >> if (!empty($_GET['delete_cookie'])) {
> >>   setcookie("sevendays", "", time()-3600); //delete the cookie to
> >> allow to download the file more than 1x in 7days as another user
> >> }
> >>
> >> if 
> >> (isset($_POST['check'])AND(isset($_POST['email']))AND(empty($_COOKIE["sevendays"])))
> >> {#user clicked form download button
> >>  $email = $_POST['email'];
> >>  setcookie("sevendays", "email", time()+60*60*24*7);
> >>  $filepath = $_SERVER['DOCUMENT_ROOT']."/.php_files/acme_brochure.pdf";
> >>  if (file_exists($filepath)) {
> >> header("Content-Type: application/force-download");
> >> header("Content-Disposition:filename=\"brochure.pdf\"");
> >> $fd = fopen($filepath,'rb');
> >> fpassthru($fd);
> >> fclose($fd);
> >>  }
> >> }#isset(check)
> >> ?>
> >> 
> >>function setcolor(backgcolor,color) {
> >>document.getElementById("file").style.color=color;
> >>document.getElementById("file").style.background=backgcolor;
> >>}
> >>
> >>  function setStyle(x) {
> >>document.getElementById(x).style.background="yellow";
> >>  }
> >>  function unSetStyle(x) {
> >>document.getElementById(x).style.background="white";
> >>  }
> >>
> >>function isFormValid (formToCheck) {
> >>retVal = true;
> >>
> >>if (
> >> (formToCheck.email.value).search(/^[\w!#$%&\'*+\/=?^`{|}~.-]+@(?:[a-z\d][a-z\d-]*(?:\.[a-z\d][a-z\d-]*)?)+\.(?:[a-z][a-z\d-]+)$/i)
> >> == -1 )
> >>{
> >>element = document.getElementById ("new1Label");
> >>element.style.color = "red";
> >>element.style.fontWeight = "bold";
> >>retVal = false;
> >>retEmVal = false;
> >>}
> >>else
> >>{
> >>element = document.getElementById ("new1Label");
> >>element.style.color = "black";
> >>element.style.fontWeight = "normal";
> >>retEmVal = true;
> >>
> >>}
> >>
> >>if (formToCheck.downloaded.value=='no') {
> >>ret7daysVal = true;
> >>}else {
> >>ret7daysVal = false;
> >>}
> >>
> >>if (!retEmVal)
> >>{
> >>alert ("Please enter a valid e-mail address!");
> >>retVal = false;
> >>}else if (!ret7daysVal)
> >>{
> >>alert ("You can download the file only once in
> >> seven days!");
> >>retVal = false;
> >>}
> >>
> >>return retVal;
> >>
> >>}
> >> 
> >>  > //You dont need this line>
> > require($_SERVER['DOCUMENT_ROOT']."/template_top.inc");
> >> $ua = $_SERVER['HTTP_USER_AGENT']."";
> >> if (preg_match("/Macintosh/",$ua)) {
> >>  if (!preg_match("/Firefox/",$ua)) {
> >>echo "For Macintosh You need to use Firefox!  >> href=\"http://www.apple.com/downloads/macosx/internet_utilities/mozillafirefox.html\";>Download
> >> here ...";
> >>exit();
> >>  }
> >> }
> >> if (preg_match("/Windows/",$ua)) {
> >>  if (!preg_match("/MSIE/",$ua)) {
> >>echo "For Windows You need to use Internet Explorer!";
> >>exit();
> >>  }
> >> }
> >> $ip = $_SERVER['REMOTE_ADDR'];
> >> $ipCheck = substr($ip,0,3);
> >> if ($ipCheck == "202") {echo "I don't trust Y

[PHP] Re: setting cookie doesn't work

2009-08-03 Thread Grega Leskovsek
I made two files now of the program: (the main one and the one where I
set the cookie and open pdf)and I noticed that it doesn't work setting
the cookie the first time I call the file where I set the cookie but
only after the second header  redirection.
How do I refresh the page in php?

Thanks in advance, Grega from Slovenia

2009/8/3 Grega Leskovsek :
> And here is the objective:
> Alter your Acme, Inc. download interface from the previous lesson(I
> had to not to allow users on computers straing IP with 202 and allow
> only IE for Win and FF for Mac to download file) so that each user
> must register her email address in order to download the file. Use
> cookies to detect whether the user has already registered, and to
> ensure that the user downloads the file only once within 7 days of
> registering.
>
> As always, validate the forms, comment your code, and explain your results!
>
>
> 2009/8/3 Grega Leskovsek :
>> Here is one of my final objectives at PHP introductory course ot
>> O'Reilly. The strange thing that setting a cookie in that program
>> les13uadownload.php doesn't work. I don't have a clue - sometimes in
>> other programs when I run them they set cookies and sometimes not. To
>> see the full functionality of this "program" I had to set cookie
>> sevendays in another program. Please check where is my bug. Thanks in
>> advance, Grega from Slovenia
>>
>> > if (!empty($_GET['delete_cookie'])) {
>>   setcookie("sevendays", "", time()-3600); //delete the cookie to
>> allow to download the file more than 1x in 7days as another user
>> }
>>
>> if 
>> (isset($_POST['check'])AND(isset($_POST['email']))AND(empty($_COOKIE["sevendays"])))
>> {#user clicked form download button
>>  $email = $_POST['email'];
>>  setcookie("sevendays", "email", time()+60*60*24*7);
>>  $filepath = $_SERVER['DOCUMENT_ROOT']."/.php_files/acme_brochure.pdf";
>>  if (file_exists($filepath)) {
>>     header("Content-Type: application/force-download");
>>     header("Content-Disposition:filename=\"brochure.pdf\"");
>>     $fd = fopen($filepath,'rb');
>>     fpassthru($fd);
>>     fclose($fd);
>>  }
>> }#isset(check)
>> ?>
>> 
>>        function setcolor(backgcolor,color) {
>>                document.getElementById("file").style.color=color;
>>                document.getElementById("file").style.background=backgcolor;
>>        }
>>
>>  function setStyle(x) {
>>        document.getElementById(x).style.background="yellow";
>>  }
>>  function unSetStyle(x) {
>>        document.getElementById(x).style.background="white";
>>  }
>>
>>            function isFormValid (formToCheck) {
>>                retVal = true;
>>
>>                if (
>> (formToCheck.email.value).search(/^[\w!#$%&\'*+\/=?^`{|}~.-]+@(?:[a-z\d][a-z\d-]*(?:\.[a-z\d][a-z\d-]*)?)+\.(?:[a-z][a-z\d-]+)$/i)
>> == -1 )
>>                {
>>                    element = document.getElementById ("new1Label");
>>                    element.style.color = "red";
>>                    element.style.fontWeight = "bold";
>>                    retVal = false;
>>                    retEmVal = false;
>>                }
>>                else
>>                {
>>                    element = document.getElementById ("new1Label");
>>                    element.style.color = "black";
>>                    element.style.fontWeight = "normal";
>>                    retEmVal = true;
>>
>>                }
>>
>>                if (formToCheck.downloaded.value=='no') {
>>                    ret7daysVal = true;
>>                }else {
>>                    ret7daysVal = false;
>>                }
>>
>>                if (!retEmVal)
>>                {
>>                    alert ("Please enter a valid e-mail address!");
>>                    retVal = false;
>>                }else if (!ret7daysVal)
>>                {
>>                    alert ("You can download the file only once in
>> seven days!");
>>                    retVal = false;
>>                }
>>
>>                return retVal;
>>
>>            }
>> 
>>  //You dont need this line>
> require($_SERVER['DOCUMENT_ROOT']."/template_top.inc");
>> $ua = $_SERVER['HTTP_USER_AGENT']."";
>> if (preg_match("/Macintosh/",$ua)) {
>>  if (!preg_match("/Firefox/",$ua)) {
>>    echo "For Macintosh You need to use Firefox! > href=\"http://www.apple.com/downloads/macosx/internet_utilities/mozillafirefox.html\";>Download
>> here ...";
>>    exit();
>>  }
>> }
>> if (preg_match("/Windows/",$ua)) {
>>  if (!preg_match("/MSIE/",$ua)) {
>>    echo "For Windows You need to use Internet Explorer!";
>>    exit();
>>  }
>> }
>> $ip = $_SERVER['REMOTE_ADDR'];
>> $ipCheck = substr($ip,0,3);
>> if ($ipCheck == "202") {echo "I don't trust You."; exit();}
>> ?>
>> > if (!empty($_COOKIE["sevendays"])) echo "IN SEVEN
>> ".$_COOKIE["sevendays"]." DAYS!!!";
>> if ($_COOKIE["sevendays"]) {
>>  echo $_COOKIE["sevendays"];
>>  ?>
>>  Not my email: > $_COOKIE["sevendays"]; ?>?
>>  > }else {
>>  ?>
>>  
>>  Enter Your e-mail: > size="25" name="email" value="

[PHP] Re: setting cookie doesn't work

2009-08-03 Thread Grega Leskovsek
And here is the objective:
Alter your Acme, Inc. download interface from the previous lesson(I
had to not to allow users on computers straing IP with 202 and allow
only IE for Win and FF for Mac to download file) so that each user
must register her email address in order to download the file. Use
cookies to detect whether the user has already registered, and to
ensure that the user downloads the file only once within 7 days of
registering.

As always, validate the forms, comment your code, and explain your results!


2009/8/3 Grega Leskovsek :
> Here is one of my final objectives at PHP introductory course ot
> O'Reilly. The strange thing that setting a cookie in that program
> les13uadownload.php doesn't work. I don't have a clue - sometimes in
> other programs when I run them they set cookies and sometimes not. To
> see the full functionality of this "program" I had to set cookie
> sevendays in another program. Please check where is my bug. Thanks in
> advance, Grega from Slovenia
>
>  if (!empty($_GET['delete_cookie'])) {
>   setcookie("sevendays", "", time()-3600); //delete the cookie to
> allow to download the file more than 1x in 7days as another user
> }
>
> if 
> (isset($_POST['check'])AND(isset($_POST['email']))AND(empty($_COOKIE["sevendays"])))
> {#user clicked form download button
>  $email = $_POST['email'];
>  setcookie("sevendays", "email", time()+60*60*24*7);
>  $filepath = $_SERVER['DOCUMENT_ROOT']."/.php_files/acme_brochure.pdf";
>  if (file_exists($filepath)) {
>     header("Content-Type: application/force-download");
>     header("Content-Disposition:filename=\"brochure.pdf\"");
>     $fd = fopen($filepath,'rb');
>     fpassthru($fd);
>     fclose($fd);
>  }
> }#isset(check)
> ?>
> 
>        function setcolor(backgcolor,color) {
>                document.getElementById("file").style.color=color;
>                document.getElementById("file").style.background=backgcolor;
>        }
>
>  function setStyle(x) {
>        document.getElementById(x).style.background="yellow";
>  }
>  function unSetStyle(x) {
>        document.getElementById(x).style.background="white";
>  }
>
>            function isFormValid (formToCheck) {
>                retVal = true;
>
>                if (
> (formToCheck.email.value).search(/^[\w!#$%&\'*+\/=?^`{|}~.-]+@(?:[a-z\d][a-z\d-]*(?:\.[a-z\d][a-z\d-]*)?)+\.(?:[a-z][a-z\d-]+)$/i)
> == -1 )
>                {
>                    element = document.getElementById ("new1Label");
>                    element.style.color = "red";
>                    element.style.fontWeight = "bold";
>                    retVal = false;
>                    retEmVal = false;
>                }
>                else
>                {
>                    element = document.getElementById ("new1Label");
>                    element.style.color = "black";
>                    element.style.fontWeight = "normal";
>                    retEmVal = true;
>
>                }
>
>                if (formToCheck.downloaded.value=='no') {
>                    ret7daysVal = true;
>                }else {
>                    ret7daysVal = false;
>                }
>
>                if (!retEmVal)
>                {
>                    alert ("Please enter a valid e-mail address!");
>                    retVal = false;
>                }else if (!ret7daysVal)
>                {
>                    alert ("You can download the file only once in
> seven days!");
>                    retVal = false;
>                }
>
>                return retVal;
>
>            }
> 
> 
require($_SERVER['DOCUMENT_ROOT']."/template_top.inc");
> $ua = $_SERVER['HTTP_USER_AGENT']."";
> if (preg_match("/Macintosh/",$ua)) {
>  if (!preg_match("/Firefox/",$ua)) {
>    echo "For Macintosh You need to use Firefox!  href=\"http://www.apple.com/downloads/macosx/internet_utilities/mozillafirefox.html\";>Download
> here ...";
>    exit();
>  }
> }
> if (preg_match("/Windows/",$ua)) {
>  if (!preg_match("/MSIE/",$ua)) {
>    echo "For Windows You need to use Internet Explorer!";
>    exit();
>  }
> }
> $ip = $_SERVER['REMOTE_ADDR'];
> $ipCheck = substr($ip,0,3);
> if ($ipCheck == "202") {echo "I don't trust You."; exit();}
> ?>
>  if (!empty($_COOKIE["sevendays"])) echo "IN SEVEN
> ".$_COOKIE["sevendays"]." DAYS!!!";
> if ($_COOKIE["sevendays"]) {
>  echo $_COOKIE["sevendays"];
>  ?>
>  Not my email:  $_COOKIE["sevendays"]; ?>?
>   }else {
>  ?>
>  
>  Enter Your e-mail:  size="25" name="email" value="">
>   />
>  
>   "no"; ?>"/>
>  
>   }
//You dont need this line>
require($_SERVER['DOCUMENT_ROOT']."/template_bottom.inc");
> print_r($_COOKIE);
> echo "XX".$_COOKIE["sevendays"]."XX";
> ?>
>
>
> --
> When the sun rises I receive and when it sets I forgive ->
> http://users.skavt.net/~gleskovs/
> All the Love, Grega Leskov'sek
>



-- 
When the sun rises I receive and when it sets I forgive ->
http://users.skavt.net/~gleskovs/
All the Love, Grega Leskov'sek

--
PHP General Mailing List (http://www.php.net/)
To unsubscri