robcrozier Posted February 17, 2008 Share Posted February 17, 2008 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! Quote Link to comment https://forums.phpfreaks.com/topic/91538-passing-url-through-the-url/ Share on other sites More sharing options...
trq Posted February 17, 2008 Share Posted February 17, 2008 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. Quote Link to comment https://forums.phpfreaks.com/topic/91538-passing-url-through-the-url/#findComment-468884 Share on other sites More sharing options...
robcrozier Posted February 17, 2008 Author Share Posted February 17, 2008 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! Quote Link to comment https://forums.phpfreaks.com/topic/91538-passing-url-through-the-url/#findComment-468891 Share on other sites More sharing options...
Daniel0 Posted February 17, 2008 Share Posted February 17, 2008 Or you could just use urlencode(). Quote Link to comment https://forums.phpfreaks.com/topic/91538-passing-url-through-the-url/#findComment-468894 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.