troubleshooting Question

HTTP_REFERER Question...

Avatar of NTGrE
NTGrE asked on
PHP
9 Comments1 Solution1383 ViewsLast Modified:
I got a page in http://localhost/vilyl/index.php and i dont want to allow direct access...

I use joomla wrapper and i want to allow access from there so i v made..

$refferer = $_SERVER['HTTP_REFERER'];
$yoursite = "http://localhost/index.php?option=com_wrapper&Itemid=26";

if($refferer != $yoursite){
  die ("Sorry, this page is not available from $refferer. Please visit $yoursite to see the page correctly!");
}

where  http://localhost/index.php?option=com_wrapper&Itemid=26 is the joomlas link.

seems that working and if i try direct access i get the error msg..and if i try via joomla wraper the page displayed corectly..

BUT...

when i click in a link in this page (category link) i get the error again..

Sorry, this page is not available from http://localhost/vilyl/index.php. Please visit http://localhost/index.php?option=com_wrapper&Itemid=26 to see the page correctly!

the code of my index.php goes like...

<?php
$refferer = $_SERVER['HTTP_REFERER'];
$yoursite = "http://localhost/index.php?option=com_wrapper&Itemid=26";

if($refferer != $yoursite){
  die ("Sorry, this page is not available from $refferer. Please visit $yoursite to see the page correctly!");
} elseif($refferer == $yoursite){

        include("config.inc.php");
        include("design.inc.php");
        include("max_char.inc.php");
            include("cntdwn.inc.php");
       
            
            
        // initialization
        $result_array = array();
        $counter = 0;

        $cid = (int)($_GET['cid']);
        $pid = (int)($_GET['pid']);

        // Category Listing<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<

        if( empty($cid) && empty($pid) )
        {
                $number_of_categories_in_row = 4;

                $result = mysql_query( "SELECT c.category_id,c.category_name,COUNT(photo_id)
                                                FROM gallery_category as c
                                                LEFT JOIN gallery_photos as p ON p.photo_category = c.category_id
                                                GROUP BY c.category_id ORDER BY category_name" );
                while( $row = mysql_fetch_array( $result ) )
                {
                        $result_array[] = "<a href='index.php?cid=".$row[0]."'>".$row[1]."</a> "."(".$row[2].")";
                }
                mysql_free_result( $result );        

                $result_final = "<tr>\n";

                foreach($result_array as $category_link)
                {
                        if($counter == $number_of_categories_in_row)
                        {        
                                $counter = 1;
                                $result_final .= "\n</tr>\n<tr>\n";
                        }
                        else
                        $counter++;

                        $result_final .= "\t<td>".$category_link."</td>\n";
                }

                if($counter)
                {
                        if($number_of_categories_in_row-$counter)
                                               $result_final .= "</tr>";
                }
        }


        // Thumbnail Listing<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<

        else if( $cid && empty( $pid ) )
        {
                $number_of_thumbs_in_row = 1;

                // If current page number, use it
                // if not, set one!

                if(!isset($_GET['page'])){
                    $page = 1;
                } else {
                    $page = $_GET['page'];
                }
.
.
.
..
bla bla bla....etc.

Seems that working only the first part when i create the category listing..but when i click in the categories i m taking the error msg......

:((

1) Any idea Why??

2) how can i redirect, after the error dislay, in my page after some seconds???

Thnx for your time ..
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 9 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 9 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros