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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T18:50:00+00:00 2026-06-05T18:50:00+00:00

Code: <?php //initializing script, do not modify session_start(); define(‘IN_SCRIPT’, true); //so that global.php cannot

  • 0

Code:

<?php
//initializing script, do not modify
session_start();
define('IN_SCRIPT', true); //so that global.php cannot be accessed directly
$_SCRIPTNAME = 'default.php';
include 'global.php';
$db = new MyDB(); //mysql class
if(isset($_GET['action'])) {
    $action = $_GET['action'];
} elseif(isset($_SESSION['user']) && $action == "login") {
    header("Location: {$_SCRIPTNAME}?action=overview");
    exit;
} elseif($action == 'logout') {
    session_unset();
    header("Location: {$_SCRIPTNAME}?action=login");
    exit;
} else {
    header("Location: {$_SCRIPTNAME}?action=login");
    exit;
}

//display proper template for the action defined (if none found, 404)
$template = $db->selectFrom("template", null, array("name" => mysql_real_escape_string($action)));
if(!empty($template['result']['0'])) {
    $template = $template['result']['0'];
    eval("echo \"".$template['html']."\";");
} else {
    $template = $db->selectFrom("template", null, array("name" => "404"));
    $template = $template['result']['0'];
    eval("echo \"".$template['html']."\";");
}
?>

In the database, I have a table templates with a couple rows in the format name/html where name is the name of the template and html is the template itself. Eval is required AFAIK and nothing is user inputted in the templates so it should be safe.

A sample URL would be: http://localhost/default.php?action=login

My question is: why would

if(isset($_GET['action'])) {
    $action = $_GET['action'];
} elseif(isset($_SESSION['user']) && $action == "login") {
    header("Location: {$_SCRIPTNAME}?action=overview");
    exit;
} elseif($action == 'logout') {
    session_unset();
    header("Location: {$_SCRIPTNAME}?action=login");
    exit;
} else {
    header("Location: {$_SCRIPTNAME}?action=login");
    exit;
}

not redirect to default.php?action=login if the ‘user’ session is not set and the action is not logout? I’m trying to make it so users not logged in cannot access the ‘overview’ page.

Thank you.

  • 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-05T18:50:03+00:00Added an answer on June 5, 2026 at 6:50 pm

    The problem is with your if/elseif block.

    You need to separate your $action definition from the block:

    if(isset($_GET['action'])) {
        $action = $_GET['action'];
    }
    
    if(isset($_SESSION['user']) && $action == "login") {
        header("Location: {$_SCRIPTNAME}?action=overview");
        exit;
    } elseif($action == 'logout') {
        session_unset();
        header("Location: {$_SCRIPTNAME}?action=login");
        exit;
    } else {
        header("Location: {$_SCRIPTNAME}?action=login");
        exit;
    }
    

    The way your code is now, it will execute the if(isset($_GET['action'])) block and then ignore the rest of the block since those are all elseifs.

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

Sidebar

Related Questions

is there a possible bit of code (php, java, css, html) that will force
My PHP code assigns an array to a Smarty variable that can be accessed
I need to include to my php script external php code which is situated
I have a php code that gives me the following output: (its an array)
I just saw this code while studying the wordpress source code (PHP), You can
I need help to use jConfirm with this existing code (php & Jquery &
code: sql.php <?php $uid = trim($_POST['uid']); $pass= trim($_POST['pass']); $type= trim($_POST['type']); $link = mysql_connect(localhost,root,akash); if
PHP code: <a id=a$id onclick=check($id,1) href=javascript:void(0) class=black>Qualify</a> I want to remove the onclick=check($id,1) so
My PHP code $dom = new DOMDocument(); @$dom->loadHTML($file); $xpath = new DOMXPath($dom); $tags =
My PHP code is split between many files, and often I find myself using

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.