Solved

read sites from text file

Posted on 2009-05-14
5
256 Views
Last Modified: 2012-05-07
hello there,
this is working perfectly fine but there are over 20 sites not just 3, I would like to make something so that it can read
the sites from a text file instead, the text file will have the sites like this

site1.com
site2.com
site3.com

how can I do something like that?
if (isset($_SERVER['HTTP_REFERER']) && $_SERVER['HTTP_REFERER'] != "") { $ref=$_SERVER['HTTP_REFERER'];	} else { $ref='EmptyReferer'; }
if(!eregi('(site1.com|site2.com|site3.com)', $ref)) {
	//echo
}

Open in new window

0
Comment
Question by:XK8ER
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
5 Comments
 
LVL 39

Expert Comment

by:Roger Baklund
ID: 24389042
Use the file() function to read the file into an array, and use in_array() to check if the domain is in the array.

http://php.net/manual/en/function.file.php
http://php.net/manual/en/function.in-array.php
0
 
LVL 1

Author Comment

by:XK8ER
ID: 24389084
how exactly can I do that?
0
 
LVL 39

Accepted Solution

by:
Roger Baklund earned 250 total points
ID: 24389301
Something like this:
if (isset($_SERVER['HTTP_REFERER']) && $_SERVER['HTTP_REFERER'] != "") {
  $ref=$_SERVER['HTTP_REFERER'];
  $data = file('domains.txt');
  if(in_array($ref.PHP_EOL,$data))
        //echo
}

Open in new window

0
 
LVL 7

Assisted Solution

by:ycTIN
ycTIN earned 250 total points
ID: 24391843
cxr answer is correct

<?php
if (isset($_SERVER['HTTP_REFERER']) && $_SERVER['HTTP_REFERER'] != "") { 
	$ref=$_SERVER['HTTP_REFERER']; 
} else { 
	$ref='EmptyReferer'; 
}
$data = file('domain.txt',FILE_IGNORE_NEW_LINES|FILE_SKIP_EMPTY_LINES);
if(in_array($ref,$data)){
	echo "allow";
} else {
	echo "deny";
}
?>

Open in new window

0
 
LVL 1

Author Comment

by:XK8ER
ID: 24391932
for some reason its not working because the $ref is just (domain1.com or domain2.com) so it doesnt match maybe?
0

Featured Post

Don't Cry: How Liquid Web is Ensuring Security

WannaCry is just the start. Read how Liquid Web is protecting itself and its customers against new threats.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Part of the Global Positioning System A geocode (https://developers.google.com/maps/documentation/geocoding/) is the major subset of a GPS coordinate (http://en.wikipedia.org/wiki/Global_Positioning_System), the other parts being the altitude and t…
Many old projects have bad code, but the budget doesn't exist to rewrite the codebase. You can update this code to be safer by introducing contemporary input validation, sanitation, and safer database queries.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

734 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question