phpQuestioner Posted July 28, 2007 Share Posted July 28, 2007 Is there anyway to look for a specific path in a variable sent by a query string? Example: http://www.domain.com/page1.php?pid=http://www.domain.com/pic1.jpg Is the any way to make sure that "domain.com" is somewhere in the "pid" query string variable? Otherwise if it is not; use a header too go somewhere else. Can this be done........? PS: I am not trying to prevent hot linking of pics; I am trying to prevent hot linking of a page. I created a script a while back that kind of does this. What it does is create a session if a page is accessed from with inside my domain and the session displays the page; otherwise the page will not display. The thing is that I cannot delete this session until after the browser closes. I used "session_destroy();" - but it did not delete the session. So now I want to be able to find a way to prevent access from outside of my domain; without sessions or cookies; this is my goal. Link to comment https://forums.phpfreaks.com/topic/62174-solved-can-you-check-a-query-string-variable-for-a-specific-path/ Share on other sites More sharing options...
zq29 Posted July 28, 2007 Share Posted July 28, 2007 Could be done with a regular expression... <?php $str = "http://www.domain.com/page1.php?pid=http://www.domain.com/pic1.jpg"; echo (eregi("pid=.*domain.com.*",$str)) ? "FOUND" : "NOT FOUND"; ?> Link to comment https://forums.phpfreaks.com/topic/62174-solved-can-you-check-a-query-string-variable-for-a-specific-path/#findComment-309596 Share on other sites More sharing options...
phpQuestioner Posted July 29, 2007 Author Share Posted July 29, 2007 SemiApocalyptic, Thank You - That will work great, but I modified it a little bit. <?php $gurl = $_SERVER['QUERY_STRING']; $str="$gurl"; echo (eregi("pid=.*domain.com.*",$str)) ? "FOUND" : "NOT FOUND"; ?> And I Also Did This...... <?php $gurl = $_SERVER['QUERY_STRING']; $str="$gurl"; $valid = (eregi("pid=.*domain.com.*",$str)) ? "Yes" : "No"; if ($valid == Yes) { echo "Welcome"; } else { echo "You Do Not Belong Here"; } ?> Link to comment https://forums.phpfreaks.com/topic/62174-solved-can-you-check-a-query-string-variable-for-a-specific-path/#findComment-309858 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.