WP caching plugins are preventing cookie from being set - php

I made a simple WordPress plugin, it works perfectly fine on my own server, but not on the live website of a friend.
It is a very basic Referral plugin, I used cookie to save the referrer ID, then used user_register hook to save it in database after some one signs up.
This is the part that saves the Referrer ID:
function set_referrer_cookie() {
setcookie("referrer_id", $_GET['ref'], time()+3600, "/");
}
add_action('init', 'set_referrer_cookie');
The cookie is not set many times, at first I was puzzled, but after a lot of testing, I believe this is caused because of caching (he has a lot of plugins, such as Breeze caching etc)
How can I make sure, the cookie is set all the time?
Is there any way around this?
Edit:
After running each URL in the browser, the plugin saves a new .php file in its /breeze/cache/ folder,
I think it is the Output of the PHP file, as the echo value is shown in plain text in it, and it's all HTML,
so it appears the Breeze plugin caches the output of PHP in a file, and serves it again as a static HTML, with no option to exclude set_cookie in the admin panel... is there any way to work around this?

Related

Session for both WordPress and NON-WP pages

Have a WordPress site, with a directory that has non-WordPress pages in it. (a couple of php files)
The non-WP pages will perform a function with another non-wordpress site, and set a few session variables.
It would be helpful if WP be able to read those variables too, but it seems to treat the files at /directory/ (the non-wp pages) as a different independent session.
I've tried starting the session from either the wordpress pages or the non-wordpress pages, trying both simultaneously, and just initiating the session_start() vs testing for existing session (if (!session_id()) { session_start(); }) on both sides.
I echo out the session ID, and depending on which side (wp or NON-wp) starts, it, the other just doesn't see a session. In fact, starting it in both (which should overwrite the other???), just makes two different concurrent session ID. And each set of pages retains its ID, so not like each is constantly getting a new one reset.
The Session should be global for the domain and for the browser/user, right? It should treat example.com/ and example.com/directory/ the same?? Am I missing something about sessions?
Or am I missing something about Wordpress? Is there some weirdness in WP or a setting somewhere that restricts its sessions to only the pages WP knows about? I know sessions aren't part of the WP core, so it would seem strange that this would be the case, but lacking info here.
I tried searching for solutions, but either I'm just using too broad search terms, or this isn't a common issue with both wp & non-wp pages and sessions.
NOTES: 1. Don't think any plug-ins are calling session. 2. Want to keep it server side (no cookies) 3. Did change the htaccess, but that was just rewrite for that directory (and changed it back) 4. Can't really merge the non-WP pages into the WP pages, so presumed session variables would work for the duration of the session.

How to make real page cache in WordPress?

I want to make page cache of static pages in my WordPress theme (and basically I know how to implement it)
The problem is that when making theme - the first time when I "get any control" about what is happening is inside functions.php file of theme, and this file is loaded about 1 sec after request starts (before it is loading all wordpress functions stuff, I quess some sql - but I dont need that all as I'm using page cache, just want to render saved html - btw. thats what is cache about for me).
So the question is - Am I able to - from level of theme - take control of WordPress initialization before theme functions.php? - the best would be as soon as possible after request start
Why? Getting html from cache takes 0,05s in my case, and time from request start to functions.php is 1s so in sume it gives 1,05s that I could reduce to like 0,1s if I'm able to 'capture' request earlier.
I dont want to modify non-theme files like WordPress core files as many people will use this theme, but if there is no other way than maybe but I dont feel it would be good practice?
i guess this might help: http://codex.wordpress.org/Plugin_API/Action_Reference/init
this hook gets executed when wordpress has loaded but before anything is saved
Create a drop-in plugin called advanced-cache.php, put it in wp-content (not wp-content/plugins), put define('WP_CACHE', true); in wp-config.php, and get to work.
Make sure not to cache:
admin pages
404 pages
POSTed pages
pages with query strings
pages that will be redirected
etc

Lost sessionvariables in firefox

I have a pretty strage problem im dealing with.
Lost sessionvariables in firefox.
Im using wordpress and have a subpage that causes the loss.
More specific:
In wordpress there exists a page called My pages (Original page names are in swedish, translated for convinience)
Under this page i have a few subpages. Among these are a page called Create test. There is nothing special about this page, for now only contains the phrase "hello world". If I enter any page other that this, it works.
But this particular page just seems to clear my session variables (wich I use to store login info)
I tried deleting the page in question in the effort to remake it.
While it was deleted I tried navigating around on the page.
Create test was the last item in the subnavigation menu, and now when its gone, the same thing happens on the last menuitem (now Account settings). This leave me to believe its something with the menu.
Even more strange, after recreating Create test, so that this page is now the last item. Still it's Account settings that is the page with the resetting of sessionvars...
I have through echo determined that the session id stays the same, just the variables that get unset.
I have unset($_SESSION['id']); at only one place, and this code is NOT run.
The problem just baffles me and I have no idea why this particular pages does this.
It may be totally unrelated, but we had problem with Firefox and sessions on certain pages in the past. It happened most of the times while developing and therefore refreshing a particular page, have you tried clearing your browser cookies which is where session is stored?
As an addition:
Check that you assign sessions before you write anything to the response stream.
Also we had similar problems with sessions set in a pages that were doing a redirection (i.e. a login page that if successful would set the session and redirect to the another page.)
I'm not sure about PHP but in .NET that can be overcome by explicitly setting not to terminate the response so that all headers are written to the response stream.
Fixed now, actually have no idea what I did. but I've change some html but mostly CSS.
So there is a strong posibility it was CSS-related.

Odd entry in WordPress 'Admin_Panel.php' file?

I just migrated a Wordpress install from one of my servers to another for a client (client's website which I set up and manage) and as a precautionary measure, I was perusing the 'Theme > Edit' listed files in the Wordpress Admin panel just to check for any links to the old server/domain and try to clean everything up.
When I got to the 'admin_panel.php' file, I found this entry at the very bottom of the file (it was the last entry):
function ranking() {
$pshow = " <span style='display:none;'><a href='http://www.ellelive.com/'>Live sex</a> , <a href='http://www.2.livejasmin.com/listpage.php?psid=elenaa'>webcam sex</a> , <a href='http://www.2.livejasmin.com/listpage.php?tags=mature&psid=elenaa'>Mature Female</a> , <a href='http://www.2.livejasmin.com/freechat.php?random&psid=elenaa'>Livejasmin</a> , <a href='http://www.2.livejasmin.com/listpage.php?tags=girl&psid=elenaa'>Girl</a></span>";
echo $pshow;
}
Now, I'm not sure where the theme that I modified for the client came from, as he supplied it, but this is just... odd.
To note, the admin_panel.php file is for the backend theme settings section, so it isn't seen by the public. I also couldn't find anything in there that reflects this entry, but then again I'm not sure I would.
I'm not a coder, so I figured I would just see if anyone had any input on this. Is this likely something that was included by the theme coder? Or should I grill my client about where he sourced this theme and see if he got it from some shady website?
I'm just really unfamiliar with PHP, and while this looks harmless as far as site security is concerned, I figured I'd make sure.
I did remove the entry and everything seems fine, but better safe than sorry, right?
Thanks!
Whoever has made the template ( I presume "elenaa") chucked some hidden links in there to increase the google rankings of these websites. Replace the function with the following if your worried about it.
function ranking(){ return ''; }
If you just delete it you could get missing function errors.
Although the function is in the admin section is it possible the function could be called somewhere on the front end of the website?
Another possible issue: this is something that happens fairly frequently if you have the wrong permissions set on your files - this is especially true if it's at the very bottom of the file.
I've had spammers run scripts on my WP builds that will check to see if the page permissions are set incorrectly, and if they are, the script will write in some links off-site at the very end of the file. This is nice and effective because the spammer gets a Google rankings boost, and most people are never the wiser.
I'd keep an eye on your file permissions, and check back to see if these mysterious links have returned in a couple of months.

Wordpress: using a test theme only for a specific user

I'm testing a new template for a wordpress based site, and I'd like to test it directly on the live version instead of making copies. I thought I could create a test user (wordpress is bridged with vbulletin which handles user auth), serve the usual theme to anyone BUT that specific user, who would get the new testing one.
I don't want to install a plugin, I'm looking for the right place to edit to insert this check:
if logged user == test_user_id
serve 'testtheme'
else
serve 'normaltheme'
The userid can be get from $_COOKIE.
I tried hacking the get_template() function in wp-include/theme.php but apparently that was not enough. Any suggestion?
This is the best way to "test" or develop a theme behind the scenes without needing to alter too much of your Wordpress core or make custom changes...
http://digwp.com/2009/12/develop-themes-behind-the-scenes/
Just logging into my old Wordpress.com blog, I see that I can do all the previewing I want from the themes manager already - click around to any page I like, or bring up the frame's URL to see what query string I'd have to append to a URL to get the same preview, e.g.
?preview=1&template=pub/mytheme&stylesheet=pub/mytheme
Any reason that's not enough?
Perhaps you should add a column to your user table, call it "is_beta" and if it's set to 1 then enable beta features/themes. This way you can easily add or remove people from the beta, and when you're beta is ready to launch, you flush the column for everybody and make the features default.

Categories