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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T22:29:27+00:00 2026-06-14T22:29:27+00:00

I have a piece of code I just wrote that detects if there is

  • 0

I have a piece of code I just wrote that detects if there is a user logged in and if [1] and [2] have any specific text in the string and then will relocate that person to another page if the values are met.

But I think my code is a little long winded. Is there a way to simplify what I have or is this the best I’ll get?

if (!isset($_SESSION['user_id'])){  
    $dir =  dirname($_SERVER['PHP_SELF']);
    $dirs = explode('/', $dir);
    if(isset($dirs[1])){
        if (($dirs[1] == "account") || ($dirs[1] == "admin")){
            header('Location: /');
        }
    }
    if(isset($dirs[2])){
        if(($dirs[2] == "account")){
            header('Location: /');
        }
    }
}

Thanks in advance

  • 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-14T22:29:28+00:00Added an answer on June 14, 2026 at 10:29 pm

    a simple way is to use a closure

    $dir =  explode('/', dirname($_SERVER['PHP_SELF']));
    
    $is = function($pos, $check) use($dir) {
        return array_key_exists($pos, $dir) && $dir[$pos] == $check;
    };
    
    if($is->__invoke(1, 'account')
        || $is->__invoke(1, 'admin')
        || $is->__invoke(2, 'account')) {
        header('Location: /');
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have just written a small piece of code and it struck me that
I have a piece of code (below) that can get the text of an
I have a piece of javascript code that I wrote to grab the html
I have one piece of Cocoa code I wrote that takes in an XML
I just wrote this piece of code to represent this error that is killing
I have an piece of code that does calculations on assets. There are many
I have the following piece of code that I wrote in C. Its fairly
Well, I'm gonna be pretty straightforward here, I just have a piece of code
I have a piece of code that was written by someone else before the
I have a piece of code: var tblGroupedMultiPassive = dtCSV.AsEnumerable() .Where(r => r.Field<String>(course_type_id) ==

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.