I cannot get the response object to work and I have tried many implementations referenced by the documentation. I don't have an external configuration for the response object, only what is in the code below.
When this code is run an empty page is displayed (there is no view linked with this action). I get no error messages in the browser / apache / php logs either.
I've checked the path to the controllers directory, which is located at:
"__ DIR __ . '/../controllers/'"
My code:
public function sendAction()
{
$this->response->redirect("contact/index");
}
If I place the following code at the top of the method, I see the expected page...
echo phpInfo();
die();
I have tried all combinations below:
$this->response->redirect("contact/index");
// Example shown in Phalcon Docs
$this->response->redirect("http://en.wikipedia.org", true);
return $this->response->redirect("http://en.wikipedia.org", true);
// Should navigate to the base URI
$this->response->redirect();
return $this->response->redirect();
// Creating a new instance of \Phalcon\Http\Response
$resp = new \Phalcon\Http\Response();
$resp->redirect("http://en.wikipedia.org", true);
I'm really not sure what else to try. I have scoured forums and documentation but haven't found anything that solves my issue.
Yes this question has been asked before but the answer didn't help!
I'm running Phalcon 2.0.1 | PHP 5.6.27 | Chrome v.54 | OSX 10.12
My opinion is that the code isn't wrong, but something must not be configured properly. I have tried installing php and Phalcon a couple of times, neither went smoothly and I downloaded a number of required packages and missing elements as I came across them trying to install. I then backed up my data and wiped my hard drive to start fresh, but the problem persists.
I had the same issue. Even if the official documentation makes examples like this
// Redirect to the default URI
$response->redirect();
// Redirect to the local base URI
$response->redirect("posts/index");
// Redirect to an external URL
$response->redirect("http://en.wikipedia.org", true);
// Redirect specifying the HTTP status code
$response->redirect("http://www.example.com/new-location", true, 301);
The only way it worked for me was returning the response send method. I hope it solves your problem too.
$this->response->redirect("http://en.wikipedia.org", true, 302);
return $this->response->send();
Related
I have a very special problem and I don't know how to deal with it.
I have web App in Laravel, when i open index page, I receive text message to my mobile phone.
Problem is, sometimes I receive 2 messages or 3, sometimes 1.
Is there a tool how to debug this strange behavior which is not always the same?
A few words about my code:
user opens the page, and because its first visit Session doesn't have attribute message_sent and SendTextMessage::SendMessage($phoneNumber, $id_message, $smsCode, $newDateFormat); is executed. After that Session has message_sent and can't be sent again, for example if I refresh the page.
SendTextMessage::SendMessage() is Class in Laravel Helpers.
controller code:
public function index($url_attribute, $id_message, Request $request)
{
if(!Session::has('message_sent'))
{
$user = User::where('id_message', $id_message)->first()->toArray();
$phoneNumber = $user['mobile_phone'];
$smsCode = $user['sms_code'];
$newDateFormat = date("d.m.yy", strtotime($smsExpirationTime));
$request->session()->flash('message', 'Text message sended.' );
SendTextMessage::SendMessage($phoneNumber,$id_message, $smsCode, $newDateFormat);
Session::put('message_sent', true);
}
return view('login');
}
SendTextMessage Class:
class SendTextMessage
{
public static function SendMessage($phoneNumber, $id_message, $smsCode, $newDateFormat)
{
$sms = new Connect();
$sms->Create("user","pass",Connect::AUTH_PLAIN);
$sms->Send_SMS($phoneNumber,"Message");
$sms->Logout();
}
}
Many thanks for any tip or help.
UPDATE:
problem is only in Chrome.
Edge and internet explorer are fine.
As this script runs on server-side the browser shouldn't be an issue. Based on your code provided, there is no clear answer to give here.
Please try the following in order to debug your problem:
Log messages at each stage of the script in order to see which part was called how often. That will help you to locate the problem. You can use \Log::error("Message") to do that.
Once you know where the problem might be, try to log "decision" making / mission critical variables to logile as well. E.g. \Log::error($session) so that you can understand why that problem might occur. One reason could be that you have a bad configured session caching or your cookies might be messed up. At some point there is probably a piece of data not the way you expect it to be.
You should maybe try to change the way you use Laravel Session.
You indicated that it was working fine on some browsers, that means your server-side code is correct so far, but there is someting messing with Chrome… From there,
if you take a quick look at the Laravel Session doc, you'll see that Session can be stored in cookies, and I bet that this is your actual setup (check in your .env file the SESSION_DRIVER constant, or in your config/session.php file).
If so, to confirm that this cookies-based session setting is the culprit, you might want to change the Session config to make it browser-independent: any other option than cookies will work, the database or file options might be the easier to setup… And if it works I would strongly encourage you to keep using this no-cookie setting to make your code browser-safe.
I'm facing weird problem which a bit complicated to understand. So the situation is that:
we have 2 installs (actually more, but not relevant for now)
both installs places on same server (apache + nginx)
we update our code and therefore deploy to staging - first install works great, second one has problem.
the code is 100% percent the same
there is no influence of other plugin (wordpress) on the specific part of code
The relevant code is the following:
$track = new trackClass();
$track->store_parameters();
$parameters = unserialize($track->parameters);
class trackClass // this class sits on different file
{
public $parameters;
public function __construct() {
...
}
method...
method...
method ..
public function store_parameters()
{
...
}
}
Before we modify our code, the function store_parameters was private, now its public.
So when on the second install the code is running its raise an error that the store_paramters() function is private and not accessible (remind you that it happens only on the second install).
I tried another thing get_class_methods($track) and the response was all the methods except the store_parameters(). Again - weird.
Next step, put wp_die('test') in the top of the file of the class. Refreshing the page and all as usual (the file is definitely loaded). If I try to access the admin (wp-admin) the changes make difference - the page is killed, blank screen and 'test' on it.
Next step, remove this file completely from the server. Refreshing the page and nothing happen. Their is ajax request from the class file which run as usual, like the file is exists and everything is ok. Again, going to the admin page and the error is raised (require_once ... not found).
Its doesn't seems like its code or development problem. The code is same. I'm afraid that its something on the server side / environment (apache, nginx) but unfortunately I've no access to the linux, I only can chat with the support of the hosting company.
They are insists that is code problem. No matter the tests I wrote above.
What can cause this kind of problem? I'm losing my mind here with no lead, its like the file is stuck somewhere.
I already posted the similar question to another thread, the reason I re posted it is that I got into problem deeper and can explain it more.
Actual Problem: I am using a library from barryvdh/laravel-cors and when an error/exception happens this library does not set the headers and it keep saying No 'Access-Control-Allow-Origin' header is present on the requested resource.
Let say I have a simple function like this:
public function store(Request $request){
return response()->json(['message' => 'coming without any problem']);
}
which works perfectly fine, and I have the other case with syntax error:
public function store(Request $request){
return response()->json(['message' => 'coming with problem'); // missing ']' before the end parenthesis....
}
This should normally throw an exception by Laravel, but for me it shows 'Access-Control-Allow-Origin'.
Well, you might ask, why do I need this to fix, is that when my code is more complex, I dont see the actuall error that will help me to fix it or at least google it...
Anyone had the same issue before and have any idea how to fix this thing?
I am using Laravel 5.0
This has to do with "cross-origin HTTP request" that can be a mix of front end and backend issues.
http://www.html5rocks.com/en/tutorials/cors/
You may need to change some settings in your web server settings or on your .htaccess file located in the script folder.
Check this: http://enable-cors.org/server.html
In terms of front end, Mozilla tends to be a little more conservative about CORS, so check their docs. If you do it well for firefox, it will work well on other browsers too.
https://developer.mozilla.org/en-US/docs/Web/HTTP/Access_control_CORS
I have HHVM running on a virtualbox VM, with the webroot mapping to my local laravel install, being served out at an internal IP.
Locally, I'm serving the site out under http://[localhost]:8000.
The codebase is identical.
code of MembersController.php (resourceful controller):
public function show($id)
{
$member = Member::findOrFail($id);
$data = array();
$data['id'] = $member->id;
$data['first_name'] = $member->first_name;
$data['last_name'] = $member->last_name;
return Response::json($data);
}
Assuming everything is working normally:
When I run a GET request to LOCALHOST: http://[localhost]:8000/api/v1/member/1, the client returns the JSON as normal - all good.
When I run a GET request to HHVM (same client, identical codebase): http://[vm_ip_address]/api/v1/member/1, the client receives no data.
The data is being passed back through the calls within HHVM though, as if I change the 'return' to 'echo', the payload is returned in both cases (headers also)
It looks like HHVM is affecting with laravel's Response::json() function and disallowing the reply contents from being displayed in the client.
Has anyone else seen this?
This is not something I can set up a unit test for, as it always passes, because the final reply always has data in it :/
Any input would be great - I'm interested to learn how to get around this.
Thanks.
Sadly you're probably going to have to get your hands dirty debugging. HHVM probably has a very slight difference in how it does something which this code-path is sensitive to. We pass 100% of laravel unit tests, but there probably isn't one covering this case.
If you can, please trace down the code to where the data changes. Put in echos and error_logs until you can build a very small test case then then open an issue on github and we'll get it fixed.
First: please forgive me - Im a bit of a novice as some of this...
I have a working test site which is running the php facebook SDK to perform some simple graphAPI requests successfully. Namely read a group's feed, which the user is a member of, and process this and display it back on a webpage.
This all works fine, the problem I have encountered is when trying to perform the same request via a php curl POST to another webpage (on the same domain). It seems that the SDK does not carry the expected session to another page when a post request is formed (see "AUTH ERROR2" in code)...this works fine when the following file is included via a "require_once" but not when a curl is made.
I would much rather do a "curl" as Im finding when a "require_once" is done from a page in a different directory level, Im getting php errors of the page not being found - which is expected.
I may just be tackling this problem all wrong...there may be a simpler way to make sure when files are includes, their correct directly level remains intact, or there may be a way to send over the currently authorised facebook sdk session via a curl post. All of which I have tried to no avail, and I would really appreciate any help or advise on this.
Thank you for your time.
//readGroupPosts.inc.php
function readGroupPosts($postVars)
{
//$access_token = $postVars[0];
// ^-- I'm presuming I need this? I have been experimenting appending it to
// the graphAPI request to no success...
$groupID = $postVars[1];
$limit = $postVars[2];
require_once("authFb.inc.php"); //link to the facebookSDK & other stuff
if ($user) {
try {
$groupFeed = $facebook->api("/$groupID/feed?limit=$limit"); //limit=0 returns all;
$groupFeed = $groupFeed['data']; //removes first tier of array for simpler access
$postArray;
for($i=0; $i<count($groupFeed); $i++)
{
$postArray[$i] = array($groupFeed[$i]['from']['name'], $groupFeed[$i]['message'], $groupFeed[$i]['updated_time'], count($groupFeed[$i]['likes']['data']));
}
return $postArray;
} catch (FacebookApiException $e) {
error_log($e);
$user = null;
return "AUTH ERROR1"; //for testing..
}
}
else
{
return "AUTH ERROR2"; //no user is authenticated i.e. $user == null..
}
}
I would much rather do a "curl" as Im finding when a "require_once" is done from a page in a different directory level, Im getting php errors of the page not being found - which is expected.
I may just be tackling this problem all wrong...
Definitively.
Using cURL as a “workaround” just because you’re not able to find your way around your server’s file system is an outrageous idea. Don’t do it. Stop even thinking about it. Now.
there may be a simpler way to make sure when files are includes, their correct directly level remains intact
Yes – for example, to use absolute paths instead of relative ones. Prefixing the path with the value of $_SERVER['DOCUMENT_ROOT'] for example – that way, once you’ve given the path correctly in respect to this “base path”, it does not matter where you’re requiring the file from, because an absolute path is the same no matter from where you look at it.
(And since this is not a Facebook-related problem at all, but just concerns basics of PHP and server-side programming, I’ll edit the tags.)