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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T07:48:00+00:00 2026-06-02T07:48:00+00:00

Basically, I want to create a site to show people how to prevent PHP

  • 0

Basically, I want to create a site to show people how to prevent PHP vulnerabilities by simulating them. However, I can not get them to work myself.

I want to see if a variable equals a valid page (I only have two for testing) and, if it does, load that page. Otherwise, I see if it contains “../”. If neither of those are true, it simply says “Page not found”.

This is my code so far:

<?php
if($page=="LOLone.php" || $page=="LOLtwo.php"){
echo "Welcome, look at the LOL cats!";
include($page);
}else if(strlen(strstr($page,"../"))>0){
echo "Congrats, you found the transversal attack vulnerability!";
}else{
echo "Page not found!";
}
?>

Whenever I try to use page=LOLone.php (or LOLtwo.php or even ../) it says “Page not found!” Can I not compare variables the way I am, or could this be my web-host playing it safe? I am a bit confused, but I am relatively new to PHP so I feel like I am missing something simple…

Ok, I made a simple mistake. A very big one too. Sorry.
Thanks for all the replies, and I will be very careful about my own server getting hacked. In this example I should be clean though, because I have it include the page only if it equals a specified value. Thanks again.

  • 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-02T07:48:01+00:00Added an answer on June 2, 2026 at 7:48 am

    Try

    $webPath = "/home/www/somesite/userpages" ;
    $pages = array(
    "page1.php",
    "page2.php"     
    );
    
    
    //http://testing.com?page=xxx
    $_GET['page'] = "../../etc/passwd" ; //Sample Hack
    
    
    //Prepare Include 
    
    $page = realpath($_GET['page']);
    $dirName = dirname($page);
    $baseName = basename($page) . ".php";
    
    
    if($dirName != $webPath)
    {
        die("Die! Die! Die!");
    }
    
    if(!in_array($baseName, $pages))
    {
        die("Kill! Kill! Kill!");
    }
    
    echo "Welcome" ;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have php generating html and I want to create layers. Basically I want
I'm using resque-status for Resque/Redis... https://github.com/quirkey/resque-status I basically want to create a new Sinatra
Basically I want to create one large object of many object in JavaScript. Something
I want to create own filetype to save objects in my app. Basically, I
I want to create a Google Docs document from within Haskell, so basically I
How to create imaged scrollbars, for example: http://www.openstudio.fr/jquery/index.htm Basically, I want to create my
I basically want to do this in code: PersonList myPersonList; //populate myPersonList here, not
Basically I want to create a comment system where comments may have parents that
Basically, i want my site to aggregate a lot of rss feeds and store
I want to realize a login for my site. I basically copied and pasted

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.