Skip to main content

Posts

Showing posts with the label php5

PHP weird Seg-faults on mysqli_stmt_bind_result

When migrating a PHP script from PHP 5.2 to PHP 5.3, I've stumbled to the following problem: The general purpose of the script is data mining. I have a procedure inside that adds data to the MySQL server. Since it is really repetitive, I've rewritten it (a while ago) to use MySQLi, in particular prepared statements, since there are a total of 3 possible queries to perform. Anyway, now, on the PHP 5.3 server, the script is crashing on the following line:

Is it bad to declare an empty class?

In my spare time, I am building a Sudoku solver to try to get the hang of OOP in PHP. A Sudoku puzzle, for those of you who don't know, is in its most common form a 9x9 matrix of numbers from 1 to 9, with 3x3 squares delineated in a tic-tac-toe like pattern. Some numbers are filled in in advance. The goal of the puzzle is to fill in the remaining numbers, so that no row, column or 3x3 square contains the same number more than once.

ACL implementation

First question Please, could you explain me how simpliest ACL could be implemented in MVC. Here is the first approach of using Acl in Controller... <?php class MyController extends Controller { public function myMethod() { //It is just abstract code $acl = new Acl(); $acl->setController('MyController'); $acl->setMethod('myMethod'); $acl->getRole(); if (!$acl->allowed()) die("You're not allowed to do it!"); ... } } ?> It is very bad approach, and it's minus is that we have to add Acl piece of code into each controller's method, but we don't need any additional dependencies! Next approach is to make all controller's methods private and add ACL code into controller's __call method. <?php class MyController extends Controller { private function myMethod() { ... } public function __call($name, $params) { //It is just abstract code $acl = new Acl();

Zend_Gdata and OAuth

I successfully retrieved token key / secret after applying Google Hybrid Protocol (OpenID + OAuth). Then I'm looking into Zend documentation here: http://framework.zend.com/manual/en/zend.gdata.html ... and into Calendar API example here: http://code.google.com/googleapps/marketplace/tutorial_php.html#Integrate-OAuth They mention about AuthSub method supported by Zend_Gdata library (especially in Zend_Gdata_HttpClient class form what I can see). But I cannot figure out how to use my key/secret tokens retrieved by Hybrid method in order to access calendar feeds. Example mentioned above uses AuthSub authentication, while Google recommends to switch to OAuth if possible and where possible, instead of using AuthSub. Any ideas? Thanks.

Send data from android to mysql using php

I have a some text on an android client, I want to send it to the database(MySQL). How do I do this.Please help me with this. I tried using php and Mysql. Is the query in Php right?? Here is what I have tried Insert.java public class Insert extends ListActivity { String[] ct_name = null; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // setContentView(R.layout.main); InputStream is = null; // http post ArrayList<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(); nameValuePairs.add(new BasicNameValuePair("c_name","KL")); try{ HttpClient httpclient = new DefaultHttpClient(); HttpPost httppost = new HttpPost("http://10.0.2.2/city1.php"); httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs)); HttpResponse response = httpclient.execute(httppost); HttpEntity entity = response.getEntity(); is = enti

Send data from android to mysql using php

I have a some text on an android client, I want to send it to the database(MySQL). How do I do this.Please help me with this. I tried using php and Mysql. Is the query in Php right?? Here is what I have tried Insert.java public class Insert extends ListActivity { String[] ct_name = null; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // setContentView(R.layout.main); InputStream is = null; // http post ArrayList<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(); nameValuePairs.add(new BasicNameValuePair("c_name","KL")); try{ HttpClient httpclient = new DefaultHttpClient(); HttpPost httppost = new HttpPost("http://10.0.2.2/city1.php"); httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs)); HttpResponse response = httpclient.execute(httppost); HttpEntity entity = response.getEntity(); is = enti

Escaping quotes - moving from PHP4 to PHP5

I've inherited a php4 site that needs to run on my PHP5 Server, I've solved most of the issues but can't figure out what the author was trying to do here. Well, to be precise, he was tring to quote the submitted text but I'm not sure how this function is supposed to work and how I should do it in PHP5? # Function to safely add slashes when magic quotes is switched off function safe_slash($string) { if (!get_magic_quotes_gpc()) { $string = addslashes($string); } return $string; }

Behaviour of glob function in php is different with open_basedir

I migrate from sugar 5.2 to sugar crm 6.2 and i'm using open_basedir and it doesn't work ... I detected the problem in the code. It's the function glob which returns false (with open_basedir) instead of an blank array (with open basedir disactivated) The file with the problem is modules/ModuleBuilder/parsers/views/History.php line 72. foreach (glob($this->getFileByTimestamp('*')) as $filename) { if(preg_match('/(\d+)$/', $filename, $match)) { $this->_list [] = $match[1]; } } (if glob return null, there is an error) When I look for the documentation of glob http://fr2.php.net/glob , there is a flag *GLOB_ERR* : Stop on read errors (like unreadable directories), by default errors are ignored. But it doesn't change, the result is false and I've no error. The configuration of open base dir allow the application path, /tmp and /usr/share Does someone know how to resolve that

imagesx() and imagesy() error when creating tumbnail

I want to create thumbnail image for top posts automaticly. So I decided to resize current image of post with small sizes for using it as tumbnail using this - resize-class.php class and wrote the code like this: // Include the class include("resize-class.php"); $top_posts = mysql_query("In this query I select top posts - the most viewed posts of the day") while ($row = mysql_fetch_array($top_posts)){ $post_id = $row['post_id']; // defining the ID of the post as variable $post_image = $row['post_image']; //defining the image of the post as variable //save image $resizeObj = new resize($post_image); // Initialise - load image $resizeObj -> resizeImage(260, 210, 'exact'); // resizing $post_image with 'exact' option $resizeObj -> saveImage('images/'.$post_id.'.jpg', 80); // saving thumbnail of $post_image to the storage } But returns the errors in loop like this: Warning: imagesx() ex

Find a url in content a site by url it?

I want search into content a site by url it site, if existence my url (for example: http://www.mydomain.com/ ) return it is TRUE else it is FALSE. If existence url as following list, Return it is FALSE: - http://www.mydomain.com/blog?12 - www.mydomain.com/news/maste.php - http://www.mydomain.com/mkds/skas/aksa.html - www.mydomain.com/ - www.mydomain.com I want just accsept(find) as(only): http://www.mydomain.com/ OR http://www.mydomain.com I tried as: $url = 'http://www.usersite.com'; $ch = curl_init(); curl_setopt($ch, CURLOPT_URL,$url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); $contents = curl_exec($ch); curl_close($ch); $link="/http:\/\/mydomain.com/"; if(preg_match("/". preg_quote($link,"/"). "/m", $contents) && strstr($contents,"http://www.mydomain.com")){ echo 'TRUE'; } else{ echo 'FALSE'; } But it doesn't worked, for it w