PHP - Unserialize Returns False...
I am trying to unserialize this string:
a:3:{s:3:\"zip\";s:5:\"55068\";s:4:\"city\";s:9:\"Rosemount\";s:5:\"state\";s:2:\"MN\";} but I unserialize is returning false. Why is it doing that? $info = unserialize($_COOKIE['zipcode']); var_dump($info); Similar TutorialsHi, I am trying to verify if the given url exists or not, by using file_exists() function. It always returns 'FALSE' , according to my understanding it happening because the file to be checked on the given url is located in safe mode. Could anyone please suggest as to how this could be overcome, by similar function or by using alternative method. Regards Abhishek Madhani I'm working on a WordPress theme and I'm trying to build in a simple if statement which will check if the user has add his own logo into the images folder if he doesn't then the name of the blog will appear as normal text in place of the graphic logo. This is how it looks like: <?php $logo_dir = get_template_directory_uri() . "/images/logo.png"; if (file_exists($logo_dir)) { ?> <li><img src="<?php bloginfo ('template_directory'); ?>/images/logo.png" alt="<?php bloginfo('description'); ?>" /></li> <?php } else { ?> <li id='blog_name'><a href="<?php bloginfo('url'); ?>"><?php bloginfo('name'); ?><font>*</font></a></li> <?php } ?> I've echo'd out $logo_dir, the URL is correct, but still for some reason it's seeing it as if there would no file exist. If I turn it around into !file_exists then the graphic logo WILL show up. So it's always seeing it as non-existent. Any ideas why this could be or am I using this function in a wrong fashion? As far as I've understood the PHP manual, this is the correct way of using it. Hi all ! The following code has two similar queries. Query 1 and Query 2. While Query 1 works just fine, Query 2 simply fails persistently. I have not been able to figure out why?
I have checked every single variable and field names but found no discrepancy of any sort or any mismatch of spelling with the fields in the database.
I would be grateful if anybody can point out what is preventing the second query from returning a valid mysqli object as the first one does. Here is the code for the two.
<?php $db_host = "localhost"; $db_user ="root"; $db_pass =""; $db_database ="allscores"; //////////////// CHECKING VARIABLE FILEDS IN A UPDATE QUERY ////////////////////////////////// //////////////// QUERY 1 ///////////////////////////////////////////////////////////////////// /* $db_database ="test"; $db_table ="users"; $RecNo = 1; $field1 = 'name'; $field2 = 'password'; $field3 = 'email'; $field4 = 'id'; $val1 = "Ajay"; $val2 = "howzatt"; $val3 = "me@mymail.com"; $con = mysqli_connect($db_host,$db_user,$db_pass,$db_database) or die('Unable to establish a DB connection'); $query = "UPDATE $db_table SET $field1 = ?, $field2 = ?, $field3 = ? WHERE $field4 = ? "; // session terminated by setting the sessionstatus as 1 $stmt = $con->prepare($query); var_dump($stmt); $stmt->bind_param('sssi',$val1,$val2,$val3,$RecNo); if($stmt->execute()) { $count = $stmt->affected_rows; echo $count; } //////////////// QUERY 1 END ///////////////////////////////////////////////////////////////////// */ //////////////// QUERY 2 ///////////////////////////////////////////////////////////////////// $con = mysqli_connect($db_host,$db_user,$db_pass,$db_database) or die('Unable to establish a DB connection'); $table = 'scores'; $date = date('Y-m-d H:i:s'); /* $prestr = "Mrt_M_"; $STATUS = $prestr."Status"; $S_R1 = $prestr."Scr_1"; $S_R2 = $prestr."Scr_2"; $PCT = $prestr."PPT"; $DPM = $prestr."DSP"; $TIMETAKEN = $prestr."TimeTaken"; */ $STATUS = "Mrt_M_Status"; $S_R1 = "Mrt_M_Scr_1"; $S_R2 = "Mrt_M_Scr_2"; $PPT = "Mrt_M_PPT"; $DSP = "Mrt_M_DSP"; $TIMETAKEN = "Mrt_M_TimeTaken"; $TimeOfLogin = $date; $no_of_logins = 10; $time_of_nLogin = $date; $m_scr_row1 = 5; $m_scr_row2 = 5; $m_ppt = 20; $m_dsp = 60; $m_time = 120; $date = $date; $RecNo = 24; $query = "UPDATE $table SET TimeOfLogin = ?, no_of_logins = ?, time_of_nLogin = ?, $S_R1 = ?, $S_R2 = ?, $PPT = ?, $DSP = ?, $TIMETAKEN = ?, $STATUS = '1', TimeOfLogout = ?, WHERE RecNo = ?"; $stmt = $con->prepare($query); var_dump($stmt); $stmt->bind_param('sisiiddssi',$TimeOfLogin,$no_of_logins,$time_of_nLogin,$m_scr_row1 $m_scr_row2,$m_ppt,$m_dsp,$m_time,$date,$RecNo); if($stmt->execute()) echo " DONE !"; ?>Thanks to all Hi, I'm pretty new to PHP and I am working on a form that sends and email. I want to display a message if the mail can't be sent (i.e. if mail() returns false) and a different message if mail() returns true, except it is returning false even though the emails are sending. Basically I have used: $to = 'myemail@email.com'; $subject = "Subject Line Goes here"; $headers = "From: $email"; $message = 'My message'; $mailSent = mail($to, $subject, $message, $headers); In testing it I have used the following to determine what is going on: if (isset($mailSent)) { echo '$mailSent ='.$mailSent; } - echo's nothing if ($mailSent == FALSE) { echo '$mailSent = FALSE'; } - echo's '$mailSent = FALSE' if ($mailSent == TRUE) { echo '$mailSent = TRUE'; } - echo's nothing if (is_null($mailSent)) { echo '$mailSent = NULL'; } - echo's '$mailSent = NULL' echo '$mailSent ='.$mailSent; - echo's '$mailSent =' Any help would be greatly appreciated! Thanks! How can I check if a function has returned false.. I know theirs the following way: if (!checkdate($month, $day, $year)) { //the function has returned false } But is their another way (beside using the ! operator) perhaps === FALSE (not sure if that'd work so asking)? I tried parsing through first https://www.jadaliyya.com/Details/28167/The-Empire-of-Sexuality-An-Interview-with-Joseph-Massad then even tried www.google.com and on both I get the following returned
post_url equals: www.google.compost_title equals: testpost_Threadybody equals: Enter your posts... URL equals: www.google.com www.google.com is not a valid URL Web page redirects after 2 seconds. And here is the if statement that handles my filter for URLs if(isset($_POST["submit"]) && !empty($_POST["url"]) && !empty($_POST["Title"])){ $URL = $conn -> real_escape_string($_POST["url"]) ; $BodyText = $conn -> real_escape_string(nl2br($_POST["ThreadBody"])) ; echo "<P>URL equals: " ; echo $URL ; echo "<P>" ; //Change to embed for youtube. if (filter_var($URL, FILTER_VALIDATE_URL)) { echo("$URL is a valid URL"); //Check if url is a youtube url if (strpos($URL,'youtube') !== false) { echo 'Youtube exists.'; $URL = preg_replace("/\s*[a-zA-Z\/\/:\.]*youtube.com\/watch\?v=([a-zA-Z0-9\-_]+)([a-zA-Z0-9\/\*\-\_\?\&\;\%\=\.]*)/i","<iframe width=\"420\" height=\"315\" src=\"//www.youtube.com/embed/$1\" frameborder=\"0\" allowfullscreen></iframe>",$URL); } else { echo 'Youtube is not included .'; $URL = "<ahref ='" . $URL . "</a>" ; } $Title = $conn -> real_escape_string($_POST["Title"]) ; $User = $_SESSION['username']; $sql = "INSERT INTO Threads (Title, Users, ThreadBody, url) VALUES ('$Title', '$User','$BodyText','$URL')"; if (mysqli_query($conn, $sql)) { echo "New record has been added successfully !"; } else { echo "Error: " . $sql . ":-" . mysqli_error($conn); } } else { echo("$URL is not a valid URL"); }
Code: [Select] <?php # This script does get included into the document create_new_tag_from.php if(isset($_POST['tag_name_submit'])){ $tag_name_submit = $_POST['tag_name_submit']; } if(!empty($_POST['tag_name'])){ $tag_name = strip_tags($_POST['tag_name']); } if(!empty($_POST['tag_description'])){ $tag_description = strip_tags($_POST['tag_description']); } if(isset($tag_name_submit)){ # The Validation of User Entered Data # Do validate for solely alphabetic characters with ctype_alpha # ctype_alpha($tag_name) && if(ctype_alpha($tag_description)){ $tag_name = strtolower($tag_name); $tag_description = strtolower($tag_description); # The Insertion Into the Database $db_connect = mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME); # Do research if SQL query has to be modified into a PHP comform query $sql_query = sprintf( "set @newid = convert( ( select max(convert( (substring(tag_id, 2)) , unsigned integer))+1 from tags), char(10) ); set @newid = if(length(@newid) = 1, concat('0', @newid), @newid); set @newid = concat('c', @newid); INSERT INTO tags (tag_id, tag_name, tag_description, added_by_user_id, creation_date, last_edited) VALUES (@newid, '%s', '%s', 7, now(), '0')", mysqli_real_escape_string($db_connect, $tag_name), mysqli_real_escape_string($db_connect, $tag_description) ); $sql_query_run = mysqli_multi_query($db_connect, $sql_query); # Print Test to See If It Works echo "works_ "; echo $tag_name . "_ "; echo $tag_description . "_ "; } else { # End of the Validation echo "The entered data must be in alphabetic characters."; } } ?> Here is the form: Code: [Select] <?php include_once('../../header.php'); include_once('../../model/contribution/create_new_tag_script.php'); ?> <form action="" method="post"> <input type="text" name="tag_name" value="" /> <textarea maxlength="60" type="text" name="tag_description" value=""></textarea> <input type="submit" name="tag_name_submit" value="Submit the New Tag" /> </form> <?php include_once('../../footer.php'); ?> By the script as given above the conditional check will skip to the error message. Though I have to say that ctype_alpha does return TRUE when I do try it with "tag_name" which is entered data from the input field, while the other is from the textarea. I simply cannot see the reason for the returned FALSE. Hello , this is my first post in this forum , i would like to see the following code and tell me your opinion , not about the security issues not about how good or bad it is. Its just a simple demonstration in order to show you the problem.
<?php include('config/functions.php'); $mysqli = connectionToDb(); $mysqli->autocommit(FALSE); $stmt = $mysqli->prepare("INSERT INTO users (first_name,last_name) VALUES ('stelios','stelios2')"); $stmt->execute(); $stmt->close(); $stmt = $mysqli->prepare("INSERT INTO users (first_name,last_name) VALUES ('stelios3','stelios4')"); $stmt->execute(); $stmt->close(); var_dump($mysqli->commit()); $mysqli->close();This is the code and the var_dump($mysqli->commit()); line prints false ! BUT , the inserts are in the database. If i comment out the commit line , then nothing is in the database. Can you advise ? Thanks ! in my code below the **data is extracted correctly for the first foreach but doesn't return anything for 2nd foreach though selected one present inside the 2nd foreach** i still get the error Warning: Invalid argument supplied for foreach() for line `foreach ($authorlist as $post)`... however the 2nd foreach returns data correctly as soon as i remove the first foreach loop. hi there, is there a difference between if($var == false) and if(false == $var) thankyou! guys this is my code <?php include("header.php"); include("conn.php"); ?> <html> <head> </head> <body> <table border="1" cellpadding="0" cellspacing="0" align="center"> <tr> <td>Please Enter the Amount</td> <td valign="top" align="left" width="200"> <form action="next.php" method="post"> <input name="amount" value="1" size="7"> </td> <tr> <td>From:</td> <td valign="top" align="left" width="200"> <?php $real= array ( 'USD'=>1, 'PAK'=>1.6323, 'GBP'=>1.02544 ); $abc= mysql_real_escape_string( serialize($real) ); //$ddsr=unserialize($abc); //$abc= implode(",",$real); //echo $abc; $from= array('Dollars','Rupees','Pounds'); $length = count($from); //$dbs=implode(",",$from); $dql = "INSERT INTO countrytype (`ID`,`fromcountry`,`tocountry`) VALUES ('','".$abc."','".$abc."')"; mysql_query($dql) or die(mysql_error()); $to= array('Dollars','Rupees','Pounds'); $to=str_replace("","",$to); ?> <input type="hidden" name="h1" value="<?php echo $length;?>"> <select> <?PHP $dgd= "SELECT * FROM countrytype GROUP BY ID"; $aws= mysql_query($dgd) or die(mysql_error()); while($row=mysql_fetch_array($aws)) { $des=stripslashes($row['fromcountry']); $dsw=unserialize($des); //$des=explode("",$row['fromcountry']); //var_dump($dsw); //echo "<td>".$row['ID']."<td>"; //echo "<td>".$dsw."<td>"; $k=1; foreach($dsw as $key=>$value) { echo "<option name='ad[]' value='$value'>$value</option>"; //print_r(array_keys($des)); $k++; } } //$sss=explode("",$row['fromcountry']); //echo $sss; ?> </select> <select> <?php $i=0; $k=1; foreach($from as $abd => $value) { echo "<option name='ar[]' value='$value' >$value</option>"; $k++; } ?></td></tr></select> <td>To: </td><td><select> <?php foreach($to as $abd => $value) { $i++; echo "<option id='i' >$value</option>"; } ?> </select> <input type="submit" name="sub" value="Convert!"/> </form> </td> </tr> </tr> </table> </body> </html> serilization works but when i fetch it from database and unserialize it nothing works Hey I got this script which is trying to unserialize but i get this error and have no idea what it means so i equally have no idea how to fix the problem. This is what it says: Quote Notice: unserialize() Error at offset 0 of 4 bytes This is the line which causes the error: Code: [Select] <?php $contents = unserialize(file_get_contents($this->msgsFile)); ?> Does any one know what the error means? And what i need to look for to fix it. I took an object, and saved it into a database serialized. Code: [Select] $object_here = serialize($theobject); Then later on, I go and I get that data from a database, and try to unserialize it.. Code: [Select] $objecthere = unserialize($row->theobject) And it throws the following error...any advice? Quote Warning: unserialize() [function.unserialize]: Node no longer exists in /path/to/file on line 20 i tried to serialize an array in php but im not sure if i had the right syntax $field[0] = "Student Name"; $field[1] = "fail"; $field_ser = serialize($field); $field_unser = unserialize($field_ser); i think i didnt do it right Need a bit of help with some php and a few kind members helped me in the past. My code is: $query = "SELECT names FROM table WHERE type='$type'"; $result = mysql_query($query) or die(mysql_error()); while($row = mysql_fetch_array($result)) { foreach(unserialize($row['names']) as $key => $value){ echo $value . '<br />'; } } Basically, a field on my table is called names. The information in this field is serialized (so many names are together in a single field, for a single row). I want to be able to search the whole table (where type='$type' - so many rows) for all names and then show unique names only. My code above unserializes the names from each field and then lists them, but doesn't deal with any duplicates (which I need removing). I have looked at functions like "unique_array()", and have tried using it in different places but it isn't doing the job. Any help appreciated. Hi, I'm new to PHP and wondered if anyone could help... I am consuming an asmx webservice using PHP code. (Later to make a widget for wordpress). I can receive all the data, but it is in one very big xml file. I want to be able to convert this data, so I can make it more readable. Could really do with help as I don't have a clue how to convert it. ANy ideas? I have an array from the database like so Array (2) ( | ['0'] => Array (4) | ( | | ['f_fid'] = String(1) "1" | | ['0'] = String(1) "1" | | ['f_names'] = String(99) "a:4:{i:0;s:18:"register_user_name";i:1;s:5:"r_u_n";i:2;s:10:"user_alias";i:3;s:12:"nickusername";} " | | ['1'] = String(99) "a:4:{i:0;s:18:"register_user_name";i:1;s:5:"r_u_n";i:2;s:10:"user_alias";i:3;s:12:"nickusername";} " | ) | ['1'] => Array (4) | ( | | ['f_fid'] = String(1) "2" | | ['0'] = String(1) "2" | | ['f_names'] = String(104) "a:4:{i:0;s:18:"register_password";i:1;s:5:"r_pass_word";i:2;s:10:"user_pass";i:3;s:12:"reg-pass-word";} " | | ['1'] = String(104) "a:4:{i:0;s:18:"register_password";i:1;s:5:"r_pass_word";i:2;s:10:"user_pass";i:3;s:12:"reg-pass-word";} " | ) ) So i use a foreach loop to turn the serialized value into an array foreach($fields as $key => $val) { $fields[$key]['f_names'] = unserialize($val['f_names']); } But for some reason the last f_names is false Array (2) ( | ['0'] => Array (4) | ( | | ['f_fid'] = String(1) "1" | | ['0'] = String(1) "1" | | ['f_names'] => Array (4) | | ( | | | ['0'] = String(18) "register_user_name" | | | ['1'] = String(5) "r_u_n" | | | ['2'] = String(10) "user_alias" | | | ['3'] = String(12) "nickusername" | | ) | | ['1'] = String(99) "a:4:{i:0;s:18:"register_user_name";i:1;s:5:"r_u_n";i:2;s:10:"user_alias";i:3;s:12:"nickusername";} " | ) | ['1'] => Array (4) | ( | | ['f_fid'] = String(1) "2" | | ['0'] = String(1) "2" | | ['f_names'] = Boolean(0) FALSE | | ['1'] = String(104) "a:4:{i:0;s:18:"register_password";i:1;s:5:"r_pass_word";i:2;s:10:"user_pass";i:3;s:12:"reg-pass-word";} " | ) ) Anyone have any idea why? Thanks |