Both examples should work fine if your WordPress site is running on https://.
However, I would recommend you set up the cookies by using available constants and functions provided by WordPress, it makes things more organized. See example below:
setcookie( 'lat', sanitize_text_field( $_POST['lat'] ), strtotime( '+14 days' ), "https://wordpress.stackexchange.com/", esc_COOKIE_DOMAIN, is_ssl(), true );
Notice that I’m using is_ssl to check whether the site is running on https or not. This should work fine.
Also, don’t insert any data coming from your web server environment without filtering it, always secure yourself.
Related Posts:
- How to set custom cookies before output
- How to stop loading multiple copies of jquery
- Creating a WordPress form with a PHP script and default header
- Why isn’t my if/elseif/else working correctly here?
- StudioPress: add meta tag to every page [closed]
- Add custom HTML to posts page
- Using PHP to toggle stylesheet and header image, set in cookie
- Mysterious HTTP 404 header in my own scripts
- Change logo based on incoming domain
- Echo URL of large version of Featured Image
- Conditional Header in wordpress
- add_image_size for header_image
- Responsive Header for Phone
- My php header() function is not working [closed]
- “imagejpeg” function is not working in wordpress
- wp-comments-post.php file returns a blank page
- Insert custom PHP head above in WP pages
- Headers already sent in Pluggable.php / homepage and wp-login error
- Is_front_page inside header.php is always returning true
- Does wordpress templates always in files or in database?
- Adding Meta Tags to a Post using its Tags, Excerpt and content
- Moving code from theme header to functions.php
- WordPress wp_redirect error
- Having Issue on Redirecting With Session in WordPress
- linking stylesheets and scripts with functions.php
- Location of core code for database connection and get_header
- Clickable image link sends people to wrong URL
- unknown issue in ‘header.php’ preventing theme from displaying fully
- How can I use a sliced image As banner? [closed]
- Add meta tags to a custom header
- Is this a correct usage of ob_start() in my WordPress project?
- Change header on pages displaying taxonomy items
- Custom CSV exporter – Cannot modify header information – headers
- How to add Post Tags to a new element in header.php?
- setcookies and header send
- How to internationalize header image?
- Custom functions for string data calculations
- How do you remove header sitewide from mobile only?
- WP_REST_Response – How to return Gzip answer and add Content-encoding header?
- How do I use an iFrame for my header in WordPress twenty seventeen?
- WordPress can’t use ZipArchive
- Reliable way to add nonce to HTTP Header in WordPress?
- How to remove get_header From all single pages in wordpress with functions.php without plugin?
- Display values of current POST request on page
- Changing ALT-tag for logo in wordpress
- Using Javascript On Page – Header and Footer Now Missing
- Modifying child theme’s header
- Add my footer menu to the header
- Change headers for one custom PHP file
- Premature end of script headers: wp-mail.php?
- Allow user to choose header style
- How to include different html tags in the header for different pages?
- Use header option on wp-login page with a second logo
- my site show this symbol (::) between site title and tagline
- Headers Already Sent
- Changing 2011 theme header image based on user dropdown
- Converting Menu Links to List Elements
- Warning: Cannot modify header information (with a twist)
- Cannot get custom javascript to execute on page
- Cannot modify header information – headers already sent
- Dynamic Email Handler with ‘header (“Location: …’
- Best way to do multiple constructors in PHP
- Moving a PHP web-app to WordPress
- How to use multiple query with same meta key
- How to use WordPress (PHP) functions in AngularJS partials files?
- How to Remove a Filter from the Admin List Table?
- Remove commas from WooCommerce checkout addresses fields
- Concatenate site_url and string doesn’t work
- How to display user nickname (not display name) in PHP template?
- Extract subdomain and relative address from a url
- Custom Template 404 for specific custom post type
- Count top level menu items
- How to complete two other input fields, completed the first
- Remove the first 5 characters of the_title and orderby that
- Replacing mysql_escape_string in a custom plugin when moving to PHP7
- running wp-cron.php using php not wget
- How can I open up my administrative panel to everyone?
- Using and saving custom dropdown boxes on user profiles
- Hide image if taxonomy term is empty
- WP_Query | IF within $args array | Help me only add specific arguments if the argument is not blank
- Use custom template on custom post type
- How do I access post_meta key with php?
- Use SCSSPHP to compile Theme Customizer Values into .SCSS files ready to compile to CSS
- Simple seo-friendly custom $_GET url rewrite with htaccess
- Update value of a associative array with update_post_meta
- feedburner plugin for WP 3.5
- WordPress custom post type and taxonomy
- I want to fusion the product columns in email table order
- Using wp_editor() when not logged stopped working
- Change username link in admin bar
- How to change this internal image link parameter using PHP?
- php if, else & custom fields – syntax error
- Why isn’t my custom function kicking in from my functions.php file?
- Banner editable from backend
- Shortcoding with Divs
- Reusing the page name class that WordPress adds to body tag
- How do I remove blog entries from home page Twenty Eleven child theme?
- Search results always returns “No results” no matter what
- Adding extra cost to woocommerce flat rate based on shipping zone
- I got this error POST https://localhost/meraboilerwp/[object%20Object] 404 (Not Found)