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

Link to comment
Share on other sites

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!

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.