Create an account

Very important

  • To access the important data of the forums, you must be active in each forum and especially in the leaks and database leaks section, send data and after sending the data and activity, data and important content will be opened and visible for you.
  • You will only see chat messages from people who are at or below your level.
  • More than 500,000 database leaks and millions of account leaks are waiting for you, so access and view with more activity.
  • Many important data are inactive and inaccessible for you, so open them with activity. (This will be done automatically)


Thread Rating:
  • 548 Vote(s) - 3.49 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to get Prestashop admin dir & admin url?

#1
i am trying to get admin url and admin dir from a module.

Can you give an example finding admin url and admin dir from a module php page?

<?php
define('PS_ADMIN_DIR', dirname(__file__) . '/../../testadmin');
echo PS_ADMIN_DIR;

this code gives me

/home/myaccount/public_html/modules/suppliers/../../testadmin

i was expecting to get

/home/myaccount/public_html/testadmin

Any ideas?
Reply

#2
<?php

$path = '/http/fpm/http/data/../../node/';

print 'path : '.$path.'<br/>';

$isdir = ( is_dir($path) === true ) ? 'yes':'no';

print 'isdir ? ['.$isdir.']<br/>';

print 'dirname : '.dirname($path).'<br/>';

$nfo = pathinfo($path);

print 'pathinfo : '.$nfo['dirname'].'<br/>';

function trimpath($p){
$p = explode('/',$p);
$out = array();
foreach($p as $n => $v)
switch($v)
{ case '.': continue; break;
case '..':
array_pop($out);
break;
default :
$out[] = $v;
break;
};
return implode('/',$out);
}

print 'trimpath : '.trimpath($path);

?>

this will print

> path : /http/fpm/http/data/../../node/
> isdir ? [yes]
> dirname : /http/fpm/http/data/../..
> pathinfo : /http/fpm/http/data/../..
> trimpath : /http/fpm/node/
Reply

#3
You can get it by using " _PS_ROOT_DIR_ " and append your admin dir name with it like below

_PS_ROOT_DIR_."/testadmin"

This will give you full path to the admin directory. The _PS_ROOT_DIR_ is used to get the PS complete path to directory where it is installed.

You can't get the admin url directly, as PS system dont know the admin directory, because we can change the admin directory name at any time to any name for security reasons. So to construct an admin url knowing your admin directory name "testadmin" and the controller name "AdminTest", you can create a url as below

$link = new Link();
_PS_BASE_URL_.__PS_BASE_URI__."testadmin/".$link->getAdminLink('AdminTest', true);


This will give you complete link including full domain and sub directory (if installed in sub directory).

the getAdminLink gets two argument , controller name and second is Boolean true / false. By default the second is set to true, so need to pass it. It is used to create the token for the controller.

I hope this will help you.


**Note : The above code is just for idea, it may or may not need some changes.**

Reply

#4
Admin dir is stored inside `_PS_ADMIN_DIR_` variable.
Reply

#5
For admin dir you can get it like that

$admin = explode(DIRECTORY_SEPARATOR,_PS_ADMIN_DIR_);
$admin_folder = array_pop((array_slice($admin, -1)));
Admin url

$admin_url =_PS_BASE_URL_.__PS_BASE_URI__.$admin_folder
Reply

#6
__PS_BASE_URI__.basename(_PS_ADMIN_DIR_)
Reply

#7

$shop_url_nossl = _PS_BASE_URL_ . __PS_BASE_URI__;
$shop_url_ssl = _PS_BASE_URL_SSL_ . __PS_BASE_URI__;
$admin_folder = basename(_PS_ADMIN_DIR_);
$admin_path = _PS_ADMIN_DIR_;
$shop_path = _PS_ROOT_DIR_;
Output:

[To see links please register here]

[To see links please register here]

admin123asd
/home/webaccount/public_html/admin123asd
/home/webaccount/public_html
Reply



Forum Jump:


Users browsing this thread:
1 Guest(s)

©0Day  2016 - 2023 | All Rights Reserved.  Made with    for the community. Connected through