Get the Referer name requested from http_request2 lib symfony1 - php

I have a query, as defined in the title, how to get the getReferer() functionality, when the called page is http_request call.
This url
How to get previous page route in Symfony? will work only when there is a page submit from previous page, then the $request->getReferer(); will get the value, But what if the previous page submit is a ajax call where in i will post only username, and the ajax call will respond with some code.
Requested:
How to Know the previous page URL When it is http_request call

Use getPathInfoArray().
$pathinfo = $request->getPathInfoArray();
$referer = $pathinfo['HTTP_REFERER'];

Related

Ajax request - determine current wordpress page in functions.php

I've tried to determine the current page in functions.php with an if (is_home()) function, because I only want to run the specific ajax request on my homepage, but it always returns false and if I request the current URI, it says /wp-admin/admin-ajax.php/wp-admin/admin-ajax.php, the URI I actually request in my JS Ajax function.
So how can I only request my current page instead of the Ajax request?
Thanks for any help!
In the javascript
var pathname = window.location.pathname;
Then you can pass it with the rest of your data to the php function.

Redirecting to another page on error with Slim Framework

I want to redirect to a page (error.php, for example) depending on the info in a form in my website. I managed to log an error like this:
if ($date > $curdate) {
return $response
->withStatus(406)
->withHeader('Content-Type', 'text/html')
->write('You can\'t select dates in the future!');
}
How can I do it so it sends you to a page with that error in particular instead of logging/requesting it in the network tab?
Right now I get this:
Request URL:http://raspberrypi/chartAPI/api/{id}/{date1}/{date2}
Request Method:POST
Status Code:406 Not Acceptable
Remote Address:192.168.0.80:80
Referrer Policy:no-referrer-when-downgrade
Which is almost working as intended. What I want to do is for it to send me to "http://raspberrypi/chartAPI/error/406" (for example), and display the contents in a file called 406.php (or error406.php, or error.php or whatever call it).
I managed to do something with this:
return $response->withRedirect("error.php");
But I get this:
Request URL:http://raspberrypi/chartAPI/api/{id}/{date1}/error.php
Request Method:GET
Status Code:405 Method Not Allowed
And slim throws this error:
Method not allowed. Must be one of: POST
Why is it removing {date2}? And why is it asking for a POST method?
This question is a continuation of this one, but due to how this website handles these "old" questions, mine got pushed down and regardless of how many edits I put, it doesn't get any attention anymore.
When you are using withRedirect, use a Route URL not a file to browse
The Error is about using GET Method Where the Route needs POST
I think this is Because you use a file to redirect to,Then the method will be Only GET not POST or others like a browser
I don't Know Why you are using POST whenever you pass parameters in URL ?!

Passing the URL of a page to a PHP POST call

I need to pass the URL of a page to a PHP POST function which will return a document. I was wondering if it is possible to pass in the URL via a function or will it have to be stored in a variable? Or is it even possible to do this? I have this function to retrieve the URL of the previous page:
$(document).ready(function() {
var referrer = document.referrer;
});
And this is the PHP POST method which does not work:
$_POST['http://<THE URL I AM SENDING THE REQUEST TO>&url=<THE URL OF THE PREVIOUS PAGE>'];
I had it set up like:
$_POST['http://<THE URL I AM SENDING THE REQUEST TO>&url=referrer'];
But it would not run. Does anyone know how I can get this to work? Thanks

How to pass value to popup window using codeigniter?

I know that you can use anchor_popup() to open up a new window in codeigniter, but what i cant figure out is how to pass values using that.
Here is the code i am using,
$attr = array('width'=>'800','height'=>'700');
echo anchor_popup('friends/'.$uid.'/'.$suid.'','add as friend',$attr);
Now i get a popup window which links to friends/34/34 where friends is a controller and rest are values which i want to give to my controller. but iam getting an error 404,
404 Page Not Found
The page you requested was not found.
I am using uri segment to grab the values.
Could any tell me what i am doing wrong?
the link friends/34/34/ is looking for a controller called "friends" and a method called "34", hence why it can't be found.
If your friends controller has no other methods, then change the link to this:
echo anchor_popup('friends/index/'.$uid.'/'.$suid,'add as friend',$attr);
else, add the appropriate method.

Get HTTP Referrer on Redirection

How can you get the HTTP Referrer when redirected from another website, not when they click on a link since it would work for $_SERVER['HTTP_REFERER'], but it doesn't work when a user has been redirected a website and the referrer would be empty.
What will be the method to get the referrer?
How can you get the HTTP Referrer when redirected from another website
You can't. If the redirection takes place under your control, you can add the original referer as a parameter, but if the external redirector doesn't do that, you have no way to get hold of the information.
An example of how I did it. Say we have 3 pages, one calling the next.
page1.com -> page2.com -> page3.com.
in page2.com get the page1.com using:
$referrer = $_SERVER['HTTP_REFERER'];//=page1.com
when redirecting to page3, send $referrer as a GET parameter
page3.com?referrer=$referrer
in page3 read the $referrer from the get.
$initialReferrer = $_GET['referrer'];//=page1.com

Categories