problem to get the Referer page - tcl

I'm trying to get the referer page, but i have a problem , sometimes i get bad the referer page,
for example:
i have 3 pages, when the page 1 link to page 2 , and the page 2 make a process and after redirect to page 3, so when i try to get the referer page in the page 3, i get the page 1 and not the page 2,
I think that the problem is the page 2 this page doesn´t show anything to the user, is only a page who make a procedure.
Do you have any idea how i can to get the referer page correctly??
Thanks.
I'm using TCL with openacs

It's difficult to answer without knowing exactly what you're trying to do. If page 2 is only calling a procedure, what about putting the contents of page 2 into an ad_proc, and then calling that proc in page 3? Or can page 2 redirect to other places when it is finished?
If you give more info, I'm sure I can help. The normal way I would pass referer info in OpenACS is to use a variable called return_url, which I pass from one page to the next as a hidden form element. There are lots of examples of that in OpenACS. Alternatively you could use ad_set_client_property to store it on page 1 and then on page 3 use ad_get_client_property to read it.

Thanks to everyone,
I already solve my problem using the < meta HTTP-EQUIV="REFRESH" content="0; url=page3" >, but in openacs there is a function that do it.
I relplace the
ad_returnredirect
by
util_ReturnMetaRefresh
so in this way i already can read the correct referer page

how are you sending the user from page 2 to page 3? with php:
enter code hereheader("location:")
or html redirect?
if you are using header("location:") it will probably not work. try using html redirect like
<meta HTTP-EQUIV="REFRESH" content="0; url=page3">

Related

How to redirect from POST to Get?

I have an HTML Page A that receives a POST method from a third-party server.
I would like to redirect Page A immediatly to Page B using GET Method. (For some other technical reasons the third-party server cannot communicate directly with page B...)
Is there any way to redirect from the POST Method on Page A to GET in Page B ? I don't care about parameters to be redirected...
I tried the following :
Add "Location" header in the POST response : Doesn't work.
Add the following javascript in Page A : Basically when Page A is loaded, it redirects
to Page B. It works but not very elegant.
<script>window.location.href = "http://stackoverflow.com";</script>
I was wondering if there is a better way to do that please ?
Thanks.
Thanks #Evert.
The answer is :
Add "Location" header in the POST response with 301 HTTP code.

How can I differentiate between two url requests from different HTML pages but with the same namespace in views.py?

I am creating a simple eBay like e-commerce website to get introduced with django. For removing an item from the watchlist, I placed two same links in two different HTML files, that is, I can either remove the item from the watchlist.html page or either from the item's page which was saved as listing.html. The url for both the pages look like this:
Remove from watchlist
Now, in my views.py, I want to render different pages on the basis of the request. For example, if someone clicked Remove from watchlist from listing.html then the link should redirect again to listing.html and same goes for the watchlist.html.
I tried using request.resolver_match.view_name but this gave me 'removeFromWatchlist' as the url namespace for both of these request is same.
Is there any way I can render two different HTML pages based on the origin of the url request?
Also, this is my second question here so apologies for incorrect or bad formatting.
You could check the HTTP_REFERER in the request.META attribute of the view to get the url that referred the request as so:
from django.shortcuts import redirect
def myview(request):
...
return redirect(request.META.get("HTTP_REFERER"))#Or however you prefer redirecting
https://docs.djangoproject.com/en/3.1/ref/request-response/#django.http.HttpRequest.META

How would I make a meta redirect that redirects to the URL stored in the parameter?

I am attempting to setup a service which will redirect the user to a URL stored in the ?url= parameter, how would I do this?
I have tried using meta
http-equiv="refresh"
with
out.print(request.getParameter("ur;")) %>
however all that happens is the page reloads in a loop. Not too sure if I need to use quotation marks (e.g /?url="https://google.com")
<meta http-equiv="refresh"
content="0; URL="<%
out.print(request.getParameter("redirect")) %>">
What I need to happen is when the user gets redirected to "https://example.com/exampledir/index.html?url=https://anotherwebsite.com" (just an example url) the script on index.html will get the parameter and redirect to it exactly. What actually happens is the page just reloads in a loop.
Since you're not using any server-side language, you won't be able to generate a different meta tag during rendering. Instead, you'll need to do this with JavaScript after the page loads.
Add a script tag to the bottom of the page like this:
<script>
var redirect = new URL(window.location).searchParams.get('redirect');
if (redirect) window.location = redirect;
</script>
Now if you browse to the page like this: http://<myserver>/myfile.html?redirect=https://google.com you'll be redirected to https://google.com.
For reference, see MDN articles on:
Window.location
URL.searchParams
I also highly recommend you read through Java​Script basics just to make sure you understand the overall concepts presented here.

html scroll down to div over django view

I'm kinda new to django and html and I wanted to know if its possible to scroll down a page to a div id by using a django view. (without using javascript)
In my html code I have something like:
<form type="POST" action="/submit_comment/">
...
</form>
Then in my urls I have:
url(r'^submit_message/$',page_views.Vep_submit_message),
And normally when a comment is submited, I process the form, and check for errors etc, then I render the previous page with the new information.
The problem is that it is a long page and I'd like to display the page scrolled to the comments div.
the comments div has an id, so normally by using /submit_message/#comments or /submit_message#comments/the window should get scrolled.
But it seems that django has some problems handling this:
You called this URL via POST, but the URL doesn't end in a slash and you have APPEND_SLASH set. Django can't redirect to the slash URL while maintaining POST data.
Is it possible to do something without javascript? Thanks!
I found a simple solution by adding the following meta
<meta http-equiv="refresh" content="0; url=#comments">

301 or 303 redirect in html meta tag?

Recently I have moved my content from oldURL to newURL and I want to attain 301 redirect(document moved permanently), to achieve that I have used new html appology page with meta tag having the new url and http-equip="Refresh", something like follows;
<meta http-equiv="Refresh" content="0; url="newURL" />
I want to know that, will it return status code 301 or status code 303 ?
Also, if it is 303, please suggest me any better way that how should I achieve 301 redirect.
Thanks in advance.
I want to know that, will it return status code 301 or status code 303 ?
No. Meta elements in an HTML document are not handled at the HTTP level.
The HTTP status will be whatever the HTTP headers say (probably 200).
Use HTTP for redirects, not Meta.
You can do one of these two solutions. You can either :-
Create an htaccess file redirecting you to the new URL. There's more on how to do the task mentioned above here.
You can create a small error template in your old URL stating that it has been moved and post the link to your new URL.
In my opinion, I would recommend you doing the former because the user will not know the transition between pages.