By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,903 Members | 2,075 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,903 IT Pros & Developers. It's quick & easy.

PHP define not working with jquery load

P: 45
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.

Expand|Select|Wrap|Line Numbers
  1. <?php
  2.     define( '_JEXEC', true ); 
  3. ?>
  4. <div class="mypage">
  5. </div>
  6. <ul>
  7.     <li><a href="#" onclick="loadpages('myiinerpage.php')">about page</a></li>   
  8. </ul>
  10. <script type="text/javascript">
  11.     var $jq = jQuery.noConflict();
  12.     function loadpages(page)
  13.     {
  14.         $jq('.mypage').load('myfolder/'+page);
  15.     }
  17. </script>
and now in the myiinerpage.php which is in the folder myfolder i have the following code.

Expand|Select|Wrap|Line Numbers
  1. <?php
  2. defined('_JEXEC') or die('Restricted access');
  3. ?>
  5. <div>
  6. my page elements
  7. </div>

but when i click on the link it shows restricted access. I have loaded jquery too, any idea y this is happening?
Dec 23 '11 #1
Share this Question
Share on Google+
3 Replies

Expert Mod 5K+
P: 8,639
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.
Dec 23 '11 #2

P: 45
Dear Dormilich

could you please help me use sessions in this particular situation
Dec 27 '11 #3

P: 45
guys finally i found a solution, hope this is right, please contribute your ideas

In my main index.php i changed function to this
Expand|Select|Wrap|Line Numbers
  1. function loadpages(page)
  2.     {
  3.         var myvalue = "myvalue ";
  4.         $jq('.mypage').load('myfolder/'+page,myvalue+"="+myvalue);
  5.     }
and in the myiinerpage.php i added a piece of code like this
Expand|Select|Wrap|Line Numbers
  1. 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
Dec 27 '11 #4

Post your reply

Sign in to post your reply or Sign up for a free account.