Sessions does not work when I change directory - php

Sessions does not work when I change directory. I mean my files that contain codes for sessions run on the main directory. However, when I upload same files to different directory, they does not run. The same codes, files but not working in different directory. What is the problem? I confused.
Here is my codes:
<?php
ob_start();
session_start();
include("db.php");
$rota=strip_tags($_POST["rota"]);
$date=strip_tags($_POST["date"]);
$_SESSION['rota']=$rota;
$_SESSION['date']=$date;
?>
------
<?php session_start();
ob_start();
include("db.php");
$date=$_SESSION["date"];
$rota=$_SESSION["rota"];
echo "Date : <b>".$date."<br><br></b>";
?>
And here is my error log:
[12-Aug-2016 13:51:41 UTC] PHP Warning: session_start(): Cannot send session cookie - headers already sent by (output started at /home/karelyac/public_html/reserve/en/y1s3.php:1) in /home/karelyac/public_html/reserve/en/y1s3.php on line 3
[12-Aug-2016 13:51:41 UTC] PHP Warning: session_start(): Cannot send session cache limiter - headers already sent (output started at /home/karelyac/public_html/reserve/en/y1s3.php:1) in /home/karelyac/public_html/reserve/en/y1s3.php on line 3
[12-Aug-2016 13:51:41 UTC] PHP Deprecated: mysql_connect(): The mysql extension is deprecated and will be removed in the future: use mysqli or PDO instead in /home/karelyac/public_html/reserve/en/db.php on line 7
[12-Aug-2016 13:51:43 UTC] PHP Warning: session_start(): Cannot send session cookie - headers already sent by (output started at /home/karelyac/public_html/reserve/en/y1s2.php:1) in /home/karelyac/public_html/reserve/en/y1s2.php on line 3
[12-Aug-2016 13:51:43 UTC] PHP Warning: session_start(): Cannot send session cache limiter - headers already sent (output started at /home/karelyac/public_html/reserve/en/y1s2.php:1) in /home/karelyac/public_html/reserve/en/y1s2.php on line 3

Related

Wordpress rest_pre_serve_request produces PHP header warnings

I am currently developing my first Wordpress plugin and I've encountered an issue with the REST API which I don't really understand. Maybe there is a better approach than mine, that I am not yet aware of, so I am happy for any help that's out there!
Here's the deal:
I am creating an API that is supposed to serve cached data from the Wordpress mysql db. I am storing data (url, mime-type, [...]) from web resources to the db which I then want to serve. The resources to be cached are defined in a policy file which looks something like this:
policy.json
{
"files":
[
{
"resource_url": "https://example.come/assets/images/image.png",
(...)
},
(...)
]
}
Since the number of files is dynamic my service needs to adjust to whatever custom routes the policy file dictates. E.g. In the above case it is supposed to serve the resource via my Wordpress site, which initially came from example.com. So if
https://my-wordpress-site.com/wp-json/example/v1/assets/images/image.png is requested, the cached file from https://example.come/assets/images/image.png is supposed to be served.
My REST API looks something like this:
mypl/rest_api.php
<?php
function custom_resource_endpoint() {
return new WP_REST_Response("The requested resource could not be found.", 400);
}
function rpc_through_endpoint( $request_data ) {
$route = $request_data->get_route();
$header = $request_data->get_headers();
$data = $request_data->get_body();
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, "https://example.com" . str_replace('example/v1/', '', $route));
curl_setopt($curl, CURLOPT_POST, 1);
curl_setopt($curl, CURLOPT_HEADER, 0);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 0);
curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, 3);
curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
curl_setopt($curl, CURLOPT_HTTPHEADER, array('Content-type: application/octet-stream'));
41 $response = curl_exec($curl);
curl_close($curl);
return new WP_REST_Response($response, 200);
}
function register_custom_routes() {
$rest_prefix = 'example/v1';
register_rest_route($rest_prefix, '/rpc', array(
'methods' => WP_REST_Server::CREATABLE,
'callback' => 'rpc_through_endpoint'
));
register_rest_route($rest_prefix, '(/w)', array(
'methods' => WP_REST_Server::READABLE,
'callback' => 'custom_resource_endpoint'
));
}
add_action('rest_api_init', 'register_custom_routes');
// Interceptor.
function serve_static_resources($served, $result, $request, $server) {
$route = $request->get_route();
if (ends_with($route, 'rpc')) {
$served = false;
} else {
$file_uri = str_replace('/example/v1/', 'https://example/', $route);
if ($file_uri != null) {
$resource = checkLatestResourceByUri($file_uri);
if(count($resource) > 0) {
$vars=get_object_vars($resource[0]);
http_response_code(200);
header( 'Content-Type: ' . $vars['resource_mime_type'], true );
92 echo $vars['resource_data'];
$served = true;
}
}
}
return $served;
}
add_filter('rest_pre_serve_request', 'serve_static_resources', 10, 4);
The way I thought about it was, I create a READABLE (GET) rest route, which accepts all requests on the rest API. Once the request comes in it is being intercepted with the rest_pre_serve_request filter, in order to check the database whether or not the requested file is cached and if so serve it. Here's my approach on that:
According to the documentation I can simply echo the data from the filter and return true or false to indicate whether the request has already been served or not. In my case though, I also have to add additional data such as the Status-Code and the Content-Type for the response, in order for the clients to be able to process it correctly. Now here's the Crux. The logic works exactly like I want it to and it serves the requests like they're supposed to be, but still I get the classic headers already sent warnings from PHP, which look like this:
[06-Aug-2020 10:47:03 UTC] PHP Warning: Cannot modify header information - headers already sent by (output started at /var/www/html/wp-content/plugins/mypl/rest_api.php:92) in /var/www/html/wp-includes/rest-api.php on line 596
[06-Aug-2020 10:47:03 UTC] PHP Warning: Cannot modify header information - headers already sent by (output started at /var/www/html/wp-content/plugins/mypl/rest_api.php:92) in /var/www/html/wp-includes/rest-api.php on line 597
[06-Aug-2020 10:47:03 UTC] PHP Warning: Cannot modify header information - headers already sent by (output started at /var/www/html/wp-content/plugins/mypl/rest_api.php:92) in /var/www/html/wp-includes/rest-api.php on line 596
[06-Aug-2020 10:47:03 UTC] PHP Warning: Cannot modify header information - headers already sent by (output started at /var/www/html/wp-content/plugins/mypl/rest_api.php:92) in /var/www/html/wp-includes/rest-api.php on line 596
[06-Aug-2020 10:47:03 UTC] PHP Warning: Cannot modify header information - headers already sent by (output started at /var/www/html/wp-content/plugins/mypl/rest_api.php:92) in /var/www/html/wp-includes/rest-api.php on line 598
[06-Aug-2020 10:47:03 UTC] PHP Warning: Cannot modify header information - headers already sent by (output started at /var/www/html/wp-content/plugins/mypl/rest_api.php:92) in /var/www/html/wp-includes/rest-api.php on line 597
[06-Aug-2020 10:47:03 UTC] PHP Warning: Cannot modify header information - headers already sent by (output started at /var/www/html/wp-content/plugins/mypl/rest_api.php:92) in /var/www/html/wp-includes/rest-api.php on line 597
[06-Aug-2020 10:47:03 UTC] PHP Warning: Cannot modify header information - headers already sent by (output started at /var/www/html/wp-content/plugins/mypl/rest_api.php:92) in /var/www/html/wp-includes/rest-api.php on line 599
[06-Aug-2020 10:47:03 UTC] PHP Warning: Cannot modify header information - headers already sent by (output started at /var/www/html/wp-content/plugins/mypl/rest_api.php:92) in /var/www/html/wp-includes/rest-api.php on line 598
[06-Aug-2020 10:47:03 UTC] PHP Warning: Cannot modify header information - headers already sent by (output started at /var/www/html/wp-content/plugins/mypl/rest_api.php:92) in /var/www/html/wp-includes/rest-api.php on line 598
[06-Aug-2020 10:47:03 UTC] PHP Warning: Cannot modify header information - headers already sent by (output started at /var/www/html/wp-content/plugins/mypl/rest_api.php:92) in /var/www/html/wp-includes/rest-api.php on line 599
[06-Aug-2020 10:47:03 UTC] PHP Warning: Cannot modify header information - headers already sent by (output started at /var/www/html/wp-content/plugins/mypl/rest_api.php:92) in /var/www/html/wp-includes/rest-api.php on line 599
[06-Aug-2020 10:47:03 UTC] PHP Warning: Cannot modify header information - headers already sent by (output started at /var/www/html/wp-content/plugins/mypl/rest_api.php:41) in /var/www/html/wp-includes/rest-api/class-wp-rest-server.php on line 1337
[06-Aug-2020 10:47:03 UTC] PHP Warning: Cannot modify header information - headers already sent by (output started at /var/www/html/wp-content/plugins/mypl/rest_api.php:41) in /var/www/html/wp-includes/rest-api.php on line 596
[06-Aug-2020 10:47:03 UTC] PHP Warning: Cannot modify header information - headers already sent by (output started at /var/www/html/wp-content/plugins/mypl/rest_api.php:41) in /var/www/html/wp-includes/rest-api.php on line 597
[06-Aug-2020 10:47:03 UTC] PHP Warning: Cannot modify header information - headers already sent by (output started at /var/www/html/wp-content/plugins/mypl/rest_api.php:41) in /var/www/html/wp-includes/rest-api.php on line 598
[06-Aug-2020 10:47:03 UTC] PHP Warning: Cannot modify header information - headers already sent by (output started at /var/www/html/wp-content/plugins/mypl/rest_api.php:41) in /var/www/html/wp-includes/rest-api.php on line 599
[06-Aug-2020 10:47:03 UTC] PHP Warning: Cannot modify header information - headers already sent by (output started at /var/www/html/wp-content/plugins/mypl/rest_api.php:92) in /var/www/html/wp-includes/rest-api.php on line 596
[06-Aug-2020 10:47:03 UTC] PHP Warning: Cannot modify header information - headers already sent by (output started at /var/www/html/wp-content/plugins/mypl/rest_api.php:92) in /var/www/html/wp-includes/rest-api.php on line 596
[06-Aug-2020 10:47:03 UTC] PHP Warning: Cannot modify header information - headers already sent by (output started at /var/www/html/wp-content/plugins/mypl/rest_api.php:92) in /var/www/html/wp-includes/rest-api.php on line 596
[06-Aug-2020 10:47:03 UTC] PHP Warning: Cannot modify header information - headers already sent by (output started at /var/www/html/wp-content/plugins/mypl/rest_api.php:92) in /var/www/html/wp-includes/rest-api.php on line 597
[06-Aug-2020 10:47:03 UTC] PHP Warning: Cannot modify header information - headers already sent by (output started at /var/www/html/wp-content/plugins/mypl/rest_api.php:92) in /var/www/html/wp-includes/rest-api.php on line 597
[06-Aug-2020 10:47:03 UTC] PHP Warning: Cannot modify header information - headers already sent by (output started at /var/www/html/wp-content/plugins/mypl/rest_api.php:92) in /var/www/html/wp-includes/rest-api.php on line 597
[06-Aug-2020 10:47:03 UTC] PHP Warning: Cannot modify header information - headers already sent by (output started at /var/www/html/wp-content/plugins/mypl/rest_api.php:92) in /var/www/html/wp-includes/rest-api.php on line 598
[06-Aug-2020 10:47:03 UTC] PHP Warning: Cannot modify header information - headers already sent by (output started at /var/www/html/wp-content/plugins/mypl/rest_api.php:92) in /var/www/html/wp-includes/rest-api.php on line 598
[06-Aug-2020 10:47:03 UTC] PHP Warning: Cannot modify header information - headers already sent by (output started at /var/www/html/wp-content/plugins/mypl/rest_api.php:92) in /var/www/html/wp-includes/rest-api.php on line 598
[06-Aug-2020 10:47:03 UTC] PHP Warning: Cannot modify header information - headers already sent by (output started at /var/www/html/wp-content/plugins/mypl/rest_api.php:92) in /var/www/html/wp-includes/rest-api.php on line 599
[06-Aug-2020 10:47:03 UTC] PHP Warning: Cannot modify header information - headers already sent by (output started at /var/www/html/wp-content/plugins/mypl/rest_api.php:92) in /var/www/html/wp-includes/rest-api.php on line 599
[06-Aug-2020 10:47:03 UTC] PHP Warning: Cannot modify header information - headers already sent by (output started at /var/www/html/wp-content/plugins/mypl/rest_api.php:92) in /var/www/html/wp-includes/rest-api.php on line 599
Lines 41 and 92 are marked in the code above.
So, is there anything that I am doing fundamentally wrong here?? Or maybe someone knows how to handle that pre serving stuff properly?
I appreciate your help!!
I found a solution to my issue.
Wordpress has a default CORS filter in .../wp-includes/rest-api.php on line 596, in this filter Wordpress sets default headers to send "Cross-Origin Resource Sharing headers with API requests". (https://github.com/WordPress/wordpress-develop/blob/5.4/src/wp-includes/rest-api.php#L596) This filter is added with default priority (10) to the REST API therefore I just had to give my custom filter a higher priority in oder to have it executed after the default WP CORS filter.
add_filter('rest_pre_serve_request', 'serve_static_resources', 11, 4);
And the warnings disappeared.

After upgrading to Php 5.5.30 and Apache 2.4 Session eror

Php 5.4 and Apache 2.2 all my website were working, after upgrading to php 5.5.30 and apache 2.4 I am getting these error message on log file on every domain on the server
[25-Nov-2015 01:55:44 UTC] PHP Warning: session_start(): Cannot send session cache limiter - headers already sent (output started at /home/mysite/public_html/qa-include/ajax/asktitle.php:76) in /home/mysite/public_html/qa-include/app/users.php on line 146
[25-Nov-2015 01:55:44 UTC] PHP Warning: Cannot modify header information - headers already sent by (output started at /home/mysite/public_html/qa-include/ajax/asktitle.php:76) in /home/mysite/public_html/qa-include/app/users.php on line 183
What should I check on the server or where do I look at?
Session info from phpinfo()
Everything set correctly????
Well my host fixed the problem,
Somehow, even session path defined in server php.ini adding this little local php.ini to the domain root with
session.save_path = "/home/mysite/tmp"
fixed this problem...

phpBB Error - PHP Warning

I have one phpBB forum on a shared hosting provider, and i get this error
[phpBB Debug] PHP Warning: in file [ROOT]/includes/auth/CAS/CAS/Client.php on line 905: session_start(): open(/hermes/phpsessions/S/T/-/Z/sess_ST-ZhPr8mYrwe, O_RDWR) failed: No such file or directory (2)
[phpBB Debug] PHP Warning: in file [ROOT]/includes/auth/CAS/CAS/Client.php on line 905: session_start(): Cannot send session cache limiter - headers already sent (output started at [ROOT]/includes/functions.php:3906)
[phpBB Debug] PHP Warning: in file [ROOT]/includes/auth/CAS/CAS/Client.php on line 1614: session_write_close(): open(/hermes/phpsessions/S/T/-/Z/sess_ST-ZhPr8mYrwe, O_RDWR) failed: No such file or directory (2)
[phpBB Debug] PHP Warning: in file [ROOT]/includes/auth/CAS/CAS/Client.php on line 1614: session_write_close(): Failed to write session data (files). Please verify that the current setting of session.save_path is correct (4;/hermes/phpsessions)
[phpBB Debug] PHP Warning: in file [ROOT]/includes/auth/CAS/CAS/Client.php on line 1618: Cannot modify header information - headers already sent by (output started at [ROOT]/includes/functions.php:3906)
the strange thing here, is that happened unexpectedly one day, it used to be working correctly. Also in my private directories i don't have any /hermes.
Make sure that session directory is writable or you can set a path yourself with:
session_save_path
This comment is also useful if you are using above function.

Wordpress - Gantry Framework

I have installed.
I installed the plugin Gantry framework and everything worked well.
When I edit wp-config.php then it appeared error ..
first i return the original wp-config.php but its same again.
The site address is http://www.balkanlife.net and the following is the issue:
Warning: session_start(): open(/tmp/sess_c8f005a6152407d7c72930471b314416, O_RDWR) failed: Permission denied (13) in /home/balkanli/public_html/wp-content/plugins/gantry/functions.php on line 182
Warning: session_start(): Cannot send session cache limiter - headers already sent (output started at /home/balkanli/public_html/wp-config.php:1) in /home/balkanli/public_html/wp-content/plugins/gantry/functions.php on line 182
Warning: Cannot modify header information - headers already sent by (output started at /home/balkanli/public_html/wp-config.php:1) in /home/balkanli/public_html/wp-content/plugins/gantry/gizmos/iphonegradients.php on line 32
Warning: Cannot modify header information - headers already sent by (output started at /home/balkanli/public_html/wp-config.php:1) in /home/balkanli/public_html/wp-content/plugins/gantry/gizmos/iphoneimages.php on line 33
Warning: Cannot modify header information - headers already sent by (output started at /home/balkanli/public_html/wp-config.php:1) in /home/balkanli/public_html/wp-content/plugins/gantry/gizmos/iphonegradients.php on line 32
Warning: Cannot modify header information - headers already sent by (output started at /home/balkanli/public_html/wp-config.php:1) in /home/balkanli/public_html/wp-content/plugins/gantry/gizmos/iphoneimages.php on line 33
Warning: Cannot modify header information - headers already sent by (output started at /home/balkanli/public_html/wp-config.php:1) in /home/balkanli/public_html/wp-content/themes/paula/widgets/viewswitcher.php on line 50
Warning: Cannot modify header information - headers already sent by (output started at /home/balkanli/public_html/wp-config.php:1) in /home/balkanli/public_html/wp-content/plugins/gantry/gizmos/iphonegradients.php on line 32
Warning: Cannot modify header information - headers already sent by (output started at /home/balkanli/public_html/wp-config.php:1) in /home/balkanli/public_html/wp-content/plugins/gantry/gizmos/iphoneimages.php on line 33
Any ideas would be most appreciated.
Tnx

phpbb3 codeigniter library session error

[phpBB Debug] PHP Notice: in file /includes/session.php on line 1024: Cannot modify header information - headers already sent by (output started at /application/libraries/phpbb_library.php:1)
[phpBB Debug] PHP Notice: in file /includes/session.php on line 1024: Cannot modify header information - headers already sent by (output started at /application/libraries/phpbb_library.php:1)
[phpBB Debug] PHP Notice: in file /includes/session.php on line 1024: Cannot modify header information - headers already sent by (output started at /application/libraries/phpbb_library.php:1)
How to fix this ?
I red in the phpbb3 library author theme, one of the posts has the same issue, and he fixed it by ‘not cloasing the controller file’, but what did he mean realy ? Sme help ?
It means that he removed ?> in the end of some php file.
But in your case all you need is just to cut off the BOM from the /application/libraries/phpbb_library.php file

Categories