php

Does PHP have a default assignment idiom like perl?

In Perl, if I want to default a value that might exist, for example as a passed in parameter, I can do this: $var = parm->('variable') || 'default'; Is there something analogous in PHP or do I have to check the value after assigning, and if it is still null assign it the default value? ...

Calculating the number of Saturdays and Sundays

How can I calculate the number of Saturdays and Sundays between two dates in php? Is there any inbuilt function for that purpose? ...

Magento quantity field doesn't work

Hi, i simply can't find a solution to my problem! The quantity field worked as it should. After a few months of programming on the whole shop, i wanted to test the quantity field and recognized that it doesn't function. I only can add one product to the cart although i typed “3” in the quantity field. I didn’t change anything in produ...

Drupal - Break up content with different content (After every 12 products, show an ad?)

Currently I have the homepage of a t-shirt site list a 4 column grid, each cell containing all the shirts on the website (using views). The client would like every few rows to display an ad (perhaps a random view/block item). Is this possible? I'm sure I will end up needing to set the grid display to something else but how could I progra...

php simplexml_load_file() with password protected url

Simple question for the one who knows the answer... $xml = simplexml_load_file("http://url/path/file.xml"); This url is .htaccess protected, how can I pass the login/password as arguments to the function? ...

Problems with PHP System_Daemon and IMAP connection.

I'm trying to create a PHP daemon that connects to an IMAP server and processes emails as they come in. I have it close to working, but the daemon keeps grabbing the original emails that it finds the first time the daemon is loaded. I believe the reason is because I'm opening the IMAP connection in the parent process. Example below: i...

How to iterate over an array of objects without foreach and ArrayAccess

Hi, I'm having to develop a site on PHP 5.1.6 and I've just come across a bug in my site which isn't happening on 5.2+. When using foreach() to iterate over an object, I get the following error: "Fatal error: Objects used as arrays in post/pre increment/decrement must return values by reference..." Does anyone know how to convert the fo...

Inheritance in kohana

Hi all, I have recently started to use Kohana and I know inheritance is in infancy stages at the moment. The work around is using a $_has_one annotation on the child class model. In may case i have "page" as the parent of "article". I have something like, protected $_has_one = array('mypage'=>array('model'=>'page', 'foreign_key'=>'id'))...

routing problem in codeigniter

I'm new to CodeIgniter and routing. I have a Login controller whose index() loads up a view to enter a username/password. In the view, the form has action="login/authenticate". Login->authenticate() determines if the login is valid or not. If it's valid, redirect('lobby'), if not redirect('login') routes.php: $route['default_controlle...

prevent multiple login with same login credentials in php

My website has premium videos, for which users have to pay to watch it. I am sending a random user name and password to the user's email id when the payment is completed. Then I want to assure no more than one user use that login credentials simultaneously. For that I use a login_status column in database table with login credentials and...

PHP Get images from a UL list

I have a long UL list and each LI contains an image tag, dynamically generated from SLideshowPro Director. I need to get the widths of ALL the images inside the UL to use in a CSS width calculation. I have been able to get the image width for the first item, but not all. My PHP is pretty limited, but do I have to make this list into a...

How to get elements from a page using Simple HTML DOM Parser

Hi I am trying to parse a HTML page using the Simple HTML DOM Parser. This HTML page doesn't make use of IDs which makes it harder to refer to elements. On this page I am trying to get the Album name, Song title, download link and the album image. I have done this but I can't even get the Album names! $html = file_get_html('http:/...

How does one retrieve and display posts on a forum?

I'm struggling with a conceptual question. When you have a forum with thousands of posts and/or threads, how do you retrieve all those posts to be displayed on your site? Do you connect to your database every time someone visits your page then capture every post in an array and display it? Surely this seems like it would be very taxing o...

Selenium RC: How to check if an element has a given attribute?

I have some buttons with an onclick attribute and some that don't. I want to check if the specified element has the onclick attribute. How can I do this? getAttribute() returns the attribute value when it has one. When it doesn't, it throws a RuntimeException and stops the test (even when I wrap it in a try/catch block). $onclickValue ...

fetching only new rows from mysql with jquery ajax

i have a table named news with 3 fields i.e (id, news, time) and i have a setInterval after every 3mints to fetch news from google or any news site .... now i want to fetch only new rows inserted after every 5 minutes...with jquery $.ajax()...how can i do that... do i reload the whole table or there is a way to fetch only the new ones....

Get the index value of an array in php

I have an array: $list = array('string1', 'string2', 'string3'); I want to get the index for a given value (i.e. 1 for string2 and 2 for string3) All I want is the position of the strings in the array string1 is 0 string2 is 1 string3 is 2 How to get this? I tried array_search but it was no use ...

Is there a way to track a GPS device using PHP?

In my upcoming project, I need to track GPS device attached to vehicles. Is there any way this is possible through PHP or ASP.Net ...

PHP database simulation

I have a PHP script that works by calling items from a database based upon the time they were placed in there and it deletes them if they are older than 5 minutes. Basically, I want to now simulate what would happen if this database was being updated regularly. So I was considering sticking in some code that loads an XML file then goes ...

Ways I can protect my site excluding XSS and Sql injection?

Hi,So, members of my website can post topics, replies, comments, edit them and so on. I always use htmlspecialchars and addslashes for html inputs to protect my site against XSS and SQL injection attacks. Is it enough or is there something more I miss? Thanks. ...

Getting a 1064 Error in MySQL but query still completes? Not sure why!!

Hi there, I am trying to insert a lot of fields into a MySQL database, some are failing, so I am adding some code into my PHP script to try and track down what is occurring. The replace seems to work as I can see the fields being populated in mysql, but I get this error: 1064:You have an error in your SQL syntax; check the manual...