Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 276999
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T01:00:20+00:00 2026-05-12T01:00:20+00:00

In my controller, I check a condition to see if the user is allowed

  • 0

In my controller, I check a condition to see if the user is allowed to do something. If the check fails, I want to send a 403 back to the browser. How do I do that in Cakephp?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-12T01:00:20+00:00Added an answer on May 12, 2026 at 1:00 am

    EDIT – This question is quite old and covers different versions of the CakePHP framework. Following is a summary of which version each answer applies to. Don’t forget to vote on the solution that helps most.

    • CakePHP 3.x and 4.x – using response object (Roberto’s answer)
    • CakePHP 2.x – using exceptions (Brad Koch’s answer) [preferred solution]
    • CakePHP 2.x – setting header only (Asa Ayers’ answer)
    • CakePHP 1.x – using error handler (my other answer)
    • CakePHP 1.x – setting header only (this answer)

    EDIT #2 – A more detailed answer for CakePHP 2.x has been added by Mark37.

    EDIT #3 – Added solution for CakePHP. (May 2018: CakePHP 3.5 did some function renaming, solution by Roberto is still valid.)


    By looking at the relevant API code from the previous comment, it seems you can call Controller::header($status) to output a header without redirection. In your case, the proper usage is most likely:

    $this->header('HTTP/1.1 403 Forbidden');
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want my controller to return the right HTTP response code when the user
I have actions in different controllers that need to check for a some condition
I need that every action in a controller checks for a specific condition. If
I want to be able to check for specific conditions when a user selects
I came across a controller in an older set of code (Rails 1.2.3) that
I have a controller action that is being executed by a link that was
i am using remote_function call onchange before calling remote_function i want to check the
My Controller class is decorated with an AuthorizeAttribute to protect the actions: [Authorize(Roles =
So the controller context depends on some asp.net internals. What are some ways to
Given a controller method like: def show @model = Model.find(params[:id]) respond_to do |format| format.html

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.