Add key to header in all page - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5) +--- Forum: General Help (https://forum.codeigniter.com/forumdisplay.php?fid=24) +--- Thread: Add key to header in all page (/showthread.php?tid=69560) |
Add key to header in all page - omid_student - 12-14-2017 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? RE: Add key to header in all page - Wouter60 - 12-14-2017 Please, explain what you mean by a key that you want to add to a header. RE: Add key to header in all page - omid_student - 12-14-2017 (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 RE: Add key to header in all page - Wouter60 - 12-14-2017 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. RE: Add key to header in all page - omid_student - 12-14-2017 (12-14-2017, 02:03 PM)Wouter60 Wrote: Try this: Oh my God,Is it working good? RE: Add key to header in all page - Wouter60 - 12-14-2017 Well, what did he answer? RE: Add key to header in all page - omid_student - 12-15-2017 (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'); But it cannot find mobile key RE: Add key to header in all page - omid_student - 12-15-2017 Can i add key to header with below code? header('mobile:0910000000'); RE: Add key to header in all page - Wouter60 - 12-15-2017 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) Or, you can assign a value to a session variable for later use: PHP Code: $this->session->mobile = '0910000000'; 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. RE: Add key to header in all page - omid_student - 12-16-2017 (12-15-2017, 09:03 AM)Wouter60 Wrote: You can't use a header with the name 'mobile'. 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 |