We just moved our Symfony2.3 project to another server and now we encounter the following problem:
The routes /login and _wdt/9d5405 result in a ERR_EMPTY_RESPONSE error in Google Chrome (and all other browsers showing their specific error messages). The error occurs in both, prod and dev environment.
I tracked down the issue from my loginAction
/**
* #Route("/login", name="login")
* #Route("/login/{redirect}", name="login_redirect")
* #Template()
*/
public function loginAction($redirect = '')
{
if ($this->getUser())
{
return $this->redirect($this->generateUrl('crea_frontend_index'));
}
$request = $this->getRequest();
$session = $request->getSession();
// get the login error if there is one
if ($request->attributes->has(SecurityContext::AUTHENTICATION_ERROR))
{
$error = $request->attributes->get(
SecurityContext::AUTHENTICATION_ERROR
);
}
else
{
$error = $session->get(SecurityContext::AUTHENTICATION_ERROR);
$session->remove(SecurityContext::AUTHENTICATION_ERROR);
}
$redirect = urldecode($redirect);
return array(
'last_username' => $session->get(SecurityContext::LAST_USERNAME), // last username entered by the user
'redirect' => $redirect,
'error' => $error,
);
}
This line produces the error:
$error = $session->get(SecurityContext::AUTHENTICATION_ERROR);
And I tracked it down to
Symfony/Component/HttpFoundation/Session/Storage/NativeSessionStorage.php
and there in line 148 if (!session_start()) {.
So it turnes out that session_start at this point produces the error but when I add a session_start(); to app.php and comment everything else it works.
Now I am completely puzzled on how to fix this. Any ideas on how to solve this or just how to further debug would be very appriciated.
PHP 5.4.20
No errors in logfiles
UPDATE
The error seems to be somehow related to these bug discussions:
https://bugs.launchpad.net/ubuntu/+source/php5/+bug/424789
https://bugs.gentoo.org/show_bug.cgi?id=276583
UPDATE
Solved: The Problem was the PHP Version 5.4.20. We tested 5.3.17 and 5.5.9. Both function well. Except 5.4.20. But I still want to know what exaclty causes this error. This could then result in a Symfony fix to deal with this version.
Related
I am running into an issue where I'm getting the following error in my laravel.log file.
[2020-12-20 13:43:43] production.ERROR: URI must be a string or UriInterface
However my code works in development, which is super weird. I'm trying to figure out why this isn't working and i'm just really at a loss and no amount of googling or searching here has answered my question as to why in development vs production this error is occuring.
Heres my function:
/**
* Returns the user avatar or the placeholder avatar
* depending on the Discord Status Code
*
* #param \App\Models\Auth\User $user
* #return \Illuminate\Http\RedirectResponse|mixed|string
*/
public static function getUserAvatar(\App\Models\Auth\User $user) {
$client = new Client();
try {
$response = $client->head($user->avatar);
} catch(BadResponseException $e) {
return "https://dummyimage.com/128x128/888ea8/ebedf2.png?text=No+Image+Found";
}
if($response->getStatusCode() == 200) {
return $user->avatar;
} else {
return "https://dummyimage.com/128x128/888ea8/ebedf2.png?text=No+Image+Found";
}
}
The main functionality is this... whenever a User logs in, their avatar updates from discord (using socialite as the login provider). However if the user changes their avatar in discord, but hasn't logged into our site in a while, that avatar link will just go dead as discord no longer wants to serve it. So the avatar link returns a 404 code. I'm basically just trying to handle this 404 code and not display a broken image on the site. Rather it just be a placeholder image instead.
Edit: When i die and dump on $user->avatar I get the following result:
I've also tried the following as well to no avail:
$response = $client->request('GET', (string) $user->avatar, ['allow_redirects' => false, 'verify' => false]);
Thanks.
Laravel JWTAuth::encode , JWTAuth::attemp , JWTAuth::fromUser, unable to create a token, and throwing error
Thats the whole response I am getting,
Error Response Image a
Error Response Image b
the login route in routes.php is like this:
Route::post('auth/login','authController#login');
and the login function in authController.php is like this:
function login(Request $request){
$user = User::where('email', '=',$request['email'])
->first(['first_name', 'last_name', 'email', 'id', 'hashed_password']);
// if email and password is wrong
if(count($user) <= 0 )
return response(["success"=>false,"message"=>"Authentication failed, wrong credentials"],401);
//sendResponse(false, "Authentication failed, wrong credentials", null, 401);
if (!Hash::check($request['password'], $user['hashed_password']))
{
return response(["success"=>false,"message"=>"Authentication failed, wrong credentials"],401);
}
try{
// attemp to verify the credentials and create a token for the user
$payload = JWTFactory::make($user['original']);
$token = JWTAuth::encode($payload);
$user['jwt'] = $token;
$user->save();
}
catch(Exception $e){
// something went wrong while creating token or updating user
return response(["success"=>false,"message"=>"There's something wrong, we will get back to you soon."],400);
}
$content['message'] = "Successfully Login";
$content['success'] = true;
$content['token'] = $user['jwt'];
$content['data']['first_name'] = $user['first_name'];
$content['data']['last_name'] = $user['last_name'];
$content['data']['email'] = $user['email'];
return response($content,200)
->header('Content-Type', "application/json");
}
I am stuck on this error for two days, and still unable to find a solution. Tried to maximize the nesting level by adding the following line in my php.ini
;xdebug.max_nesting_level=1000
but it didn't work.
Kindly help.
Looking at your error message, it is still acting on the default xdebug.max_nesting_level.
From what you've showed that you changed in your php.ini file - you've updated your xdebug.max_nesting_level but left it commented out so that it won't take any affect.
You need to uncomment it by removing the ; before it, so that it looks like this:
xdebug.max_nesting_level=1000
Then restart your services for it to take affect.
I'm having an issue with my correctly displaying my URLs for my website. I'm using the latest version of Codeigniter.
I'm getting the below error message. I was doing some research and I think my issue is URI segments but I'm perplexed as to how to fix the problem.
My goal is to get the URL to look nice this
(_states is a sub directory folder on my localhost)
mydomain.com/_states/dealers/Florida (This URL actually works)
mydomain.com/_states/dealers/Florida/Miami (not working)
mydomain.com/_states/dealers/Florida/Miami/8 (not working)
I've also provided the syntax for my routes.php and model_data.php. How would you guys going about fixing this problem? Thanks everyone in advance.
A PHP Error was encountered
Severity: Warning
Message: Missing argument 2 for Site::getDealersCity()
Filename: controllers/site.php
Line Number: 43
A PHP Error was encountered
Severity: Notice
Message: Undefined variable: city
Filename: controllers/site.php
Line Number: 47
Site Controller
public function getDealersCity($state, $city){
//$city = $this->uri->segment(3);
//echo "$city";
if(is_null($state)) return false;
if(is_null($city)) return false;
$this->load->model('model_data');
$data['statecity'] = $this->model_data->get_database_by_cities($state,$city);
$this->load->view('statecity',$data);
}
Model_data.php function
function get_database_by_cities($state, $city){
$query = $this->db->get_where('states',
array('state' => $state,
'city' => $city)
);
if($query->num_rows()) return $query->result();
return null;
}
Routes.php
$route['default_controller'] = "site";
$route['dealers/(:any)/(:any)'] = "site/getUniqueDealerInfo/$3";
$route['dealers/(:any)/(:any)'] = "site/getDealersCity/$2";
$route['dealers/(:any)'] = "site/getCities/$1";
$route['404_override'] = '';
$route['dealers/(:any)/(:any)'] = "site/getUniqueDealerInfo/$3";
$route['dealers/(:any)/(:any)'] = "site/getDealersCity/$2";
The routes are conflicting in nature, one route overrides other.
Try using
$route['dealers/(:any)/(:any)'] = "site/getDealersCity/$1/$2";
And there is no function for
getUniqueDealerInfo
Have a look at the answers here Similar Question
I'm running into a problem I just can't seem to fix. I'm working on kind of a CMS kind of thing. And one of the functions is making image slideshows.
In one controller, I check if a slideshow with a certain ID exists, and if it exists, it should take the data and work with it, otherwise, set an error message (CodeIgniter flashdata) and redirect to the homepage.
The code I use for this is the following:
if($this->Mslideshow->slideshowExists($showid) === FALSE){
echo 'I\'m getting here';
$this->session->set_flashdata('error',$showid);
redirect('admin/index','refresh');
}else{
echo 'Slideshow exists';
}
And the code of the slideshowExists() function is:
public function slideshowExists($showid)
{
$this->db->where('id',$showid)
->limit(1);
$query = $this->db->get('slideshows');
if($query->num_rows() < 1){
return FALSE;
}
$this->currentquery = $query;
return TRUE;
}
And the problem is this, very strange actually. If the result I get back is FALSE, everything goes as planned. Error message gets set and redirect goes to 'admin/index'.
But if what I get back is TRUE, then the stange thing happens. I do get an echo with 'Slideshow exists', but I also get the error message.
I've tried everything, deleted cookies. Reset all sessions etc.
And even stranger is that when I tried to put the $showid I use to check into the error message, all of a sudden $showid is ' img '. While everywhere else is '1' or '2'...
Hope someone can help. Thanks!
=====EDIT=====
I tried to edit the code and simplify it. Right now I have this code in my Controller:
public function slideshow($showid){
$query = $this->db->where('id',$showid)->get('slideshows');
if($query->num_rows() < 1){
$this->session->set_flashdata('error','Slideshow doesn\'t exist.');
redirect('admin/index','refresh');
}
$data['page'] = 'slideshow';
$data['title'] = 'Slideshows';
$this->scripts->load_scripts(array());
$this->scripts->load_functions(array());
$this->load->view('admin/dashboard_template.php',$data);
}
When I run this with a $showid, that doesn't exist, I get the error message after being redirected to 'admin/index'. When I use a $showid that does exist, I do get the error, but no redirect but just the rest of the code.
I think you have to read your flash data in your view:
$error = $this->session->flashdata('error');
var_dump($error);
or in your Controller:
$error = $this->session->flashdata('error');
if(isset($error)) {
var_dump($error);
}
Also you can read this question: CodeIgniter "flashdata" doesn't work
you can get the flash data by following way
$error = $this->session->flashdata('error');
if($error)
{
echo $error;
}
You can try
if($this->session->flashdata('msg') != "")
This works for me.
I'm trying to unit-test my controller (Yii framework).
/**
* #dataProvider provider
*/
public function testActionEdit_view_login($controller){
$user = new CWebUser;
$user->id = 978;
$identity = new UserIdentity('me#test.com', '123456');
$user->login($identity);
$controller->actionEdit();
$output = ob_get_contents();
assertContains('Add/Change Profile Picture:', $output);
assertContains('bio', $output);
assertContains('specialties', $output);
assertContains('change login', $output);
assertContains('New Password', $output);
}
When I do
$user->login($identity);
in order to login, I get the following error:
session_regenerate_id(): Cannot regenerate session id - headers already sent
I've already tried buffering the output by putting this at the beginning of the class:
public static function setUpBeforeClass(){
ob_start();
}
I also put ob_clean() in setUp() and ob_end_clean() in tearDownAfterClass().
Still I get the message that headers have already been sent. There are no spaces or newlines in the file, when I comment out the specific test method, it works perfectly. The login() seems to cause the problem.
Anyone got ideas how to prevent this / maybe unit-test the controller differently?
Thanks,
MrB
Before your call to $user->login, add the following code:
$mockSession = $this->getMock('CHttpSession', array('regenerateID'));
Yii::app()->setComponent('session', $mockSession);
This overwrites the regenerateID method with a method that does nothing.
Adding ob_start() to the bootstrap also works, but there is no output from PHPUnit until everything has completed.
With this method, you can still see the progress as it is happening.
I upgraded from Yii 1.1.7 to 1.1.10 and the regenerateID method was added in 1.1.8 so I got this error today.
Got it. I had included some Yii files before the ob_start(), which seem to have printed the headers. Now I buffer that, too.