Cannot access website folder

Ask about general coding issues or problems here.

Moderators: egami, macek, gesf

Post Reply
khofong3
New php-forum User
New php-forum User
Posts: 8
Joined: Mon Feb 03, 2020 9:07 pm

Tue Feb 04, 2020 12:05 am

Dear Experts,

I had setup a WAMP server in my PC with Win 8 and a new Virtual Host was added as below -

<VirtualHost *:80>
ServerName wampjhmjkb
DocumentRoot "c:/wampjhmjkb"
<Directory "c:/wampjhmjkb/">
Options +Indexes +Includes +FollowSymLinks +MultiViews
AllowOverride All
Require local
</Directory>
</VirtualHost>

Our required website is under a sub-folder "Web_Application" as below -

C:\wampJHMJKB\Web_Application

When accessing the website by accessing the above sub-folder in Google Chrome, i.e.

http://wampjhmjkb/Web_Application/

I could NOT access the website and found msg as below -

Not Found
The requested URL /Web_Application/en/ was not found on this server.

Apache/2.4.39 (Win64) PHP/7.2.18 Server at wampjhmjkb Port 80

Don't know why the above msg was found as there is no the above sub-folder "....../en/" setup in my PC.

Could you advise how to solve the above problem so that I can access the above website / sub-folder "Web_ Application" ?

Below is the content of "index.php" under the above sub-folder "Web_Application" -
<?php
include('core/framework.php');
$framework = new framework();
$framework->call('common', 'func');
$framework->init();
?>

Below is the content of "framework.php" under the above sub-folder "Web_Application - core"
<?php

/**
* Framework
* This php included all core functions to be used
*
* Copyright Annoucement
* @
* @
* @
* @
* @
*
* Function List
* ==========================================================================================
* - System Function
* @function lib($class, $object) Function to load library
* @function func($function) Function to load function
* @function call($name, $type) Function to load apps's php ('func' or 'class' or 'other')
* @function load($page, $func) Function to load page (default load '$page->main()')
* @function init($defaultPage, $defaultFunc) Function to initial the core (default load 'index->main()')
* @function url($fullPath) Function to get current url path (default 'false')
* @function path() Function to get core path
* @function now($format) Function to get current time (default 'Y-m-d H:i:s')
* @function isCMS() Function to check current path whether is cms or not
* @function render($bag, $view, $template_bag, $template) Function to render view (default 'html')
* @function cacheLog($cache_path) Function to add log and clear expired cache file
*/

class framework {

private $_time = false;

public function __construct($runtime = false) {
if(!session_id()){
session_start();
}
require_once(self::path().'/core/function/common.func.php');
if(self::lib('config', 'sys')->get('debug') == true) {
error_reporting(E_ERROR | E_WARNING | E_PARSE);
}else{
error_reporting(0);
}
$protocol = toLower(self::lib('config', 'sys')->get('forceProtocol'));
if($protocol && getip()) {
$is_https = isset($_SERVER['HTTPS']) && toLower($_SERVER['HTTPS']) != 'off';
if(($is_https && $protocol == 'http') ||
(! $is_https && $protocol == 'https'))
{
redirect($protocol . '://' . $_SERVER['HTTP_HOST'] . geturl(true, true, true));
}
}
$tmp = get_global('_page');
set_global('_page', $tmp ? $tmp : 'index');
$customize_link = self::lib('config', 'sys')->get('customizeLink');
if(! self::isCMS() &&
($customize_link === true || (is_array($customize_link) && in_array(get_global('_page'), $customize_link))))
{
set_global('_func', 'main');
}
else
{
$tmp = get_global('_func');
set_global('_func', $tmp ? $tmp : 'main');
}
if($runtime){
self::runtime();
}
}

public function __destruct() {
if($this->_time){
$time = microtime();
$time = explode(' ', $time);
$time = $time[1] + $time[0];
$endtime = $time;
$totaltime = ($endtime - $this->_time);
echo '<br />This page loaded in '.$totaltime.' seconds.';
}
}

/**
* Function to load library
* @param string $class Class name to load.
* @param array $arr Extra param pass to the library.
* @return object Class object
*/
public static function lib($class, $arr = array()) {
$class = toLower($class);
if(!class_exists($class)) {
$path = self::path() . "/core/class/{$class}.class.php";
if(file_exists($path)){
require_once($path);
}
}
if(class_exists($class)) {
if(!is_array($arr)){
$arr = array($arr);
}
$class = new ReflectionClass($class);
return $class->newInstanceArgs($arr);
}else{
return false;
}
}

/**
* Function to load core function
* @param string $func Function name to load.
* @return object self
*/
public static function func($function) {
$function = toLower($function);
$path = self::path() . "/core/function/{$function}.func.php";
if(file_exists($path)){
require_once($path);
}
return new framework();
}

/**
* Function to load apps's php
* @param string $name, array $name PHP name to load.
* @param string $type PHP type to load.
* @return object self
*/
public static function call($name, $type = '') {
if(is_array($name)){
foreach($name as $value){
self::call($value, $type);
}
}else{
switch($type){
case 'func':
$folders = array('function');
break;
case 'class':
$folders = array('class');
break;
case 'other':
$folders = array('3rdparty');
break;
default:
$folders = array('function', 'class', '3rdparty');
}
$base_path = self::path() . (self::isCMS() ? '/cms' : '');
foreach($folders as $folder){
$path = "{$base_path}/apps/{$folder}/{$name}.php";
if(file_exists($path)){
require_once($path);
break;
}
}
}
return new framework();
}

/**
* Function to load page
* @param string $page Page name to load.
* @param string $func Function to call.
* @param array $para Parameter to pass to the function.
* @return object self
*/
public static function load($page, $func, $para = array()) {
if($page != 'html')
{
$cache_folder = false;
if(! self::isCMS() && ! do_post() && ! do_file())
{
$cache = self::lib('config', 'cache')->get();
if($cache['view']['enable'] && ! in_array($page, $cache['view']['no_cache']))
{
$cache_folder = self::path() . '/' . $cache['path'];
if(! is_dir($cache_folder))
{
mkdir($cache_folder, 0777);
}
$cache_folder .= '/view';
if(! is_dir($cache_folder))
{
mkdir($cache_folder, 0777);
}
self::cacheLog($cache_folder);
$cache_name = geturl(true, true, true);
if($cache['view']['session'])
{
$cache_name .= json_encode($_SESSION);
}
$cache_folder .= '/' . md5($cache_name);
if(file_exists($cache_folder) && (! $cache['view']['lifetime'] || (time() - filemtime($cache_folder)) < $cache['view']['lifetime']))
{
read_file($cache_folder);
return new framework();
}
}
}
$path = self::path() . (self::isCMS() ? '/cms' : '') . "/apps/controller/{$page}.php";
if(file_exists($path)) {
require_once($path);
}
if(class_exists('_' . $page))
{
$page = '_' . $page;
$pageClass = new $page();
}
elseif(class_exists($page))
{
$pageClass = new $page();
}
if($pageClass)
{
$hv_func = true;
if(method_exists($pageClass, '_' . $func))
{
$func = '_' . $func;
}
elseif(! method_exists($pageClass, $func))
{
$hv_func = false;
}
if($hv_func)
{
$tmp = new ReflectionMethod($pageClass, $func);
if($tmp->isPublic())
{
$para = xssfilter($para);
ob_start();
call_user_func_array(array($pageClass, $func), $para);
$html = ob_get_clean();
echo $html;
del_session('_redirect');
if($cache_folder)
{
file_put_contents($cache_folder, $html);
}
return new framework();
}
}
}
}
self::redirect(geturl());
}

/**
* Function to initial the core
* @param string $defaultPage Default home page to load
* @param string $defaultFunc Default home page function to call
*/
public function init($defaultPage = '', $defaultFunc = '') {
if($defaultPage){
set_global('_page', $defaultPage);
}
if($defaultFunc){
set_global('_func', $defaultFunc);
}
$url = self::url(true);
if(! xssfilter($url))
{
self::redirect(geturl());
}
$para = explode('/', $url);
if($path = get_global('_path'))
{
if($path == 'img/')
{
include(self::path() . '/img.php');
exit;
}
else
{
if(strpos($path, 'upload/') === false)
{
$ext = toLower(pathinfo($path, PATHINFO_EXTENSION));
$dangerous_ext = array('htaccess', 'php', 'asp', 'aspx');
if(! in_array($ext, $dangerous_ext))
{
if(is_file($path) && file_exists($path))
{
$name = basename($path);
if(strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE') || strpos($_SERVER['HTTP_USER_AGENT'], 'Trident/7.0'))
{
$name = mb_convert_encoding($name, 'big5', 'auto');
}
header('Content-Description: File Transfer');
header('Content-Type: ' . file_type($path));
header('Content-Disposition: inline; filename="' . $name . '"');
header('Content-Transfer-Encoding: binary');
header('Cache-Control: private, max-age=604800');
header('Pragma: public');
header('Expires: ' . gmdate('D, d M Y H:i:s', time() + 604800) . ' GMT');
header('Last-Modified: ' . gmdate('D, d M Y H:i:s', filemtime($path)) . ' GMT');
flush();
read_file($path);
exit;
}
elseif(strpos($path, 'css/') !== false)
{
$path = preg_replace('/^css\/([a-zA-Z0-9\/]+)(\.css)?$/i', '$1', $path);
include(self::path() . '/css.php');
exit;
}
elseif($path == 'js/lang.js')
{
header('content-type: text/javascript');
header('Cache-Control: private, max-age=604800');
header('Expires: ' . gmdate('D, d M Y H:i:s', time() + 604800) . ' GMT');
include('lang.php');
exit;
}
}
header('HTTP/1.0 404 Not Found');
}
else
{
$file = $path;
include(self::path() . '/file.php');
}
exit;
}
}
$customize_link = self::lib('config', 'sys')->get('customizeLink');
if(! self::isCMS() && $customize_link)
{
$full_customize_link = self::lib('config', 'sys')->get('fullCustomizeLink');
if($full_customize_link)
{
$pageName = get_global('_page');
}
else
{
$pageName = array_shift($para);
}
if($full_customize_link || ! is_array($customize_link) || (is_array($customize_link) &&
in_array($pageName, $customize_link)))
{
$funcName = 'main';
}
else
{
$funcName = array_shift($para);
}
}
else
{
$pageName = array_shift($para);
$funcName = array_shift($para);
}
$_config = self::lib('config', 'sys');
header('Content-Type: text/html; charset=utf-8');
header('X-XSS-Protection: 1; mode=block');
if($_config->get('iframe'))
{
header('P3P: CP="CAO PSA OUR"');
}
else
{
header('X-Content-Type-Options: nosniff');
header('X-Frame-Options: SAMEORIGIN');
}
if(! $_config->get('jsAccessCookie'))
{
@ini_set('session.cookie_httponly', true);
@ini_set('session.cookie_secure', true);
}
$title = $_config->get('title');
$meta = $_config->get('meta');
$database = $_config->get('database');
if($_config->get('lang')){
$lang = self::lib('language')->get();
if(is_array($title)){
$title = $title[$lang];
}
if(isset($meta[$lang])){
$meta = $meta[$lang];
}
}
if($database && ! self::isCMS())
{
$_setting = self::lib('setting');
$language = self::lib('language')->getLang();
foreach($language as $key => $value)
{
if($value['code'] == $lang)
{
$lang = $key;
break;
}
}
$meta['keywords'] = $_setting->get('keywords_' . $lang);
$meta['description'] = $_setting->get('description_' . $lang);
}
if($meta){
foreach($meta as $key => $value){
if(!self::lib('meta')->get($key)){
self::lib('meta')->set($key, $value);
}
}
}
self::lib('title')->set($title);
self::load($pageName, $funcName, $para);
return $this;
}

/**
* Function to get current url path
* @param boolean $fullPath Whether to get full url path or not
* @return string url path
*/
public static function url($fullPath = false) {
if(! $para = get_global('_para'))
{
$is_cms = self::isCMS();
$cms_lang = self::lib('config')->get('cmsLang', 'sys');
$cms_def_lang = self::lib('config')->get('cmsDefLang', 'sys');
$customize_link = self::lib('config', 'sys')->get('customizeLink');
$script_name = $_SERVER['SCRIPT_NAME'];
if(self::lib('config')->get('htaccess', 'sys'))
{
$script_name = dirname($_SERVER['SCRIPT_NAME']);
}
$path = str_replace($script_name . '/', '', $_SERVER['REQUEST_URI']);
$path = preg_replace('/^\//', '', $path);
$path = preg_replace('/\?.*$/', '', $path);
$para = array_filter(explode('/', $path), function($value) {
return $value !== '';
});
if((! preg_match('/^(.*\/)?(?P<path>(css|js|img|upload)\/.*)$/', $path, $match) || preg_match('/(css\/[^\.]*|lang\.js)$/', $path)) && ($is_cms || self::lib('config')->get('lang', 'sys'))){
$lang = array_shift($para);
$_lang = self::lib('language', $lang);
$url = '/' . (sizeof($para) ? implode('/', $para) . '/' : '') . (do_get() ? '?' . http_build_query(do_get()) : '');
if(! $is_cms && $lang != $_lang->get())
{
self::redirect(geturl() . $_lang->get() . $url);
}
else if($is_cms && $lang != $cms_def_lang && ! in_array($lang, array_keys($cms_lang)))
{
self::redirect(geturl() . $cms_def_lang . $url);
}
}
if(array_key_exists('path', $match))
{
set_global('_path', $match['path']);
}
$para[0] = $para[0] ? $para[0] : get_global('_page');
$para[1] = $para[1] ? $para[1] : get_global('_func');
set_global('_para', $para);
}
if($fullPath)
{
return implode('/', $para);
}
else
{
return $para[0] . '/' . $para[1];
}
}

/**
* Function to get core path
* @return string core path
*/
public static function path() {
return dirname(dirname(__FILE__));
}

/**
* Function to get current time
* @param string $format Datetime format
* @return string datetime (Y-m-d H:i:s)
*/
public static function now($format = 'Y-m-d H:i:s') {
return to_date($format, ((int) self::lib('setting')->get('time')).' hour');
}

/**
* Function to check current path whether is cms or not
* @return boolean true or false
*/
public static function isCMS() {
if(self::lib('config')->get('htaccess', 'sys'))
{
return preg_match('/\/cms\/$/', geturl());
}
else
{
return preg_match('/\/cms\/' . basename($_SERVER['SCRIPT_NAME']) . '\/$/', geturl());
}
}

/**
* Function to render view
* @param array $bag Variable to be used in the view
* @param string $view View name
* @param array $template_bag Variable to be used in the template view (html)
* @param string $template Template view name (html)
*/
public static function render($bag = array(), $view = '', $template_bag = array(), $template = 'html') {
if($template)
{
$path = self::path() . (self::isCMS() ? '/cms' : '') . "/apps/controller/html.php";
if(file_exists($path))
{
require_once($path);
$template_func = $template == 'html' ? 'main' : $template;
if(method_exists('html', $template_func))
{
$tmp = new ReflectionMethod('html', $template_func);
if($tmp->isPublic())
{
$template_bag = extend(call_user_func(array('html', $template_func)), $template_bag);
}
}
}
}
if(is_array($bag))
{
ob_start();
include_view($bag, $view);
$body = ob_get_clean();
}
else
{
$body = $bag;
}
if($template)
{
if($protocol = toLower(self::lib('config', 'sys')->get('forceProtocol')))
{
$body = '<script type="text/javascript">
if(window.location.protocol.toLowerCase().indexOf(\'' . $protocol . ':\') == -1)
{
window.location.href = \'' . $protocol . '://\'+ window.location.host + window.location.pathname;
}
</script>' . $body;
}
if(! self::lib('config', 'sys')->get('allowHighlight', 'sys'))
{
$body = '<script type="text/javascript">
document.addEventListener(\'dragstart\', function(e) {
e.preventDefault();
}, false);
document.addEventListener(\'selectstart\', function(e) {
e.preventDefault();
}, false);
function noHightlight(node) {
if (node.nodeType == 1) {
node.setAttribute(\'unselectable\', \'on\');
}
var child = node.firstChild;
while (child) {
noHightlight(child);
child = child.nextSibling;
}
}
noHightlight(document.body);
</script>' . $body;
}
if(! self::lib('config', 'sys')->get('allowRightClick', 'sys'))
{
$body = '<script type="text/javascript">
document.addEventListener(\'contextmenu\', function(e) {
e.preventDefault();
}, false);
</script>' . $body;
}
ob_start();
include_view(extend($template_bag, array(
'body' => $body
)), $template);
$body = ob_get_clean();
}
if(! self::isCMS())
{
$url = geturl();
if(! self::lib('config')->get('htaccess', 'sys'))
{
$url = dirname($url) . '/';
}
$body = preg_replace('/(\<(link|script|img|a|source)[^>]*\s+(src|href)\=(\"|\'))((?!((https?|tel|sms|mailto|whatsapp|callto|facetime|skype|wtai|dc)\:|\.{0,2}\/|\#))[^>]*(\"|\'))/i', '$1' . $url . '$5', $body);
}
echo $body;
}

/**
* Function to add log and clear expired cache file
* @param string $cache_path Cache path
*/
public static function cacheLog($cache_path)
{
$log_path = $cache_path . '/log';
$now = time();
if(! file_exists($log_path))
{
file_put_contents($log_path, $now);
}
else
{
$last_clean = file_get_contents($log_path);
$diff = $now - $last_clean;
if($diff > 86400)
{
file_put_contents($log_path, $now);
$files = filelist($cache_path);
if($files)
{
foreach($files as $value)
{
if(file_exists($value) && ($now - filemtime($value)) > 86400)
{
@unlink($value);
}
}
}
}
}
}

private function runtime(){
$time = microtime();
$time = explode(' ', $time);
$time = $time[1] + $time[0];
$this->_time = $time;
}

private function redirect($url)
{
$_redirect = (int) get_session('_redirect');
if($_redirect >= 3)
{
del_session('_redirect');
die("'" . self::url(true) . "' not exists.");
}
else
{
header('HTTP/1.1 301 Moved Permanently');
set_session('_redirect', $_redirect + 1);
redirect($url);
}
}

}
?>

Pls let me know if you need more info. on this.


Many Thanks,
KH Fong
khofong3
New php-forum User
New php-forum User
Posts: 8
Joined: Mon Feb 03, 2020 9:07 pm

Tue Feb 04, 2020 2:15 am

Dear Experts,

If you cannot access the following link -

http://wampjhmjkb/Web_Application/

Pls kindly try the following link -

http://test.jkbrothers.net/angliadesign ... plication/

Error is similar as below -

Not Found
The requested URL /angliadesign/clients2/jhm/site/Web_Application/en/ was not found on this server.

Apache/2.4.39 (Win64) PHP/7.2.18 Server at test.jkbrothers.net Port 80

Also don't know why the above msg was found as there is no the above sub-folder "....../en/" setup in my PC.

For your help to check and advise how to solve this problem so that I can access our required website / sub-folder "Web_ Application".


Many Thanks,
KH Fong
User avatar
hyper
php-forum GURU
php-forum GURU
Posts: 998
Joined: Mon Feb 22, 2016 5:52 pm

Tue Feb 04, 2020 9:24 am

You need to edit 'sites-available' and your 'hosts' file and also create a 'xxx.conf 'file, then you'll also need to execute 'a2ensite xxx' and then restart apache.

There should be a tutorial for your win 8 set up somewhere.
khofong3
New php-forum User
New php-forum User
Posts: 8
Joined: Mon Feb 03, 2020 9:07 pm

Tue Feb 04, 2020 5:55 pm

Dear hyper,

Thanks for your advice. Could you explain in details on how to proceed as below ?

1) edit 'sites-available' and our 'hosts' file
2) create a 'xxx.conf 'file
3) execute 'a2ensite xxx' (we don't have such file under our main folder "web_application")

For the above step (2), there is a sub-folder "config" under our main folder "web_application". In this sub-folder, there are some .conf files as below -
cache.conf
db.conf
menu.conf
menu_map.conf
smtp.conf
sys.conf

Does it mean that this step (2) had been completed ?


Many Thanks,
KH Fong
User avatar
hyper
php-forum GURU
php-forum GURU
Posts: 998
Joined: Mon Feb 22, 2016 5:52 pm

Tue Feb 04, 2020 7:11 pm

You'll have to search for a set of full instructions as there are variations with versions and operating systems.

a2ensite is used to register your new virtual host with apache 2 - enable - site.

I don't use windows so I can be more specific than that.
khofong3
New php-forum User
New php-forum User
Posts: 8
Joined: Mon Feb 03, 2020 9:07 pm

Tue Feb 04, 2020 8:37 pm

Hi,

If I would be able to search for the solutions / instructions, I would not ask for help in here.

Your suggestions are quite general but not specific -

1) edit 'sites-available' and our 'hosts' file -

For the 'sites-available', we had already setup our Virtual Host of WAMP server as below -

For the following website -
http://test.jkbrothers.net/angliadesign ... plication/

<VirtualHost *:80>
ServerName localhost
ServerAlias localhost
DocumentRoot "${INSTALL_DIR}/www"
<Directory "${INSTALL_DIR}/www/angliadesign/clients2/jhm/site/Web_Application/">
Options +Indexes +Includes +FollowSymLinks +MultiViews
AllowOverride None
# Require local
Require all granted
</Directory>
</VirtualHost>

For the following website -
http://wampjhmjkb/web_application/

<VirtualHost *:80>
ServerName wampjhmjkb
DocumentRoot "c:/wampjhmjkb/Web_Application"
<Directory "c:/wampjhmjkb/Web_Application/">
Options +Indexes +Includes +FollowSymLinks +MultiViews
AllowOverride All
Require local
</Directory>
</VirtualHost>

Is it also required to edit ?

Also, which 'hosts' file is required to edit ? There are a lot of files under our main folder "Web_Application". Don't know which one is required to edit as you mentioned.

2) create a 'xxx.conf 'file - Is it already completed as mentioned in my post at 9:55 am ?

3) execute 'a2ensite xxx' - For WAMP server including Apache 2.4.39, nothing is required to register when installing the server or creating the Virtual Host. Also, there is no the selection for "apache 2 - enable - site" in WAMP server. Could you also advise ?

Pls kindly let me know if you need more info. and/or source codes.


Many Thanks,
KH Fong
khofong3
New php-forum User
New php-forum User
Posts: 8
Joined: Mon Feb 03, 2020 9:07 pm

Wed Feb 05, 2020 11:48 pm

Any expert can help to advise for our above problem ?

Tks,
KH Fong
khofong3
New php-forum User
New php-forum User
Posts: 8
Joined: Mon Feb 03, 2020 9:07 pm

Thu Feb 06, 2020 6:37 pm

Dear Experts,

After changing the following Virtual Host of WAMP server -
From -
http://wampjhmjkb/web_application/

<VirtualHost *:80>
ServerName wampjhmjkb
DocumentRoot "c:/wampjhmjkb/Web_Application"
<Directory "c:/wampjhmjkb/Web_Application/">
Options +Indexes +Includes +FollowSymLinks +MultiViews
AllowOverride All
Require local
</Directory>
</VirtualHost>

To -
http://jhmjkb/

<VirtualHost *:80>
ServerName jhmjkb
DocumentRoot "c:/wampHosts/jhmjkb"
<Directory "c:/wampHosts/jhmjkb/">
Options +Indexes +Includes +FollowSymLinks +MultiViews
AllowOverride All
Require local
</Directory>
</VirtualHost>

Problem still could not be solved with similar error as below -
Not Found
The requested URL /en/ was not found on this server.

Apache/2.4.39 (Win64) PHP/7.2.18 Server at jhmjkb Port 80

The "/en/" was still automatically defaulted while there is no such sub-folder under the above Root Directory - "jhmjkb".

When inputting the "http://jhmjkb/" in browser, it is automatically changed to "http://jhmjkb/en/".

Same as the original hosted website (which hosting will be ended by vendor shortly) -
http://www.jhm-jkbrothers.com/

When inputting the above website in browser, it is also automatically changed to "http://www.jhm-jkbrothers.com/en/".

Does it mean that some sub-folder(s) like "/en/" with files are missing in the above Root Directory - "jhmjkb", or else ?


Many Thanks,
KH Fong
khofong3
New php-forum User
New php-forum User
Posts: 8
Joined: Mon Feb 03, 2020 9:07 pm

Sun Feb 09, 2020 6:12 pm

Any expert can help to advise for our above problem ?

Below is the content of "index.php" under the above Root Directory - "jhmjkb" -
<?php
include('core/framework.php');
$framework = new framework();
$framework->call('common', 'func');
$framework->init();
?>

For the content of "framework.php" under the above Directory - "jhmjkb/core", pls kindly refer my above original post on Feb 04, 2020 4:05 pm.


Many Thanks,
KH Fong
Post Reply