FPDF session variables - mysql

I have a web application that I've built on Wordpress version 4.1.1, I'm using PHP 5.4.22 and MySQL 5.5.42-cll.
The application collects user entry via form input fields, through a series of 4 consecutive pages, and stores to session variables. On the last page, there is a print to PDF feature that displays the customized PDF for user download. This PDF is generated via FPDF.
I had this feature working and am not sure what change, or auto-update in wordpress could've caused this to stop working. But I have troubleshot and narrowed the problem down to this:
The session variables aren't making it to the FPDF PHP files. I'm able to verify that the session variables remain on the page prior by printing them to the page. Again, I didn't change any of the code in the FPDF files or data input pages.
Please help if you can. I'm not certain what the problem may be.
Additional Info:
Around the same time this error was found, I was working on forcing SSL throughout wordpress. I ended up using the plugin WordPress Force HTTPS. I speculated this could've over-wrote something, but I'm not sure. The code within this plugin is simply:
function toz_force_https () {
if ( !is_ssl() ) {
wp_redirect('https://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'], 301 );
exit();
}
}
add_action ( 'template_redirect', 'toz_force_https', 1 );
Any assistance would be greatly appreciated!

I found the answer. Please forgive my oversight, this may be a super simple answer but I'm posting it so someone else doesn't go through the same frustration.
All of my session variables were stored on
https://www.example.com
and I was launching my FPDF via
https://example.com
I learned the hard way that Session variables in PHP are lost when changing the domain. Hope this saves someone some time.

Related

Wordpress JSON API returns normal site page in html. How do I get it to give me JSON like it's supposed to

For example, entering http://mywordpresswebsite.example.com/?json=1 into the browser loads the main site html, the same as omitting the json querystring variable: http://mywordpresswebsite.example.com/
The JSON API is activated. I have tried reactivating and deactivating, checking .htaccess file settings, and deactivating all other plugins. None of those have made much difference so far.
TIA
I had the same problem with my localhost test page and was wondering, why my route worked last week and was not accessible this week.
Short explanation
After some tests and a lot of frustration, I was able to use the REST API Route again by following the wordpress documentation about routes-vs-endpoints with “Pretty Permalinks” and “Ugly” Permalinks
Longer explanation
I guess in my case it was based on the reinstall of my MySQL Database. By installing the new database, my previous setup has been reset to the wordpress standard installation with permalinks as "plain", which is an "ugly" permalink. That's the reason, why the answer of Mattygabe work for me after the reinstall of the database.
But with this solution, I had a problem with my filter value and therefore I found the solution with "pretty premalinks" and changed my permalinks to "Month and name", as shown in the picture. After this change, I could access my REST API via the desired route.
There could be also some difficulties with REST APIs related to the following examples:
using "wp" within the REST route
if you work on plugins, which should be shared, keep on mind that some plugins may restrict REST Access, e.g. iThemes Security
I'm likely doing it wrong, but when I form my requests for a Wordpress installation at http://www.example.com/ like this:
http://www.example.com/index.php?rest_route=/my/rest/route/here
I end up getting proper responses back.
I had a heck of a time figuring this out and ended up grokking a URL formatted like that in the HTML returned to me. I was expecting to make requests as http://www.example.com/wp_json/wp/v2/my/rest/route/here , but I only got HTML responses.
(FWIW, I am reposting this on all similar questions on the StackExchange network. Admins/mods - if this is against the rules or seen as rep spamming, feel free to take it down. Was hoping to help anyone else hitting the same issue I am, and to also learn what it is I've done wrong and why.)
Ok, so the new endpoint for Wordpress 4.7 is mywordpresswebsite.example.com/index.php/wp-json. It's part of Wordpress Core as of 4.7 and not a plugin anymore, there's nothing to be activated. Thank you, Mark Kaplun.
I also experienced this issue. I did install the WP API plugin and then realized I didn't need it so I deactivated it and deleted it. Afterwards I tried a GET request to https://example.com/wp-json/wp/v2/posts and received the HTML of my wordpress site.
To fix this I ended up deactivating all plugins and then I started receiving the JSON response from https://example.com/wp-json/wp/v2/posts so I stepped through each plugin reactivating and in the end all my plugins are active and the endpoint is responding with JSON.
I changed Permalinks (Settings => Permalinks)
I had an issue returning html page instead of JSON response on Wordpress 5.3 and I got resolved when I changed the Permalink as Post name from plain

Unable to fix malformed JSON in wordpress

I am using woocommerce for the first time with wordpress in order to setup an e-commerce site. Everything is installed properly from wordpress to woocommerce plugin and the theme. But the problem resides.
Kindly check below image
I keep getting the same error again and again, I reinstalled the entire wordpress site but no luck. I followed few tutorials wherein they instruct to open browser console and check for a red line which I don't receive in my console.
What I get is in the image below
Also, somehow I am not even able to select another payment option other then cash on delivery which I have installed on my site. I have been struggling for last 3 days, but no luck! Kindly do not down vote this question. As I am feeling helpless at the moment.
The site is fashionburst.in
Thanks in advance
For anyone who might run into this issue, try to turn on debugging in wp-config.php
define( 'WP_DEBUG', true );
define( 'WP_DEBUG_LOG', true );
And then read the log file in wp-content/debug.log. I had a PHP error in one of my plugin's hooks and since the checkout is processed with JS, the checkout.min.js threw this error. Log file should give you proper error report (in my case I was using undefined PHP function).

New MySQL query on each page refresh

I'm trying to to guarantee that fresh JSON is sent to my page every time a user clicks refresh. Currently, if the JSON is updated the webpage will not reflect the change until Apache is restarted.
I have tried the following approaches -
Create a nocache function and call the decorator in the page function
I have tried putting headers in my HTML
Using Command + Shift + R in Chrome for MacOS for a "hard" refresh
No good... I'm beginning to think I'm misunderstanding something. Can someone point out the error of my ways? I copy and pasted the code presented in those links. The first link even speaks about JSON specifically. I can show my exact code being used if desired, but like I said; copy and paste.
Maybe its not even a caching issue, I'm not sure, but I'm open to any ideas!
EDIT:
I know now that my no-cache headers ARE being passed to the HTML. The issue lies somewhere in that the Flask isn't asking MySQL for updated data every time the page is loaded, only when Apache is restarted. So even if fresh data is in MySQL DB it will not be displayed for the user unless Apache gets restarted.
I finally found another post on Stack Overflow regarding my question.
Turns out I need to make my DB connection and form the JSON in the same function. Before I was calling the data from the DB in a separate function and then referencing it to create JSON and pass it to the HTML in a different one. Now everything is inline see HERE.

Html Chat Or Something With Parameters

Well, I almost don't know anything about this language, so I need help!
I need codes/scripts that I can paste to my website, or copy the files on the server... then make that work.
I used to copy random ones but nothing worked.
What exactly I need:
-A chat that appears on the page
-That chat should with with URL parameters, like: www.site.com/message="Hello", so that message appears on the page
-All messages should be saved in a file on server, for example "history.txt", and that history should load by loading the page...
Is that all simple? Possible?
Thanks if anyone get me an answer(s)!
You need to use PHP to do this. If you use the GET method, parameters can be passed through the url, and it's very easy to read and write files. Where are you coding at the moment?

How to configure Netbeans code entry point when you use mod-rewriting

I am developing a website in PHP and I am using mod-rewrite rules. I want to use the Netbeans Run Configuration (under project properties) to set code entry points that looks like http://project/news or http://project/user/12
It seems Netbeans have a problem with this and needs an entry point to a physical file like http://project/user.php?id=12
Has anyone found a good way to work around this?
I see your question is a bit old, but since it has no answer, I will give you one.
What I did to solve the problem, was to give netbeans what it wants in terms of a valid physical file, but provide my controller (index.php in this case) with the 'data' to act correctly. I pass this data using a query parameter. Using your example of project being the web site domain and user/12 as the URL, use the following in the NetBeans Run Configuration and arguments boxes. netbeans does not need the ? as it inserts that automatically, see the complete url below the input boxes
Project URL: http://project
Index File: index.php *(put your controller name here)*
Arguments: url=user/12
http://project/index.php?url=user/12
Then in your controller (index.php in this example), test for the url query param and if it exists parse it instead of the actual Server Request, as you would do normally.
I also do not want the above URL to be publically accessible. So, by using an IS_DEVELOPER define, which is true only for configured developer IP addresses, I can control who has access that special url.
If you are trying to debug specific pages, alternatively, you can set the NetBeans run configuration to:
http://project/
and debug your project, but you must run through your home page once and since the debugger is now active, just navigate to http://project/user/12 in your browser and NetBeans will debug at that entry point. I found passing through my home page every time a pain, so I use the technique above.
Hopefully that provides enough insight to work with your project. It has worked good for me and if you need more detail, just ask.
EDIT: Also, one can make the Run Configuration Project URL the complete url http://project/user/12 and leave the Index File and Arguments blank and that works too without any special code in controller. (tested in NetBeans 7.1). I think I will start using this method.