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 8797843
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T23:56:18+00:00 2026-06-13T23:56:18+00:00

E.g. I have a working url: http://localhost/article/154 Where 154 is $id of the article

  • 0

E.g. I have a working url:

http://localhost/article/154

Where 154 is $id of the article in db and a controller article looks like e.g.:

function index ($id = '')
{

// some code here

}

Now, when I type something like:

http://localhost/article/154dsdead34

I get error because that id is not in my db. But, the php errors are shown on the page and the whole page is messedd up.

Instead I need a redirect to my controller called custom404 that can handle this (or if it is for some reason not possible at least a direct redirect(‘/’); to the homepage)

The same fix for variants like (to big $id number or not found in db):

http://localhost/article/3004534534534234600234

or (other parameters)

http://localhost/article/154/something/derer/asdasd

how to do such security check in CodeIgniter?

  • 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-06-13T23:56:19+00:00Added an answer on June 13, 2026 at 11:56 pm

    So many ways to do this.

    Inside the function, define ($id = NULL) so it skips empty errors, and the 1st statement can be if ( ! is_numeric($id)) show_404();

    You could also run $id = (int)$id; which should turn 154dsdead34 into 154.

    Routing is an option aswell. What would you prefer?

    You could do like this; inside the function run:

    if ( ! preg_match("~^article/\d+$~", $this->uri->uri_string())) {
        // Redirect user
    }
    

    Change accordingly. ~ opens and closes the regex. it’s often /, but with like ~ you don’t have to escape / (\/). ^ is the beginning of the string and $ is the end. \d+ is equal to [0-9]+ and requires cases with one digit or more. I hope it makes sense.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a Url like this http://localhost:4737/Site/listing/NH/Plaistow/2831516 and I want it to reroute to
I have a working .Net WCF HTTP service. If I put the URL into
Hi I want to redirect the URl: http://localhost/invite/yK-as8_/Subhrojit_Nag to http://localhost/auth/accept_invitation/yK-as8_/Subhrojit_Nag I have used the
I want to rewrite the URL like below: URL: http://localhost/my_site/?file_name=sample This is my URL
I have a problem in my Java webapp. Here is the code in index.jsp:
I have ajax calls that have the url http://localhost:80/Push/GetContacts?id=23 and the following servlet mapping:
I have a problem in rewriting my dynamic url pattern in localhost. here is
I have this working query that outputs URL and click counts from database. <?php
I have a problem getting password_Reset_confirm bit working. url: (r'^password_reset/$', 'django.contrib.auth.views.password_reset'), (r'^password_reset_done/$', 'django.contrib.auth.views.password_reset_done'), (r'^password_reset_confirm/(?P<uidb36>[0-9A-Za-z]+)-(?P<token>.+)/$',
I have working code of js, it shows different div for selected option. <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.