php

Protecting the login page

I'm trying to add extra security to my drupal site. I removed the login block, but it can also be accessed through http://mydrupalsite.com/user It's still needed to allow the admin account in, but is there a way to protect this single page with htaccess or something more robust than what drupal allows out of the box? ...

number formating problem in php and ajax

i have one text box formated with follwoing syntax $("#cont_dt").blur(function(){ $(this).format({format:"#,###.00", locale:"us"}); }) this work fine, for example if i type 250000.50 it automatically formated to 250,000.50 but the problem is when i try to pass same value to php file via ajax to add recor...

I have an array on strings in php. I want to replace all occurrences of those strings with another string within a block of text

I have an array that contains several domain names. I need to replace those domains inside blocks of text (forum posts) with another string, if any of them actually appear inside that forum post. Whats the best way of doing that? I can't alter the array that contains a list of domains it would search for. Its stored as follows: $doma...

how to test mail() using PHPUnit

Hello, is there a way to test with PHPUnit (or maybe other testing framework for PHP) if mail is sent correctly? I have to test a code which uses PHP function mail() . With custom mailer class i could always make a mock, but for mail() ... ? Maybe there is some plugin which is capable to use IMAP and verify if mail is received? (and it ...

beanstalkd weirdness, returns invalid jobs

beanstalkd is playing tricks on me. As you can see from the following series of commands, there are ready jobs, but I cant peek, delete, or do anything with them. watch ab_similar_sync_node WATCHING 1 stats-tube ab_similar_sync_node OK 272 --- name: ab_similar_sync_node current-jobs-urgent: 0 current-jobs-ready: 8521 current-jobs-reser...

PHP: Removing object by reference from associative array

Hey guys, I've got a recursive function searching an object by index in a multidimensional, associative array. $settings = array( 'title' => new XCPreferenceShortText('title'), 'html' => new XCPreferenceLongText('html'), '_blog' => array( '_blog' => new XCPreferenceHeading('blog'), 'acceptcomments' => new XCPreferenceBoolean('a...

tcpdf and image with bad links

Hi, i use latest TCPDF version. If the text is a picture of a bad link shows an error and do not generate a PDF file. Is it possible to disable this error? If you did not find the image to generate the PDF, but without a picture. I hope to understand my problem, Thanks ...

preg_match() and username

function isUserID($username) { if (preg_match('/^[a-z\d_]{2,20}$/i', $username)) { return true; } else { return false; } } Easy one.., i have this, can you explain what it checks for? I know it checks if the username have length between 2-20, what more? Thanks ...

How can I get html webpage charset encode from html as string and not as dom?

Hi, How can I get html webpage charset encode from html as string and not as dom? I get html string like that: $html = file_get_contents($url); preg_match_all (string pattern, string subject, array matches, int flags) but i dont know regex, and I need to find out webpage charset (UTF-8/windows-255/etc..) Thanks, ...

How to generate a 9 digit number

I'm trying to use php to generate a 9 digit number that does not start with a 0 and is separated by dash every third number. e.g. 102-394-458 I'm also debating whether to store it as a number or do the formatting on the front end or to store it as a number and do the formatting on the backend or to just store the dashes in the dat...

Using Email Class in Codeigniter (Advanced Way)

I want to send emails using Email Class(CodeIgniter) Problem is that Email is sending so simple in text format... I want to design email with (html, tables and colors) or What is the advanced-way for Emailing with CodeIgniter. ...

how to connect two tables with sql and php

I am a bit new to sql and php so I need some help here. I created two tables and I want to establish a 'one-to-many relationship' but I can't figure out how I can give the data through the php file. Here is some code: CREATE TABLE `details` ( `details_id` int(11) NOT NULL AUTO_INCREMENT, `name` varchar(30) NOT NULL, `latitude` ...

echo <img> tag...

Hello there, I getting crazy trying to echo an <img> tag I want to add this simple string "/uploads/" before $photo->name...Here is my echo: echo '<img src="'.$photo->name.'"/>'; thanks for any help... ...

Help with a joined query (MySQL)

Hello can anybody see why this query fails? SELECT A.idAd, A.ads_in_Cat, A.title, A.currency, A.price, A.in_dpt, A.description, A.featured FROM ads A LEFT JOIN featured F ON F.ad = A.idAd INNER JOIN dept D ON D.id_dept = A.in_dpt INNER JOIN sub_cat_ad S ON S.id_sub_cat = A.ads_in_Cat INNER JOIN cat_ad C ON C.idCat_ad = S.from_cat_ad ...

mysqli prepare statement using select failing for some unknown reason

Why is this failing? I am connected to the correct db, and keys is definitely there. //verify key against key list in database if ($prep_statement = $db->prepare("SELECT id FROM key_list WHERE keys=?")) { $prep_statement->bind_param('s',$key); $prep_statement->execute(); echo $prep_statement->num_rows; $prep_statement->...

Submit form button not working for simple todo list app (I'm new to CakePHP)?

Hello, I am learning cakephp, and I was just doing a simple Todo list app from a book. The app basically takes in a task from an input field, then you click 'Add Task' and the task should be added to database and then the user gets redirected to Tasks View page where all the tasks can be seen including the one they just added. In the ad...

Reducing the number of queries from 2 to 1

Is it possible to use 1 query instead 2? Or this way is better? (for speed) <? $q1 = mysql_query("SELECT name,url,id FROM gallery") or die(mysql_error()); if (mysql_num_rows($q1) > 0) { while ($row = mysql_fetch_array($q1)) { echo 'IMAGES FROM '.$row['name']; $id = $row['id']; //second query for each gallery $imgq ...

Resources for the state design pattern implemented in PHP?

I am looking for resources and examples of the state design pattern for PHP. Could anybody share these with me? ...

Singleton database.php

If I have a database.php class (singleton) which reads and writes information for users of my web application, what happens when simultaneous requests for the same database function is called? Is it possible that the database class will return the wrong information to other users accessing the same function at the same time? What othe...

How to print direct links to page numbers, next to the thread subject in a forum?

Ciao, In my forums where I list all the threads, I want also to show links to pages. Like: http://www.phpbb.com/community/viewforum.php?f=6 (As you can see, it prints the number of pages for the threads that have more than 1 page.) How should I do so it prints Page 2 if it has more than 10 posts? I'm not taking about paging, I have ...