phpme1221 Posted July 19, 2011 Share Posted July 19, 2011 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! Quote Link to comment Share on other sites More sharing options...
AyKay47 Posted July 19, 2011 Share Posted July 19, 2011 the variable $SM that you have made should contain the array in its original form..why aren't you using that variable instead of $s1 which is your encoded array? Quote Link to comment Share on other sites More sharing options...
premiso Posted July 19, 2011 Share Posted July 19, 2011 $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. Quote Link to comment Share on other sites More sharing options...
phpme1221 Posted July 19, 2011 Author Share Posted July 19, 2011 Thanks all , but i tried echoing $SM nothing shows up Quote Link to comment Share on other sites More sharing options...
AyKay47 Posted July 19, 2011 Share Posted July 19, 2011 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"; } ?> Quote Link to comment Share on other sites More sharing options...
phpme1221 Posted July 19, 2011 Author Share Posted July 19, 2011 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? Quote Link to comment Share on other sites More sharing options...
phpme1221 Posted July 19, 2011 Author Share Posted July 19, 2011 magic quotes is off as well in the php.ini file Quote Link to comment Share on other sites More sharing options...
AyKay47 Posted July 19, 2011 Share Posted July 19, 2011 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 Quote Link to comment Share on other sites More sharing options...
phpme1221 Posted July 19, 2011 Author Share Posted July 19, 2011 Thanks AyKay, But what if you dont know the exact size or values of the array, like what i have i just use $row['Host'] because my query extracts the # of host a user ownes.. the example array is a list of values which i am not after... Quote Link to comment Share on other sites More sharing options...
AyKay47 Posted July 19, 2011 Share Posted July 19, 2011 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); Quote Link to comment Share on other sites More sharing options...
phpme1221 Posted July 19, 2011 Author Share Posted July 19, 2011 Thanks aykay, Shows nothing this time, blank page on target.php... i use a var_dump shows bool(false) this is fustrating eh....... Quote Link to comment Share on other sites More sharing options...
AyKay47 Posted July 19, 2011 Share Posted July 19, 2011 the code I posted will work if used correctly, and will certainly not cause your target.php page to return blank...what errors do you receive in your error.log? make sure your error_reporting is set to 1 Quote Link to comment Share on other sites More sharing options...
phpme1221 Posted July 19, 2011 Author Share Posted July 19, 2011 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... Quote Link to comment Share on other sites More sharing options...
phpme1221 Posted July 19, 2011 Author Share Posted July 19, 2011 correction showing Array ( [0] => Host1 [1] => Host2 ) Quote Link to comment Share on other sites More sharing options...
AyKay47 Posted July 19, 2011 Share Posted July 19, 2011 foreach($array as $value){ print "$value <br />"; //format it however you want } Quote Link to comment Share on other sites More sharing options...
phpme1221 Posted July 19, 2011 Author Share Posted July 19, 2011 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! Quote Link to comment Share on other sites More sharing options...
phpme1221 Posted July 19, 2011 Author Share Posted July 19, 2011 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! Quote Link to comment Share on other sites More sharing options...
AyKay47 Posted July 19, 2011 Share Posted July 19, 2011 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? Quote Link to comment Share on other sites More sharing options...
Zane Posted July 19, 2011 Share Posted July 19, 2011 $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. Quote Link to comment Share on other sites More sharing options...
AyKay47 Posted July 19, 2011 Share Posted July 19, 2011 $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 Quote Link to comment Share on other sites More sharing options...
phpme1221 Posted July 19, 2011 Author Share Posted July 19, 2011 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 Quote Link to comment Share on other sites More sharing options...
phpme1221 Posted July 19, 2011 Author Share Posted July 19, 2011 Hi aykay, Yeah i get what your saying but not sure how to go about doing this though \ any website on this $_SESSION variable Quote Link to comment Share on other sites More sharing options...
phpme1221 Posted July 19, 2011 Author Share Posted July 19, 2011 a sad attempt session_start(); if (isset($_SESSION['test']) > 1) { echo "Host Registered"; } Can you help me out here aykay? thanks Quote Link to comment Share on other sites More sharing options...
AyKay47 Posted July 19, 2011 Share Posted July 19, 2011 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... } Quote Link to comment Share on other sites More sharing options...
AyKay47 Posted July 19, 2011 Share Posted July 19, 2011 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; Quote Link to comment 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.