Jump to content


Photo

Using $_SERVER["HTTP_REFERER"] in a link


  • Please log in to reply
13 replies to this topic

#1 bob_the _builder

bob_the _builder
  • Members
  • PipPipPip
  • Advanced Member
  • 207 posts

Posted 01 September 2006 - 09:57 PM

Hi,

When I use $_SERVER["HTTP_REFERER"] within a link like:

<a href="index.php?action=delete&subcat_id='.$_GET['subcat_id'].'&confirm=y&referer='.$_SERVER["HTTP_REFERER"].'">Yes</a>


and try to call on $_GET['referer'] to redirect user back:


<meta http-equiv="refresh" content="3; url='.$_GET['referer'].'">';


$_GET['referer'] only seems to hold the value:


http://localhost/gallery/index.php?action=sh_subcat


but it should be:


http://localhost/gallery/index.php?action=sh_subcat&subcatid=4


Seems that it takes out everthing after the & in the above url?

Is there a work around for that?

Thanks


#2 wildteen88

wildteen88
  • Staff Alumni
  • Advanced Member
  • 10,482 posts
  • LocationUK, Bournemouth

Posted 01 September 2006 - 10:09 PM

Uus $_SERVER['QUERY_STRING'] to get the query string from the url, the bit after the question mark

$url = $_GET['REFERER'] . '?' . $_SERVER['QUERY_STRING'];

#3 bob_the _builder

bob_the _builder
  • Members
  • PipPipPip
  • Advanced Member
  • 207 posts

Posted 01 September 2006 - 10:24 PM

Thanks,

Is it bad pratice sending the url across like that to $_GET it at the destination?

#4 trq

trq
  • Staff Alumni
  • Advanced Member
  • 31,041 posts

Posted 01 September 2006 - 10:35 PM

Is it bad pratice sending the url across like that to $_GET it at the destination?


Its quite common practice really.

#5 bob_the _builder

bob_the _builder
  • Members
  • PipPipPip
  • Advanced Member
  • 207 posts

Posted 01 September 2006 - 10:50 PM

Still not working .. Tried:

&referer='.$_SERVER["HTTP_REFERER"].'?'.$_SERVER['QUERY_STRING'].'

and:

<meta http-equiv="refresh" content="3; url='.$_GET['referer'].'">

but still get:

http://localhost/gal...ction=sh_subcat

but it should be:


http://localhost/gal...bcat&subcatid=4


Thanks

#6 wildteen88

wildteen88
  • Staff Alumni
  • Advanced Member
  • 10,482 posts
  • LocationUK, Bournemouth

Posted 01 September 2006 - 10:58 PM

Try this:

$referer = urlencode($_SERVER["HTTP_REFERER"]. '?' .$_SERVER['QUERY_STRING']);
echo '<a href="index.php?action=delete&subcat_id=' . $_GET['subcat_id'] . '&confirm=y&referer=' . $referer . '">Yes</a>';

When you retrieve the referer you'll need to urldecode($_GET['referer'])

#7 bob_the _builder

bob_the _builder
  • Members
  • PipPipPip
  • Advanced Member
  • 207 posts

Posted 01 September 2006 - 11:12 PM

Works using:

&referer='.urlencode($_SERVER["HTTP_REFERER"]).'

then:

<meta http-equiv="refresh" content="3; url='.$_GET['referer'].'">

Thanks!

#8 lounger

lounger
  • Members
  • PipPipPip
  • Advanced Member
  • 46 posts

Posted 01 September 2006 - 11:16 PM

hey bob

i too am having trouble with a script which uses this $ref=@$HTTP_REFERER; but unfortunatly i am unable to post it here as the system always says The page cannot be displayed, i need the script to get the pic url and not the browser url ,any ideas how i can post my script so that everone can see it??

#9 bob_the _builder

bob_the _builder
  • Members
  • PipPipPip
  • Advanced Member
  • 207 posts

Posted 01 September 2006 - 11:27 PM

Hi lounger,

Not following your request that well, can you post some code to give a better idea on what you are trying to acheive?

Thanks

#10 lounger

lounger
  • Members
  • PipPipPip
  • Advanced Member
  • 46 posts

Posted 01 September 2006 - 11:36 PM

hi bob

i have a send a page to your friends script on a web page in my site but this sends the recipient the browser url, this is bad because it means that when this url link is clicked the peson who clicked it is actually in the senders account and can cause lots of mischeif eg. delete files ect. what i need is the script to send the image url instead which is also shown on my web page but i do not know how to make the script use that url instead of the browser url.

i cant post the script as this forum throws me out and shows me the page -The page cannot be displayed i cant even post a snippet or am i doing somthing wrong?? im just cut and pasting it on here?



#11 bob_the _builder

bob_the _builder
  • Members
  • PipPipPip
  • Advanced Member
  • 207 posts

Posted 01 September 2006 - 11:42 PM

Should be able to copy and paste into the text area .. maybe you are trying to paste more code than the limit allowed here?

#12 wildteen88

wildteen88
  • Staff Alumni
  • Advanced Member
  • 10,482 posts
  • LocationUK, Bournemouth

Posted 01 September 2006 - 11:43 PM

lounger for now post your code over at http://www.pastebin.com

Also are you asking bob_the _builder for help, or are you in some way trying to help bob_the _builder? If you are asking for help then post in your own topic. Dont hijack other peoples threads.

#13 lounger

lounger
  • Members
  • PipPipPip
  • Advanced Member
  • 46 posts

Posted 01 September 2006 - 11:51 PM

ok ill post in pastebin, im not hijacking anything im just giving bob support as i too am in a similar situation with i think the same problem??

and bob i was only tring to post one line so im not sure why it wont let me but ill try the other site now good luck with that buddy.

#14 wildteen88

wildteen88
  • Staff Alumni
  • Advanced Member
  • 10,482 posts
  • LocationUK, Bournemouth

Posted 01 September 2006 - 11:54 PM

I didnt say go away, just post your code over at pastebin.com then provbide the link to the code you pasted over at pastebin.com. Also read your thread you posted earlier here




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users