#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2013
    Posts
    13
    Rep Power
    0

    Defined variables and classes


    I am having difficulty accessing a class using a defined variable as an url.
    if I do this:
    Code:
    if (!defined('CLASS_URL')) {
    	define('CLASS_URL', BASE_URL . DIR_REL . "guts/classes/");
    }
    
    include CLASS_URL . "school.php";
    I get "Fatal error: Class 'Nav' not found in /Applications/MAMP/htdocs/Dcms/includes/header.php on line 20"
    If I do this:
    Code:
    include "guts/classes/school.php";
    It goes through. The problem is I also need it to work on a page inside the "guts" folder.
    Thank you kindly,
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Loyal (3000 - 3499 posts)

    Join Date
    Jul 2003
    Posts
    3,332
    Rep Power
    594
    Please enclose your code in [ PHP ] tags not [ CODE ] tags. See the sticky at the top of this forum that says READ THIS BEFORE POSTING.

    First you have no class definition. Second did you print the value of CLASS_URL to be sure it is what you expect? It is looking for a class named NAV which you didn't post or even say where it is defined.
    There are 10 kinds of people in the world. Those that understand binary and those that don't.
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2013
    Posts
    13
    Rep Power
    0
    Originally Posted by gw1500se
    Please enclose your code in [ PHP ] tags not [ CODE ] tags. See the sticky at the top of this forum that says READ THIS BEFORE POSTING.

    First you have no class definition. Second did you print the value of CLASS_URL to be sure it is what you expect? It is looking for a class named NAV which you didn't post or even say where it is defined.
    Yes I have printed the value of CLASS_URL and it is correct.
    As a new development, it seems that it does not like the "http://localhost" portion as although it finds the class page it does not find the class itself.

    Apologies about the code
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Loyal (3000 - 3499 posts)

    Join Date
    Jul 2003
    Posts
    3,332
    Rep Power
    594
    You need to post the value of CLASS_URL at the point of the error. Where are you loading the class file and what does it contain?
    There are 10 kinds of people in the world. Those that understand binary and those that don't.
  8. #5
  9. --
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Jul 2012
    Posts
    3,957
    Rep Power
    1045
    Hi,

    you can't just load PHP scripts from a URL. This is a fundamental misunderstanding. What you need is a local file path.

    (To be exact, it is possible to use URLs when a certain configuration directive is on. But this is a gigantic security risk, so it must be turned off.)
    The 6 worst sins of security ē How to (properly) access a MySQL database with PHP

    Why canít I use certain words like "drop" as part of my Security Question answers?
    There are certain words used by hackers to try to gain access to systems and manipulate data; therefore, the following words are restricted: "select," "delete," "update," "insert," "drop" and "null".
  10. #6
  11. No Profile Picture
    Contributing User
    Devshed Loyal (3000 - 3499 posts)

    Join Date
    Jul 2003
    Posts
    3,332
    Rep Power
    594
    It should also be noted, according to my understanding, if you include a URL with a php extension, functions and classes will not work anyway because they go directly to the php parser. One workaround is to use some other extension such as inc.

    Comments on this post

    • Jacques1 disagrees
    There are 10 kinds of people in the world. Those that understand binary and those that don't.
  12. #7
  13. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2013
    Posts
    13
    Rep Power
    0
    Originally Posted by gw1500se
    You need to post the value of CLASS_URL at the point of the error. Where are you loading the class file and what does it contain?
    The value of CLASS_URL is "http://localhost/Dcms/guts/classes/"
    The class file is "http://localhost/Dcms/guts/classes/school.php"
    and it contains:
    PHP Code:
    class Nav{
        function 
    buildNav(){
            global 
    $conn;
            
    $sql "select * from pages where tID != 0";
            
    $result $conn->query($sql);
            
    $num $result->num_rows;
            if(
    $num 1){
                echo 
    "<ul>";
                while(
    $row $result->fetch_object()){
                    echo 
    "<li><a href=\"" BASE_URL DIR_REL $row->url "\">" $row->name "</a></li>";
                }
                echo 
    "</ul>";
            }
        }

  14. #8
  15. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2013
    Posts
    13
    Rep Power
    0
    Originally Posted by Jacques1
    Hi,

    you can't just load PHP scripts from a URL. This is a fundamental misunderstanding. What you need is a local file path.

    (To be exact, it is possible to use URLs when a certain configuration directive is on. But this is a gigantic security risk, so it must be turned off.)
    Aha, that is what I was figuring. Now to find a way to make it work from both folders.
  16. #9
  17. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2013
    Posts
    13
    Rep Power
    0
    Originally Posted by gw1500se
    It should also be noted, according to my understanding, if you include a URL with a php extension, functions and classes will not work anyway because they go directly to the php parser. One workaround is to use some other extension such as inc.
    I am unfamiliar with inc, would you care to expand? I am just trying to expand upon my knowledge by moving to oop from procedural.
    Thanks,
  18. #10
  19. --
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Jul 2012
    Posts
    3,957
    Rep Power
    1045
    No. No. You don't load PHP code from URLs at all. This "feature" is pretty much the first thing you turn off when you set up a server.

    Including remote scripts is a gigantic security risk, because PHP will execute anything it receives from that URL. If the remote server is attacked, and the original script gets replaced with malicious code, you have a serious problem. If the remote script gets manipulated in transport, you again have a serious problem. So don't do it. This is a no-no, because it effectively adds all security vulnerables from the remote server to your own machine.

    And including scripts from a local URL is obviously nonsense.



    Originally Posted by Scorpa54
    Now to find a way to make it work from both folders.
    With an absolute file path. You know how those look like, right?
    The 6 worst sins of security ē How to (properly) access a MySQL database with PHP

    Why canít I use certain words like "drop" as part of my Security Question answers?
    There are certain words used by hackers to try to gain access to systems and manipulate data; therefore, the following words are restricted: "select," "delete," "update," "insert," "drop" and "null".
  20. #11
  21. No Profile Picture
    Contributing User
    Devshed Loyal (3000 - 3499 posts)

    Join Date
    Jul 2003
    Posts
    3,332
    Rep Power
    594
    That is just an example of an extension that is NOT php. In any case, as Jacques1 suggested, don't use a URL at all. Use a local file path instead.
    There are 10 kinds of people in the world. Those that understand binary and those that don't.
  22. #12
  23. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2013
    Posts
    13
    Rep Power
    0
    Originally Posted by Jacques1
    With an absolute file path. You know how those look like, right?
    I understand, just not sure how to pull it off. I may have to duplicate certain things or something like that. Darn good thing it's personal and not for a client. And I'm suppose to be on holiday... yeah, right.
  24. #13
  25. No Profile Picture
    Contributing User
    Devshed Loyal (3000 - 3499 posts)

    Join Date
    Jul 2003
    Posts
    3,332
    Rep Power
    594
    Just use the absolute or relative path in your definition instead of an actual URL. Why do you think you need to duplicate things?
    There are 10 kinds of people in the world. Those that understand binary and those that don't.
  26. #14
  27. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2013
    Posts
    13
    Rep Power
    0
    Originally Posted by gw1500se
    Just use the absolute or relative path in your definition instead of an actual URL. Why do you think you need to duplicate things?
    I'm playing with a cms and for editing I was attempting to call things from the "home" folder to the "edit" folder. Perhaps that idea requires more thought. Like I say, I'm trying to learn.
  28. #15
  29. --
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Jul 2012
    Posts
    3,957
    Rep Power
    1045
    You need to get familiar with your operating system. This isn't a PHP problem, it's a matter of basic file handling.
    The 6 worst sins of security ē How to (properly) access a MySQL database with PHP

    Why canít I use certain words like "drop" as part of my Security Question answers?
    There are certain words used by hackers to try to gain access to systems and manipulate data; therefore, the following words are restricted: "select," "delete," "update," "insert," "drop" and "null".

IMN logo majestic logo threadwatch logo seochat tools logo