PHP define not working with jquery load

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • charles07
    New Member
    • Dec 2011
    • 45

    PHP define not working with jquery load

    I have a main file index.php into which iam loading myinnerpage.php . I have defined a variable inside index.php & checks it on myinnerpage.php , but when i load innerpage it shows restricted access, any idea why? following is my code.

    index.php
    Code:
    <?php
        define( '_JEXEC', true ); 
    ?>
    <div class="mypage">
    </div>
    <ul>
        <li><a href="#" onclick="loadpages('myiinerpage.php')">about page</a></li>   
    </ul>
    
    <script type="text/javascript">
        var $jq = jQuery.noConflict();
        function loadpages(page)
        {
            $jq('.mypage').load('myfolder/'+page);
        }
        
    </script>
    and now in the myiinerpage.php which is in the folder myfolder i have the following code.

    Code:
    <?php
    defined('_JEXEC') or die('Restricted access');
    ?>
    
    <div>
    my page elements
    </div>

    but when i click on the link it shows restricted access. I have loaded jquery too, any idea y this is happening?
  • Dormilich
    Recognized Expert Expert
    • Aug 2008
    • 8694

    #2
    that’s because constants are only valid in the current script. what you do is an AJAX request for which the constant is long gone. you would need to use sessions to accomplish that.

    Comment

    • charles07
      New Member
      • Dec 2011
      • 45

      #3
      Dear Dormilich

      could you please help me use sessions in this particular situation

      Comment

      • charles07
        New Member
        • Dec 2011
        • 45

        #4
        guys finally i found a solution, hope this is right, please contribute your ideas

        In my main index.php i changed function to this
        Code:
        function loadpages(page)
            {
                var myvalue = "myvalue ";
                $jq('.mypage').load('myfolder/'+page,myvalue+"="+myvalue);
            }
        and in the myiinerpage.php i added a piece of code like this
        Code:
        if($_GET['myvalue '] == '' || $_SERVER['HTTP_REFERER'] == '')die("Access denied");
        i used $_SERVER['HTTP_REFERER'] just incase someone tries to access the page by directly typing the get value in url

        Comment

        Working...