Req:header("referer") is current url, not where the request originated

607 views
Skip to first unread message

Caiyun Deng

unread,
May 26, 2015, 9:07:00 AM5/26/15
to chica...@googlegroups.com
Hi!
Req:header("referer") is current url, not where the request originated.
Do i use it by the wrong way?

Kai Janson

unread,
May 26, 2015, 3:48:01 PM5/26/15
to chica...@googlegroups.com
In afraid that a bit more surrounding code is needed to understand your problem.  The usage is correct.

--Kai 

Sent from my iPhone
--
You received this message because you are subscribed to the Google Groups "ChicagoBoss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to chicagoboss...@googlegroups.com.
Visit this group at http://groups.google.com/group/chicagoboss.
To view this discussion on the web visit https://groups.google.com/d/msgid/chicagoboss/0dc7404d-7b58-4c14-8484-3a47e1bfca47%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

can2nac

unread,
May 27, 2015, 11:34:34 AM5/27/15
to chica...@googlegroups.com
It is "where the request originated."
Post your code and Req:header()

Evgeny M

unread,
May 27, 2015, 7:49:16 PM5/27/15
to chica...@googlegroups.com
Maybe you call this in a script/json returning controller? Any javascript file included in a page will have referer equal to the page url.

вторник, 26 мая 2015 г., 16:07:00 UTC+3 пользователь Caiyun Deng написал:

Jesse Gumm

unread,
May 28, 2015, 3:44:11 PM5/28/15
to chica...@googlegroups.com
Indeed, the context in which this is being called is important.  If being checked, for example, from a dynamically generated image (inside a <img> tag), the referer header would end up being the current URL of the page.

AFAIK, the header("http_referer") is working properly, since it's simply passing the request for that header to the underlying server.

-Jesse

--
You received this message because you are subscribed to the Google Groups "ChicagoBoss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to chicagoboss...@googlegroups.com.
Visit this group at http://groups.google.com/group/chicagoboss.

For more options, visit https://groups.google.com/d/optout.



--
Jesse Gumm
Owner, Sigma Star Systems
414.940.4866 || sigma-star.com || @jessegumm

Caiyun Deng

unread,
May 28, 2015, 11:56:18 PM5/28/15
to chica...@googlegroups.com
I click the link from view/game/game_list.html, My html is:
    <div class="col-sm-{{ col_num }}">
      <div class="thumbnail">
        <a href="/game/subject/{{ game.id }}">
          <img src="/static/img/game_logo/{{ game.id }}.png">
          <div class="text-center">
            <span>{{ game.name }}</span>
          </div>
        </a>
      </div>
    </div>

And the controller's code:
-module(yxq_game_controller, [Req]).
-compile(export_all).
-include("yxq.hrl").  
-include("deps/mysql/src/mysql.hrl").
-include("deps/simple_bridge/include/simple_bridge.hrl").

before_(Action, Arg1, Arg2) ->
    ?TRACE_VAR(Req:header(http_referer)),
    ?TRACE_VAR(Req:header(referer)),

And the print result is:
******
Module: yxq_game_controller, Line: 41, 
My print's "Req : header ( http_referer )" is undefined
******

******
Module: yxq_game_controller, Line: 41, 
My print's "Req : header ( referer )" is "http://localhost:8006/game/subject/1"
******
11:50:51.680 [notice] Request Method: 'POST', Tokens: []

Req:header(http_referer) is undefined, Req:header(referer) is current url, not http://localhost:8006/game/game_list

can2nac

unread,
May 29, 2015, 9:58:15 AM5/29/15
to chica...@googlegroups.com
post Req:header(), the full headre as it is, do not cut out a part of it.


On Tuesday, May 26, 2015 at 4:07:00 PM UTC+3, Caiyun Deng wrote:

Caiyun Deng

unread,
May 31, 2015, 11:39:45 PM5/31/15
to chica...@googlegroups.com
Req:header() will be "Unhandled Error: error:undef"

在 2015年5月29日星期五 UTC+8下午9:58:15,can2nac写道:

Jesse Gumm

unread,
May 31, 2015, 11:54:25 PM5/31/15
to chica...@googlegroups.com

I think he means Req:headers(), which should return all headers in the request.

-Jesse

--
You received this message because you are subscribed to the Google Groups "ChicagoBoss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to chicagoboss...@googlegroups.com.
Visit this group at http://groups.google.com/group/chicagoboss.

Caiyun Deng

unread,
Jun 1, 2015, 4:06:40 AM6/1/15
to chica...@googlegroups.com
******
Module: yxq_game_controller, Line: 41, 
My print's "Req : headers ( )" is [{connection,"keep-alive"},
                                   {accept,"*/*"},
                                   {host,"192.168.1.236:8006"},
                                   {connection,"keep-alive"},
                                   {accept,"*/*"},
                                   {host,"192.168.1.236:8006"},
                                   {referer,
                                       "http://192.168.1.236:8006/game/subject/1"},
                                   {user_agent,
                                       "Mozilla/5.0 (Windows NT 5.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/37.0.2062.103 Safari/537.36"},
                                   {accept_language,"zh-CN,zh;q=0.8"},
                                   {cookie,
                                       "account_id=10; session_id=c228c97902478325ba6f03464fbf1a28"},
                                   {content_length,"14"},
                                   {content_type,
                                       "application/x-www-form-urlencoded; charset=UTF-8"},
                                   {accept_encoding,"gzip,deflate"}]
******

******
Module: yxq_game_controller, Line: 41, 
My print's "Req : header ( referer )" is "http://192.168.1.236:8006/game/subject/1"
******
It is the same.

can2nac

unread,
Jun 1, 2015, 10:59:21 AM6/1/15
to chica...@googlegroups.com
Could you post the whole Req?

On Tuesday, May 26, 2015 at 4:07:00 PM UTC+3, Caiyun Deng wrote:

Caiyun Deng

unread,
Jun 1, 2015, 10:50:52 PM6/1/15
to chica...@googlegroups.com
Module: yxq_game_controller, Line: 41, 
My print's "Req" is {simple_bridge_request_wrapper,mochiweb_request_bridge,
                        {mochicow_request,#Port<0.72165>,'POST',
                            "/game/get_another_recommend_game",'HTTP/1.1',
                            {12,
                             {"host",
                              {"host","localhost:8006"},
                              {"connection",
                               {"connection","keep-alive"},
                               {"accept",
                                {"accept","*/*"},
                                nil,
                                {"accept-encoding",
                                 {"accept-encoding","gzip, deflate"},
                                 nil,
                                 {"accept-language",
                                  {"accept-language",
                                   "zh-CN,zh;q=0.8,en;q=0.6"},
                                  nil,nil}}},
                               {"content-length",
                                {"content-length","14"},
                                nil,
                                {"content-type",
                                 {"content-type",
                                  "application/x-www-form-urlencoded; charset=UTF-8"},
                                 nil,
                                 {"cookie",
                                  {"cookie",
                                   "account_id=10; session_id=c228c97902478325ba6f03464fbf1a28"},
                                  nil,nil}}}},
                              {"origin",
                               {"origin","http://localhost:8006"},
                               nil,
                               {"x-requested-with",
                                {"x-requested-with","XMLHttpRequest"},
                                {"user-agent",
                                 {"user-agent",
                                  "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/43.0.2357.65 Safari/537.36"},
                                 {"referer",
                                  {"referer",
                                   "http://localhost:8006/game/subject/1"},
                                  nil,nil},
                                 nil},
                                nil}}}},
                            <<"last_game_id=0">>},
                        false,[],[],none}
******


在 2015年6月1日星期一 UTC+8下午10:59:21,can2nac写道:

Jesse Gumm

unread,
Jun 1, 2015, 11:47:21 PM6/1/15
to chica...@googlegroups.com

The fact that there's a POST request in there is interesting, and likely the cause of confusion.

The Post must be originating from the original request, because a simple link from an <a href> link will generate a GET request.

Find the source of the post and youll have your culprit. I'd bet some Javascript is doing it on page load.

-Jesse

--
You received this message because you are subscribed to the Google Groups "ChicagoBoss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to chicagoboss...@googlegroups.com.
Visit this group at http://groups.google.com/group/chicagoboss.

Caiyun Deng

unread,
Jun 2, 2015, 7:39:38 AM6/2/15
to chica...@googlegroups.com
You are right.
sorry!  it is my fault.

在 2015年6月2日星期二 UTC+8上午11:47:21,Jesse Gumm写道:

Jesse Gumm

unread,
Jun 2, 2015, 7:41:09 AM6/2/15
to chica...@googlegroups.com

Excellent! Glad it was solved!

-Jesse

Reply all
Reply to author
Forward
0 new messages