TYPO3 protected sites access to GET variables - php

I am writing an TYPO3 Extension and everything is working fine right now. I Access the GET Variables via
t3lib_div::_GET('rid');
This does work on the testsite I added my Extension to, but if I add it on another subsite of the same page which is in an access-restricted area this does not work. I use var_dump to look at the GET vars, and on the normal site it works, on the restricted I dont get anything (not even NULL!) Just no output and the logic also does not take it. How do i fix that, or ist there another way to access the GET variables in that case?

I guess that happens because within the first request the output of your extensions is stored within the cache. And the second output is just generated out of the cache (instead of regeneration within your extension). To avoid that you could just make your Extensions not cacheable (USER_INT) or use cHash to show that cache-entries are related to more input values than just the simple page-url...
cHash is explained in the the mysteries of cHash article and I guess you'll find enough information regarding USER vs. USER_INT Objects with google ;)

I have no clue why, but seems to be some kind of caching issue. I always cleared the Typo3 cache so it was not directly a problem with that, but if i set the "nocache" flag for the site the plugin is on, everything works fine. So actually it has nothing to do with the access thing, but I do not understand why this doesnt work without nocache.

Related

retrieve user->ID from wordpress to aanother php site

I have a PHP application custom_appli in /var/www/httpdocs.
Wordpress is installed on the same server in /var/www/httpdocs/new_cms/wordpress.
I need to retrieve user->ID using SESSION of custom_appli.
I have tried to insert :
require( './new_cms/wp-snapshots/wp-blog-header.php' );
global $user;
$user = wp_get_current_user();
echo "ID :".$user->ID;
writing wp-load instead of wp-blog-header doesn't change anything no matter whether I use include or require_once.
Could you please give me a link or advice on how to obtain user from SESSION?
Thanks in advance
Details and info are sparse, but here's how I would do it (I know about 5 methods, these are the least painful):
As mentioned, wp_get_current_user() gets you close, but that is generally only usable on the page for the user as in "on load" only. So from the WP served page you can get user ID (and all other info) and the session and have something that is usable. There are many ways to use that data to solve your problem, not really smooth all the time. Session data is etherial, beware.
Another way to go about it is to use wp-load.php and wrap it in middleware. this script bootstraps WP and allows queries and similar in the "bootstrapped" wordpress environment providing the applications internal API. I would consider adding wp-load to custom_appli "in the right way" and use that as middleware between the 2 applications. You will still need to identify the user as in many cases.
Without more information it is hard to guide you, but I can tell by your needs and the code already in the post that you are setting up for possible problems with dependencies, possible name-spacing collisions($user is something that could bite you as a global), and a myriad of other ways to loose time. If custom_appli needs a user ID, send it the user from WP on page load or similar.
When/why do you need that info? What is the flow?
You can also traverse a lot via session ID info too (depending on configuration).
FWIW I have passed user information successfully from 2 freestanding applications on different servers, it was very hard to do correctly, but it is possible.
Update after clarification
As mentioned "wordpress-user and cusstom-appli have same users" is possibly a replication of functionality, specifically running 2 tables(?) or logic. Just some feedback.
Basically you are wanting to hook the "logged in" status of a WP user. I see no mention of:
FK/relationships built on user (easy but a little more work)
ACL/permission based access on custom appl
No serializing of data or similar to the WP user (user in general)
Any of the above might have me change the solution. Here is a pretty clean prototype I wrote for you that is about 15 lines of code.
It follows some code from wp and essentially:
Makes sure PHP session is initialized via the theme functions.php
Uses the WP login (authentication) success to add a var to the session
On logout unsets the var (!IMPORTANT!)
Also makes sure the session is set when not logged in or the key is not present
Is easy to pick up outside of WP via session (custom_appl.php)
I tested this and it worked fine locally on one of my installs, I don't see any reason why it would give you problems. I would harden this a little more, but this is only a prototype showing how to use the key tools in PHP and WP.
wp_get_current_user() is a function in wp-includes/pluggable.php, which is loaded by wp-settings.php. I'm not sure how exactly WordPress bootstraps itself but I'd try to include wp-settings.php if anything.

php settings header location redirecting to paypal but query vars not passed (possibly)

so this is kind of wierd.
on 99.99% of servers this is being used it works just fine, but I have one , where it somehow does not want to work properly, so I wonder if there's a php settings (this server has also suhosin installed) that might prevent this from working.
scenario is this:
the script is (trying to) redirect to paypal like so:
header('location: https://www.paypal.com/cgi-bin/webscr?'.http_build_query($varsToSendtoPaypal).'');
as i mentioned , this works just fine 99.99% of the time. even if i do
print'https://www.paypal.com/cgi-bin/webscr?'.http_build_query($varsToSendtoPaypal).'';
and copy the resulting url into the browser it redirects as expected.
however, when using the header method it DOES redirect, but only to the paypal homepage at paypal.com and not the checkout page .
Somehow I am thinking that the query string gets truncated for some reason , but I have no idea where to look to find out if that is the case or what setting it may be that might affect this....
there are also only 22 variables in the query string with nothing out of the ordinary
any ideas / hints / pointers greatly appreciated
happy to expand of course if required..
PS: this script runs in a wordpess plugin btw, but I would have thought that has no bearing on why this would not work . just thought i'd mention it though
so, thanks to msg7086 suggestion to have a look at the console, I tracked the error down to this particular server using & as opposed to just & when using http_build_query.
the fix for this appears to be using
http_build_query($array,'','&');
as opposed to just
http_build_query($array);
maybe this helps someone

Is there a way to pass variables except sessions and get variables?

My problem is not so easy to describe ... for me :-) so please be lenient towards me.
I have several ways to view a list. which means, there are some possibilities how to come to and create the view which displays my list. this wokrs well with parallel opend browser tabs and is desired though.
if I click on an item of my list I come to a detail-view of that item.
at this view I want to know from which type of list the link was "called". the first problem is, that the referrer will allways be the same and the second: I should not append a get variable to the url. (and it should not be a submitted form too)
if I store it to the session, I will overwrite my session param when working in a parallel tab as well.
what is the best way to still achive my goal, of knowing which mode the previous list was in.
You need to use something to differentiate one page from another, otherwise your server won't know what you're asking for.
You can POST your request: this will hide the URL parameters, but will hinder your back button functionality.
You can GET your request: this will make your URLs more "ugly" but you should be able to work around that by passing short, concise identifiers like www.example.com/listDetail?id=12
If you can set up mod_rewrite, then you can GET requests to a url like www.example.com/listDetails/12, and apache will rewrite the request behind the scenes to look more like www.example.com/listDetails?id=12 but the user will never see it -- they will just see the original, clean/friendly version.
You said you don't have access to the server configuration -- I assume this is because you are on a shared server? Most shared servers already have mod_rewrite installed. And while the apache vhost is typically the most appropriate place to put rewrite rules, they can also be put in a .htaccess file within any directory you want to control. (Sometimes the server configuration disables this, but usually on a shared host, it is enabled) Look into creating .htaccess files and how to use mod_rewrite

CakePHP dropping session between pages

I have an application with multiple regions and various incoming links. The premise, well it worked before, is that in the app_controller, I break out these incoming links and set them in the session.
So I have a huge beforeFilter() in my app_controller which catches these and sets two variables in the session. Viewing.region and Search.engine, no problem.
The problem arises that the session does not seem to be persistant across page requests. So for example, going to /reviews/write (userReviews/add) should have a session available which was set when the user arrived at the site. Although it seems to have vanished!
It would appear that unless $this->params is caught explicitly in the app_controller and a session variable written, it does not exist on other pages.
So far I have tried, swapping between storing session in 'cake' and 'php' both seem to exhibit the same behaviour. I use 'php' as a default. My Session.timeout is '120', Session.checkAgent is False and Security.level is 'low'. All of which should give enough leniency to the framework to allow sessions the most room to live!
I'm a bit stumped as to why the session seems to be either recreated or blanked when a new page is being requested. I have commented out the requestAction() calls to make sure that isn't confusing the session request object also, which doesn't seem to make a difference.
Any help would be great, as I don't have to have to recode the site to pass all the various variables via parameters in the url, as that would suck, and it's worked before, thus switching on $this->Session->read('Viewing.region') in all my code!
Try setting the security setting in your /app/config/core.php file to medium or low. That solved a session problem I had.
i had the solution or at least that work for me
you try to pass from controller reviews action write to controller userReviews action add right???
check that your controller userReviews must end whit php tag "?>" and NO MORE SPACE
SO if you have someting like this
line
999 //more code lines
1000 ?>
1001
your session fail
you have to had this
line
999 //more code lines
1000 ?>
sorry for my bad english
soo you
It would appear that unless
$this->params is caught explicitly in
the app_controller and a session
variable written, it does not exist on
other pages.
That sounds like the proper behavior unless you are posting data from page to page. If you want any variable to persist, it should either be set in the model (where it will persist with the association), or passed on in a function, or set in the session explicitly using the session component:
$this->Session->write('Viewing.region');
(see: http://book.cakephp.org/view/398/Methods)
On a related note, I've had most success with sessions stored in the database. Run the file from app/config and set it to db. See if that helps.
Also, do the Cake core tests for the session work?
Might it be this problem? Essentially, cake's session resets if the user-agent changes
It's a shame that I ran into this very problem you mention a few days ago and now I cannot find the link that helped me solve it.
Also: are you using database or plain php sessions?
I'm going to go out on a limb here without being able to look at your code, but might it be possible that your "reviews" controller (or whatever) has its own beforeFilter() and doesn't call its parent's beforeFilter() explicitly?
This has burned me before...
I got some issues like this. Session set using some controller was not available in another , controller . I could clear the issue after spending few hours . There was a white space afer the end of php tag at the bottom . After clearing the line and white space after the last ?>
tag worked fine .
I had this problem when moving a CakePHP site. My problem was that the session directory wasn't writeable. You should make sure the folder app/tmp and all it's subfolders (including sessions) have permission 777.

URL not behaving as expected in Zend Framework

When calling the following type of url in a controller's init method I get two different results on two different servers:
http://address.com/index/action/?start=2009-04-18&end=2009-04-21
Calling
echo $_GET['start'];
Gives me 2009-04-18 on one server and nothing at all on the other server.
However, and this is the strange part, adding
exit();
after that echo statement causes 2009-04-18 to display as expected on both servers.
FYI dumping the request params shows they are available on the one server but not on the other... unless you call exit();
What in the world could be causing this? I realize this isn't the way to structure URLs in ZF but it is the way it is being done in this particular project. Maybe a custom route of some sort would help? STill doesn't explain the exit(); bit causing the $_GET variable to display.
EDIT: In order to get around this for now I wrote a custom route, however the ? in the url messes things up. By including it it appears that the GET variable is forced and overrides my custom route. Leaving it out, everything works fine in the route I created but I don't have the option to remove that ?. Anyone know how to make the custom route take precedence over the GET variables being populated when that ? is in there?
My guess is the $_GET['start'] is actually working on both servers, the problem is the one that shows nothing is having a problem AFTER this statement, but the output from the echo is still in the output buffer. If you do a flush() after the echo, you should be able to see the output, then whatever crashing afterwords will still crash but you will see the date.
I'm not sure what you're doing with the routing(not enough code to see), but your query string(everything after the ?) is totally different from your routes. If you're going to use routing, you'll want to enable mod_rewrite by using the provided .htaccess file on the ZF Quickstart page.
I think you'll want to make your own custom Router(not just a Route), and then use the $_GET parameters to route to the controller you want, along with the parameters it needs. The default Router doesn't do complicated things with the QueryString, at least not the last time I checked.
Check your .htaccess file on the broken server.
http://framework.zend.com/manual/en/zend.controller.router.html

Categories