Jump to content

[SOLVED] Can You Check A Query String Variable For A Specific Path?


phpQuestioner

Recommended Posts

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
Share on other sites

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
Share on other sites

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.