Jump to content

passing array in url


phpme1221

Recommended Posts

Hello All,

 

Can you please help me pass an array inside a url, the url  is being sent as part of a body in an email.

 

So far i am able to send emai with url and when i click the link inside the email i do see the array data but with all the additional characters; 2nd i tried testing the index of the array its starts with additionl characters you see below ' array[0] is ' array[1] is . array[2] is a and soo on

 

'.a:2:{i:0;a:1:{i:0;s:9

 

I have tried to sterialized and unsterialized at the target page but nothing is working.  Here is part of the code;

 

source page:

 

$list[] = $row['Host'];

$SM = urlencode(serialize($list);

$body .= "Please click on link: <a href = \"http://xx.xx.xx.xx/reg.php?SM=$SM\">click</a>";

 

target page ( clicked on email )

 

$SM = urldecode(unserialize($_GET['SM']));

$s1 = $_GET['SM'];

echo stripslashes($s1);

 

i have also tried echo stripslashes($s1[0]); thinking it will show the first "host" but it shows the funny characters..  I have tried base64 htmlspecialcharacters , nothing has worked. HELP and thanks!

 

 

 

 

Link to comment
Share on other sites

  • Replies 62
  • Created
  • Last Reply

Top Posters In This Topic

here's an interesting function that I found on php.net that creates a GET query from an array

 

function encode_array($args)
{
  if(!is_array($args)) return false;
  $c = 0;
  $out = '';
  foreach($args as $name => $value)
  {
    if($c++ != 0) $out .= '&';
    $out .= urlencode("$name").'=';
    if(is_array($value))
    {
      $out .= urlencode(serialize($value));
    }else{
      $out .= urlencode("$value");
    }
  }
  return $out . "\n";
}
?>

 

Link to comment
Share on other sites

whoa, sorry thats a bit too much for me to handle, maybe you can help me with the function using my parameters... there is no easier way around this?

with this function, simply place your array where $args is...it does the work for you, it will return the variable $out which will be the query string with your keys and values...so say you have an array like this..

 

$arr = array('apple' => 'red', 'orange' => 'round', 'blueberry' => 'blue');

 

you pass it through the function that I have previously posted like so

 

encode_array($arr);

 

you should receive something like this

 

$out = "apple=red&orange=round$blueberry=blue";

 

then you will simply add this to your url..

 

$body .= "Please click on link: <a href = \"http://xx.xx.xx.xx/reg.php?$out \">click</a>";

 

then use $_GET to extract the array values like you would any other query string

Link to comment
Share on other sites

I see your point, in your case then perhaps we should revert back to what we were doing before..let's try this..

 

$list[] = $row['Host'];
$array = urlencode(serialize($list);
$body .= "Please click on link: <a href = \"http://xx.xx.xx.xx/reg.php?array=$array \">click</a>";

target page ( clicked on email )

$array = (isset($_GET['array'])) ? unserialize($_GET['array']): array(); //unserialize only
print_r($array);

 

 

Link to comment
Share on other sites

Hi aykay,

 

Looks a lot better, yes there was an error on php.ini,

 

howerver i have to specify print_r($array[0]); to get the first value (Host1), how do i show all without have to specify the index #?

 

print_r($array); shows

 

array(2) { [0]=> string(9) "Host1" [1]=> string(10) "Host2"

 

thanks atkay we are almost there...

Link to comment
Share on other sites

Hi aykay, 

 

Thanks again, you have greatly helped me,  now this may be strentching it, can you tell me how can i hide the query string or paremeter in the url  and is there a way to you can think of to remove the session from cache?  i dont want the user to always be able to click on an old email to register again, just 1 time only registration? Any suggestions thanks! agian a major piece has been accomplished!

Link to comment
Share on other sites

Hi Aykay,

 

Another question you might be able to help me with?  if i wanted to insert each array value (host) into the database thru a form, how do i specify each host to enter into db?

 

Thanks! ;)

not exactly sure what you are trying to do here, can you give me an example please?

Link to comment
Share on other sites

$SM = unserialize(urldecode($_GET['SM']));

 

You had that kind of backwards fix it like above and see what happens. If you do have magic_quotes on, then you will want to stripslashes prior to unserialize, not after.

??

OP, as for the register once is concerned..there are quite a few ways that this can be done, once a user clicks on the link that they are given in the email, you can set a $_SESSION value to "read" or "1" or whatever value you want. If the session isn't set yet, proceed with the execution that you want to do, if the session is set, stop execution and show the user a message that the link has already been visited..perhaps something like that will do for you

Link to comment
Share on other sites

Hi Aykay,

 

I want to insert the parameters passed into a databause using a form, but now sure how to extract the values that was passed in reg.php.  Inside the reg.php will be form for the user to reg a host.

 

Host 1 active = YES or NO

          Lease for Another 90 days  = Yes or NO

          Description, Text box why you need it

 

Host 2 ""

 

 

Host 3 ""

 

on and on

Link to comment
Share on other sites

is reg.php the target page that the array is sent to?

Still not sure what you are trying to do, or how a form would have any relevance here.. but what you can do is display a form for each value in the array like so..

 

foreach($array as $value){
      print "<form action='#' method='POST'>
      $value Active = <input type='radio' name='active' value='Yes' /><input type='radio' name='active' value='No' /><br />
      Lease for Another 90 Days? <input type='radio' name='lease' value='Yes' /><input type='radio' name='lease' value='No' /><br />
      Description <textarea name='description' cols='5' rows='30'></textarea>
      <input type='submit' name='$value' value='Submit' />"; 
}

something like that perhaps, then you can grab the data based on which Host it is

 

if(isset($_POST['Host1'])){ //if the submit button for Host1 has been pressed
      // sanitize data, insert into database
}elseif(isset($_POST['Host2'])){ // is the submit button for Host2 has been pressed, etc...

}

Link to comment
Share on other sites

a sad attempt

 

session_start();

if (isset($_SESSION['test']) > 1) {

echo "Host Registered";

}

 

 

Can you help me out here  aykay? thanks

okay lets say that after all of the code that you want to run, you set $_SESSION['test'] = 1; at the very top of your code you would have something like

 

session_start();
if(isset($_SESSION['test'])){
      if($_SESSION['test'] == 1){
            exit("Host already registered!");
      }
}

 

remember at the very bottom of your page, after all of your initial code has been run is where you will want to place $_SESSION['test'] = 1;

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.