Welcome Guest, Not a member yet? Register   Sign In
Add key to header in all page
#1

Hello
I have many controller that i need add key to header when i call other page or controller
Example
When i redirect to controller/method,i add key to header before redirect
Maybe?
Reply
#2

Please, explain what you mean by a key that you want to add to a header.
Reply
#3

(12-14-2017, 11:26 AM)Wouter60 Wrote: Please, explain what you mean by a key that you want to add to a header.

I make api that it is working with header
I add user id in header key and check data according to it
Now i make site for use this api
And i cannot this api and i have to send header for api if i need use it
Reply
#4

Try this:

PHP Code:
$this->output->set_header('Authorization : APIKEY your-api-key-here'); 

before you load the view for the page that has to be displayed.
Reply
#5

(12-14-2017, 02:03 PM)Wouter60 Wrote: Try this:

PHP Code:
$this->output->set_header('Authorization : APIKEY your-api-key-here'); 

before you load the view for the page that has to be displayed.

Oh my God,Is it working good?
Reply
#6

Well, what did he answer?
Reply
#7

(12-14-2017, 10:58 PM)Wouter60 Wrote: Well, what did he answer?

No not working
I use below code
PHP Code:
$this->output->set_header('mobile:0910000000'); 
And call model for check header key
But it cannot find mobile key
Reply
#8

Can i add key to header with below code?
header('mobile:0910000000');
Reply
#9

You can't use a header with the name 'mobile'.
For a complete list of headers, see:
https://developer.mozilla.org/nl/docs/Web/HTTP/Headers

But why do you need a header to pass a value to a model?
You can include the code in the url, like this:

http://website/test/test_value/0910000000

Your controller (test) gets the value as a parameter for the function test_value:
PHP Code:
public function test_value($mobile
{
 
  //Based on the url in the example, $mobile has the value '0910000000';


Or, you can assign a value to a session variable for later use:
PHP Code:
$this->session->mobile '0910000000';
redirect('....'); 

After a redirect to another page, your controller can read the value like this:
PHP Code:
$mobile $this->session->mobile

And then, you can pass this value to your model to check the corresponding data.
Reply
#10

(12-15-2017, 09:03 AM)Wouter60 Wrote: You can't use a header with the name 'mobile'.
For a complete list of headers, see:
https://developer.mozilla.org/nl/docs/Web/HTTP/Headers

But why do you need a header to pass a value to a model?
You can include the code in the url, like this:

http://website/test/test_value/0910000000

Your controller (test) gets the value as a parameter for the function test_value:
PHP Code:
public function test_value($mobile
{
 
  //Based on the url in the example, $mobile has the value '0910000000';


Or, you can assign a value to a session variable for later use:
PHP Code:
$this->session->mobile '0910000000';
redirect('....'); 

After a redirect to another page, your controller can read the value like this:
PHP Code:
$mobile $this->session->mobile

And then, you can pass this value to your model to check the corresponding data.

I cannot pase field in url because i use header key in all model that i send it from app to api
Finally i decide to use session that you suggest me
Thanks
Reply




Theme © iAndrew 2016 - Forum software by © MyBB