More cookie problems, php

I'm sorry to keep asking stupid questions, but I have tried to research this and couldn't find it.

This time, I want to be able to check a _POST against an array, before deciding it's ok to set the cookie. Here's my snippet.

<?php header( 'Location: http://www.site.com/ler.php' ) ; ?> <?php setcookie("choice1","true",time()+20); ?> <?php $match_id = strtoupper($_POST["arr"]); //var_dump(implode($_POST)); $bArray = array( "A"=>"1", "B"=>"2", "C"=>"3", "D"=>"4", "ETC"=>"5");

I need the array and variable to be set before the cookie, because I want to use array_key_exists conditional. I tried switching the order but that didn't do anything. I know it's not the header because the other code with cookies and headers works fine. Any ideas??

-------------Problems Reply------------

Not sure what you're asking here, but its clear that the code you've presented is probably not going to work as you expect.

You're outputting body content before the call to setcookie(). So unless you've got output buffering enabled it's going to fail. Setting an expiry time of 20 seconds is a dumb idea too - client side clock is unlikely to be synchronised.

Also there are several browsers which ignore all subsequent headers after a redirect. Further, depending on the timing of processing, some browsers will drop the connection after a redirect - in the absence of an ignore_user_abort() this may cause premature termination of the code.

Further, presumably there's a reason for parsing the data / setting a cookie - how can you be sure this has completed before the redirect request from the browser is procesed?

I want to be able to check a _POST against an array, before deciding it's ok to set the cookie

Its apparent that the code you've provided does not check anything before setting the cookie - why have you included it in your question?

check if the post array variable is set or not.

if(isset($_POST['arr']))
{
if(in_array("value", $bArray)
{
setcookie("choice1","true",time()+20);
}
}

Category:php Views:0 Time:2012-01-23

Related post

  • Android WebView Cookie Problem 2009-10-30

    I have a server that sends my android app a session cookie to be used for authenticated communication. I am trying to load a WebView with a URL pointing to that same server and I'm trying to pass in the session cookie for authentication. I am observi

  • ie complicated subdomain cookie problem 2009-12-22

    all my cookies work great on subdomain, but if subdomain has "_" in it, then cookie dont get read at all and dont get right at all eaither. following are my tested result, which will self explain justlife.demo.com *** works fine *** just-life.demo.co

  • weird MVC2 Cookies problem 2010-11-19

    I am having a cookie problem in the below example. the cookie does get created and when i put a debug point after its creation i can check whats in the cookie with a watch. however, when i restart the website, the cookie is still there, but has becom

  • Safari's annoying cookie problem. How do I work around it effectively? 2011-03-03

    In case you dont know what safari's cookie problem, here's are a link to it: Safari doesn't set Cookie but IE / FF does.. I got some problem with it. Compared to the answer in the link I have a user-login cookies set with user-id and hash. In the log

  • Perl WWW::Mechanize cookie problem 2011-08-12

    I am trying to automate the collection of links from a site that asks for a captcha first. For this, I capture the captcha image so it can be solved externally, and then submit the solution as part of the form fields. Somehow it doesn't work. I suspe

  • Many rpsec tests with test_sign_in fail after upgrading to Rails 3.1, maybe a cookie problem? 2011-09-21

    I have upgraded to Rails 3.1 and everything seems to work fine. But the tests (RSpec) fail anyhow, e.g. the following one: describe "for admin user" do before(:each) do @city = Factory(:city) @user = Factory(:user) @business = Factory(:business, :use

  • Cache / cookies problem with IE9: website not refreshing content 2012-06-27

    original title: Cache / cookies problem with IE9 Hi, I've been having issues with website not refreshing content. The particular offenders have been forum.sonicwall.com, and sometimes lifehacker.com. I've tried setting the "check everyime I visit thi

  • Cookie Problem with the website delicious 2012-08-25

    I sent the following email to delicious support staff: "My delicious account is signing out while I have the website open even though I have the stay signed in boxed ticket. I have tried the suggestion in FAQ about re-setting cookies and have also ad

  • Cookie Problem: Windows Live Messenger log-in lasts for one day only or less 2013-04-30

    Moderators at the Hotmail, Messenger, and SkyDrive group first suggested I do a Windows Essentials repair. Then when that failed they suggested I do an uninstall, download, and install. When that also failed they suggested I get in touch with you. I

  • Window 7 & IE8 Cookie problems. It will not accept logon to my works exchange web site for private connection (e.g. using the cookie). 2013-11-12

    Original title: Window 7 & IE8 Cookie problems. I just purchased a new laptop with Windows 7 & IE8. It will not accept logon to my works exchange web site for private connection (e.g. using the cookie). I also had problems with cookies on oth

  • trouble posting on Craig's List, suspect cookie problem 2014-12-17

    I have posted on craigs list before, but now for some reason when I get past text entuy for item to be sold and get to the (enter WORD or WORDS in box below prompt, the code words do not appear and the box does not appear A continue box does appear b

  • Cookie problems with virtual directories in IIS (deleting unwanted cookies) 2008-11-21

    I've just had a small nightmare with unwanted cookies somehow being created. I swear my code never created a cookie in a certain virtual directory, it just read it, but somehow my browser ended up with a root cookie and a copy of this cookie for the

  • Cookie Problem in Python 2009-01-16

    I'm working on a simple HTML scraper for Hulu in python 2.6 and am having problems with logging on to my account. Here's my code so far: import urllib import urllib2 from cookielib import CookieJar #make a cookie and redirect handlers cookies = Cooki

  • Strange Javascript/cross site cookies problem 2009-07-23

    I've got a PHP script running on domain B that, when called generates some JS. The idea is that in a given html page I can have: <script src="http://b.domain/myscript.php"></script> So when the page loads, the script is called and the JS

  • PHP cookies problem, works in Firefox not in other browser 2009-07-31

    I've a problem with setting cookies in php. I've to say that I'm not very experienced with php, so maybe is a very stupid problem. I've an ajax rating system that should check a cookie to see if the the photo has already been voted. The page called w

  • PHP Session/Cookie problems with Windows XP, Vista, IE and certain users 2009-08-10

    I've mentioned it on here before, but still have the problem, so have added some extra info :) We have a local intranet site that everyone on the network uses, maybe 5% (or even less) of the users that use the site have problems where the session isn

  • IE7 problem - session and cookie problem 2009-09-08

    I have one problem with IE7. Let me explain the scenario I have opened my web based application in IE7 browser in TAB1 by using normal login feature. After successful login, i entered to the application home page and i do with my normal transaction s

  • Php: Why is this code not working? Is it cookies problem? 2009-10-22

    I wrote some code to manage my wordpress mu website, but it seems to not work... It uses libcurl and is supposed to login and create new blog. After i load this script in my browser it only logs me in but no new blog is created and all urls on wp-adm

  • Custom Model-Binder that pulls from a cookie problem? 2010-02-04

    I am trying to do the following. Use the default model binder to bind an object from query string values. If that fails, I then try and bind the object from cookie values. However I am using dataannotations on this object and I am having the followin

  • Cross Domain Cookies Problem (ASP.NET) 2010-04-26

    i have a problem with cross-domain cookies. I read a lot of documentation about sharing cookies between subdomains. The main idea of all articles is set Domain property to something like ".mydomain.com". I've created two domains on local IIS server -

Copyright (C) dskims.com, All Rights Reserved.

processed in 0.254 (s). 11 q(s)