Page 1 of 1

reading a file

Posted: Mon Aug 23, 2010 6:39 am
by nite4000
Can someone help with this?

I have a file that will have a domain name in it along with other info the domain would be like this http://www.mydomain.com

Now the script of course would chk to see if the file exists but will compare the domain name from file to the url/domain. I need to have it give a error if they dont match

remember the file would have other info so it would have to look for the domain name/

I have tried everything but nothing seems to work for me here is code i have

Code: Select all

<?php 

$section = file_get_contents('file.php', NULL, NULL, 0, 50);

if($pageURL !=$section) {
	echo 'error';
	
$pageUR1  = ereg_replace("/(.+)", "", $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"]); 
} else { 


echo $pageUR1;
}

?>

hope someone can help.

Re: reading a file

Posted: Mon Aug 23, 2010 8:01 am
by dlaurent86
Hey buddy i do see one problem with your script you declare the $pageUR1 variable inside the if statement try this:

Code: Select all

<?php 
$section = file_get_contents('file.php', NULL, NULL, 0, 50);
$pageUR1  = ereg_replace("/(.+)", "", $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"]); 

if($pageURL !=$section) {
        echo 'error';  
} else { 
echo $pageUR1;
}
?>
another thing is i would use file.txt instead of file.php if your just using the file to store your information as a string. and instead of storing your data in a file why not use a database.

Re: reading a file

Posted: Mon Aug 23, 2010 10:06 am
by nite4000
it didnt work. I changed it to a txt file and when i put the domainname in teh file and ran it on the same domain i still get a error msgs from the code.
it should be ok since its the same domain but its not

Re: reading a file

Posted: Mon Aug 23, 2010 5:17 pm
by dlaurent86
ok do me a favor run this script and let me know what you get.

Code: Select all

<?php 
$section = file_get_contents('file.txt', NULL, NULL, 0, 50);
$pageUR1  = ereg_replace("/(.+)", "", $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"]); 
echo 'section: '.$section.'<br/>pageUR1:'.$pageUR1;
?>
obviously $section and $pageUr1 do not match. so you need to change the url in file.txt

Re: reading a file

Posted: Mon Aug 23, 2010 5:22 pm
by nite4000
when i ran that i got this

section: www.mydomain.com
pageUR1:www.mydomain.com

The domain i am using i dont want to give out but they were the same when i ran it.

Re: reading a file

Posted: Mon Aug 23, 2010 6:59 pm
by dlaurent86
ok my apologies the first code i gave you the variable names were incorrect. try this and respond

Code: Select all

 <?php 
$section = file_get_contents('file.txt', NULL, NULL, 0, 50);
$pageURL  = ereg_replace("/(.+)", "", $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"]); 

if($pageURL !=$section) {
        echo 'error';  
} else { 
echo $pageURL;
}
?>
and looking at your original code.

Code: Select all

<?php 

$section = file_get_contents('file.php', NULL, NULL, 0, 50);

if($pageURL !=$section) {
        echo 'error';
        
$pageUR1  = ereg_replace("/(.+)", "", $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"]); 
} else { 


echo $pageUR1;
}

?>
you where declaring $pageUR1 inside the if statement comparing $pageURL to $section. im assuming $pageUR1 and $pageURL are the same variable and there was just a typo.

Re: reading a file

Posted: Mon Aug 23, 2010 7:03 pm
by nite4000
ok it works from what I can tell. Thank you for your help. I knew I was close just wasnt catching it. Thanks again.