Setting a cookie needs to happen before any content is output, so
cookiesetter.php needs to be included before the <html> tag.

Hope this helps

On Sun, 18 Oct 2020, 21:06 Chiefo Azubike De-Lord Zuwi, <
[email protected]> wrote:

> I created an issue for this problem with the link
> https://issuetracker.google.com/issues/166921075
> My cookies are not being created and google marked this as bug for 2
> months now no result. LET ME RECAP THE QUESTION HERE
>
> ISSUE BELOW:
> I am using php72 runtime on app engine. Now, after my website is up and
> running, I noticed that my cookies are not being created, after close
> inspection via gcloud logs read, I found out that header were already sent
> out, so I could not create or remove cookies from any page on my website
> only via front controller.
>
> After multiple tests, I added setcookie on my front controller and the
> cookie creates successfully, but that is not what I want, I want to be able
> to create cookies on whatever pages I desire.
>
> What I expected to happen:
>  I expected the cookies to be created when the page loads not front
> controller creating my cookies for me.
>
> Steps to reproduce:
>   - Write a PHP website maybe one page
>   - Host on google app engine php runtime 72 stated on app.yaml file
>   - Deploy via app.yaml file.
>   - Add setcookie code on website page.
>
> Other information: ASKED QUESTIONS on stackoverflow
>
> This are questions i asked on stack overflow
>
> https://stackoverflow.com/questions/63586479/cookie-not-storing-on-users-browser-php-7-google-app-engine-gae
> <https://www.google.com/url?q=https://stackoverflow.com/questions/63586479/cookie-not-storing-on-users-browser-php-7-google-app-engine-gae&sa=D&usg=AFQjCNE6nOtQo3QaMWwPsQsE0i1BQMa5qg>
>  AND
>
> https://stackoverflow.com/questions/63616342/cannot-set-cookie-in-php-7-after-migrating-from-godaddy-to-google-app-engine-co
> <https://www.google.com/url?q=https://stackoverflow.com/questions/63616342/cannot-set-cookie-in-php-7-after-migrating-from-godaddy-to-google-app-engine-co&sa=D&usg=AFQjCNFQXjqPy4Tg3gcR7CRbIrzhUmWRoA>
>
>
>
> This is my code recreation.
>
> app.yaml file
>
>      runtime: php72
>      runtime_config:
>      document_root:
>
>      handlers:
>
>     - url: /.*
>        script: auto
>        secure: always
>        redirect_http_response_code: 301
>
>     entrypoint:
>        serve worker.php
>
>
> worker.php //THIS WORKER.PHP below is the only place that allows the
> creation of cookie for me, I do  not want to be able to create cookie here
> only. I want it on any page I wish to create it on.
>
>           <?php
>           ini_set('allow_url_fopen',1);
> [IF I INCLUDE cookiesetter.php here it works perfectly]
>          $path = @parse_url($_SERVER['REQUEST_URI'])['path'];
>          switch ($path){
>          case '/':
>             require 'index.php';
>             break;
>          case '/index':
>             require 'index.php';
>             break;
>          case '/index.php':
>             require 'index.php';
>             break;
>          case '/about':
>             require 'about.php';
>             break;
>          case '/about.php':
>             require 'about.php';
>             break;
>          case '/contact':
>             require 'contact.php';
>             break;
>          case '/contact.php':
>             require 'contact.php';
>             break;
>         case '/privacy':
>             require 'privacy.php';
>             break;
>         case '/privacy.php':
>             require 'privacy.php';
>             break;
>         case '/product-listing/':
>             require __DIR__.'/product-listing.php';
>             break;
>         case   (preg_match('/product-listing.*/', $path) ? true : false) :
>             require __DIR__.'/product-listing.php';
>             break;
>         case '/404':
>             require '404.php';
>             break;
>         case '/404.php':
>             require '404.php';
>             break;
>         default:
>             http_response_code(404);
>             header("Location: https://www.sharyor.com/404
> <https://www.google.com/url?q=https://www.sharyor.com/404&sa=D&usg=AFQjCNEMideAuyelQfSgrKAavLybMK7veA>
> ");
>             exit();
>         }
>         ?>
>
>
> code i use to setcookie on my site it is saved o cookiesetter.php file and
> included on every page.
>         <?php
>         if (isset($_COOKIE['sharyor_tra'])){
>         } else {
>         setcookie('sharyor_tra', $transactionid, time() + (3000 * 24 * 60
> * 60), "/");
>         @$trackingcodecookie = $_COOKIE['sharyor_tra'];
>         }
>          ?>
>
>
> index.php
>         <html>
>         <head>
>         <title>Home page</title>
>         <?php
>          include "cookiesetter.php"; //refer to the code above where I
> said this code is used to create cookie referenced on cookiesetter.php
>          ?>
>         </head>
>          <body>
>          <h1>Home page</h1>
>          </body>
>          </html>
>
> about.php
>         <html>
>         <head>
>         <title>About page</title>
>         <?php
>          include "cookiesetter.php"; //refer to the code above where I
> said this code is used to create cookie referenced on cookiesetter.php
>          ?>
>         </head>
>          <body>
>          <h1>About page</h1>
>          </body>
>          </html>
>
>
> privacy.php
>         <html>
>         <head>
>         <title>Privacy page</title>
>         <?php
>          include "cookiesetter.php"; //refer to the code above where I
> said this code is used to create cookie referenced on cookiesetter.php
>          ?>
>         </head>
>          <body>
>          <h1>Privacy page</h1>
>          </body>
>          </html>
>
>
> contact.php
>         <html>
>         <head>
>         <title>Contact page</title>
>         <?php
>          include "cookiesetter.php"; //refer to the code above where I
> said this code is used to create cookie referenced on cookiesetter.php
>          ?>
>         </head>
>          <body>
>          <h1>Contact page</h1>
>          </body>
>          </html>
>
> product-listing.php     //I USE REQUEST URI in product listing because GET
> parameter is not passing I asked a question on stack overflow too
>         <html>
>         <head>
>         <title>Product listing page</title>
>         <?php
>          include "cookiesetter.php"; //refer to the code above where I
> said this code is used to create cookie referenced on cookiesetter.php
>          ?>
>         </head>
>          <body>
>          <h1>Product listing page</h1>
>          <p>
>          echo $hi = $_SERVER["REQUEST_URI"];
>          </p>
>          </body>
>          </html>
>
>
> 404.php
>         <html>
>         <head>
>         <title>404 error page</title>
>         <?php
>          include "cookiesetter.php"; //refer to the code above where I
> said this code is used to create cookie referenced on cookiesetter.php
>          ?>
>         </head>
>          <body>
>          <h1>404 error page</h1>
>          </body>
>          </html>
>
>
>
> --
> You received this message because you are subscribed to the Google Groups
> "Google App Engine" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/google-appengine/cced8183-e9bc-4f18-89c6-08e643afbc02n%40googlegroups.com
> <https://groups.google.com/d/msgid/google-appengine/cced8183-e9bc-4f18-89c6-08e643afbc02n%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
>

-- 
You received this message because you are subscribed to the Google Groups 
"Google App Engine" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/google-appengine/CAKneeSGsU2rnaXM1KkB57pYiwOCQxJuQC31LHgRNFCCCh8EmMw%40mail.gmail.com.

Reply via email to