tcollie Posted January 9, 2007 Share Posted January 9, 2007 I'm trying prevent access to pages on my site unless they are called from another page on my server itself and I'm getting the following error:[code]Warning: eregi() [function.eregi]: REG_EMPTY[/code]Here is how I have this set up:[code]//This defines my root folder--In production this will be my domain$root = 'localhost';//This checks if the page referrer is a local page within my site$webserver=apache_request_headers();if( !eregi($root,$webserver[Referer])) {//Okay to process here}else{//Stop Processing}[/code]Can somebody help me out with this? Link to comment Share on other sites More sharing options...
effigy Posted January 9, 2007 Share Posted January 9, 2007 Is there something in[tt] $webserver[Referer][/tt]? Link to comment Share on other sites More sharing options...
tcollie Posted January 10, 2007 Author Share Posted January 10, 2007 $webserver[Referer] is the apache_request_headers() function. Link to comment Share on other sites More sharing options...
effigy Posted January 10, 2007 Share Posted January 10, 2007 No, it's a key from the array returned by that function. What I was getting at is, do you see something if you do [tt]echo $webserver[Referer];[/tt]? Link to comment Share on other sites More sharing options...
tcollie Posted January 10, 2007 Author Share Posted January 10, 2007 Sorry, my bad. I didn't understand what you were getting at. I have put a link from a file called run.php to a page that echos $webserver[Referer] and here is what I get when I click the link and view my test.php page:http://localhost/project/run.php Link to comment Share on other sites More sharing options...
effigy Posted January 10, 2007 Share Posted January 10, 2007 I cannot access a link on your localhost. I tried your code and it works OK for me; did you make any typos while transferring it to the forum? Have you tried turning on[tt] error_reporting(E_ALL);[/tt]? Link to comment Share on other sites More sharing options...
tcollie Posted January 10, 2007 Author Share Posted January 10, 2007 Sorry, It left out some info on my post.When I click a link to view my test.php page here is the info returned:[code]http://localhost/project/run.php[/code]And here is the code for my test.php page:[code]$webserver=apache_request_headers();//if( !eregi($root,$webserver[Referer])) {echo $webserver[Referer];[/code] Link to comment Share on other sites More sharing options...
effigy Posted January 10, 2007 Share Posted January 10, 2007 What is your PHP version?This works for me:[code]<a href="<?php echo $_SERVER['PHP_SELF']; ?>">Load this page.</a><pre><?php $root = 'localhost'; $webserver = apache_request_headers(); print_r($webserver); if (!eregi($root, $webserver['Referer'])) { echo "Not local"; } else { echo "Local"; }?></pre>[/code] Link to comment Share on other sites More sharing options...
tcollie Posted January 10, 2007 Author Share Posted January 10, 2007 Works perfectly. Thanks for all your help. I'll give you my first million $$ when I win the lottery. :D Link to comment Share on other sites More sharing options...
Recommended Posts