Jump to content

passing URL through the URL ???!!!!


robcrozier

Recommended Posts

Hi,

 

I wonder if anyone can offer any assistance with regard to this problem?

 

What im trying to do is assign a var in one script that contains a partial URL e.g:


$var = page.php?var1=bla&var2=bla2

 

Now.. what i want to do is pass $var through the URL to another script.  It's the way that i need to pass the var that#s causing the trouble.  What i need to do is pass $var through the URL contained within another var.  e.g:

 

 


header("Location:new_page.php?var2=$var");

 

As you can probably now see, the way in which the var is being passed is causing only the first part of $var to be passed through the URL (up to the 1st '&').  This is because it thinks that this is the start of another variable that is being passed through the URL.

 

Does anyone have any suggestions as to how this could be worked around?  I need to pass $var all in one, contained within the URL var.

 

I hope this makes sense, lol.

 

Thanks for your time in advance!

Link to comment
https://forums.phpfreaks.com/topic/91538-passing-url-through-the-url/
Share on other sites

You'll need to use str_replace to replace the & and =  with something else, then use it again on the next page to change them back. eg;

 

p1.php

<?php

  $var = 'blah=foo&boo=bob';
  $var = str_replace(array('&','='),array('::','::::'),$var);
  echo "<a href=\"p2.php?var=$var\">p2</a>";

?>

 

p2.php

<?php

  $var = $_GET['var'];
  $var = str_replace(array('::','::::'),array('&','='),$var);
  echo $var;

?>

 

In fact you could simply use htmlspecialchars and htmlspecialchars_decode, much simpler.

Haha, you know what... i was just about to report this topic as solved as i had just came up with the same resolution.  It's typical after sitting staring at it for ages and then posting the problem on here that i come up with the solution myself.

 

Thanks a lot for your time anyway mate!

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.