php

PHP code to check country from IP

I understand how to code this all. My question is: say I got a dump of the IP address ranges for countries, would it be changed at some sooner point of time? and how often? Thanks ...

altering variable inside print/echo?

cant you? Instead of $next_page = $pageNumber + 1; print '<a href="'.$url.'/page/'.$next_page.'">Next &raquo;</a>'; i would like to write it like this print '<a href="'.$url.'/page/'.$pageNumber+1.'">Next &raquo;</a>'; the last one gives my parse error. why? ...

PHP rename does not work

Hi, I download a file with cURL using option CURLOPT_FILE and then try to rename the downloaded file, for example, from "1.txt" to "2.txt". It fails to rename the file. PHP throws an error: "Warning: rename(E:\.../test/1.txt,E:\.../test/2.txt) [function.rename]: No such file or directory in E:\.../test\lib\CURL\Download.php on li...

Chaining method PHP

<?php $sth = Framework::blah()->any_key['any_key_2']; ?> Hello, I want to get 'any_key' and 'any_key_2' in blah(), how I do that? ...

I don't want a session to be invalid until the browser is closed

Hi, Storing the session id on the client computer is no problem and is very straight forward. The problem is to store the actual session on the server until I'm actually feeling I'm done with it. The garbage collector is pretty clear about how it works. I can see no way to prevent it from cleaning up the garbage within a certain time. ...

PHP sanitization question.

Is it safe if I just use htmlpurifier for some of my user submitted data so they can enter html code like myspace? http://htmlpurifier.org/ Here is a sample code of PHP and htmlpurifier. $purifier->purify($content); ...

How to get rid of error messages with PHP's imap_fetchstructure()?

Hi! PHP provides very useful functions to fetch emails from a POP3 account, in my case to handle bounce-mails. The function imap_fetchstructure(), however, gives me headache. When using it in one script, I (for some mails) get the message: Notice: Unknown: Warning: MIME header encountered in non-MIME message (errflg=3) in Unknow...

Which PHP-template to load depends on javascript support

I have the following scenario: A multiple step registration procedure. Let's say it's 4 steps, and each step depends on previous input. This could be solved with or without Javascript. Without JS: A "proceed"-button is attached to each step With JS: The next part is automatically revealed to the user when previous step is done. (No "pr...

Passing an object between two controllers

Hi, I have two controllers , and I have one object. I want to pass that object between my two controllers in CodeIgniter. There is a registry or something like that?? Example - I am using ipbwi (for invision power board 3.1 integration ) , on my main controller I am doing this - private $ipbwi; function Main() { parent::Cont...

PHP: Codeigniter style-url:s?

Hi everybody, I am looking for some help on how to create the sort of URL-rewriting CodeIgniter features for my own PHP pet application. I know that the .htaccess-file does one part of the magic, but how does a PHP file looks that handles the URL splitting and calling of controllers/methods accordingly to the URI? Thanks a lot for yo...

Nested versus composite conditions

Which one of these 2 examples would perform better: Example 1: if($condition_1) { if($condition_2) { // do something } } Example 2: if($condition_1 and $condition_2) { // do something } ...

PHP Error, what did i do wrong?

Hi, i have this code: <?php $stap2 = $_POST['stap2']; $stap3 = $_POST['stap3']; $stap4 = $_POST['stap4']; $klaar = $_POST['klaar']; if(isset($klaar)){ $cijfer1 = $_POST['cijfer1']; $cijfer2 = $_POST['cijfer2']; $cijfer3 = $_POST['cijfer3']; $cijfer4 = $_POST['cijfer4']; ...

SELECT JOIN in same table ON multiple rows...

I have a table with an itemID and a categoryID columns. Both columns are primary keys because each item can have more than 1 category: itemID | catID ----------------- 1 | 2 1 | 3 1 | 4 2 | 2 2 | 3 2 | 4 I want to select items with the same categories (based on all the item categories,...

Doctrine 2: Call to a member function format() on a non-object ... in DateTimeType.php

i have a datatime field /** * Date time posted * @Column(type="datetime") */ private $dtPosted; set to a default value by use of a LifeCycleCallback /** * @PrePersist */ function onPrePersist() { // set default date $this->dtPosted = date('Y-m-d H:m:s'); i am getting Fatal error: Call to a member function forma...

How can I get the number of queued jobs of a particular type in gearman?

I have a number of gearman clients sending a job, say job1. $client = new GearmanClient(); $client->addServer(); $client->doBackground('job1', 'workload'); It takes, say 10 seconds to process this job. I want to track how many 'job1' jobs are waiting for a worker to work on them at any given time. How can I do that? ...

Cheking if a webpage is online (best practices for making a Uptime Bot)

Hello, im making a investigation and i need to check every 15 min for about 7 days if a web site is online. I have the url and high programing skills in VB6 and PHP, and some ideas of how to do that (like making a ping to the port 80 of the url), but due the important of this investigation i need recomendation from professionals, so if y...

MYSQL delete where value = multiple POST values

I'm trying to put this, check_box=147&check_box=148&check_box=146 etc.. into $delete_selected = $connection->real_escape_string($_POST['check_box']) $sql = "DELETE FROM categories WHERE cat_id = '$delete_selected'"; but it only deletes the first check_box value. Is there a way to loop through all the values? ...

Scope of class declaration

I have a file classes.php in which I declare a set of classes to be used in a series of pages. Then, in one page, I need to use another class, that is declared in a separate file. Now, this separate class uses some classes located in the classes.php file. So, in most pages, I have: [1] <?php require('classes.php'); [page code] ?> whi...

append encoding on creation of xml file

this code creates an xml file if it does not exist: $xmldoc = new DOMDocument(); if(file_exists('test.xml')){ $xmldoc->load('test.xml'); } else { $xmldoc->loadXML('<root/>'); } however, i would also like encoding="UTF-8" to be appended automatically on creation of the file. how would one do this in php? ...

Generating gradients from a hexcode or RGB in PHP/jQuery?

Hello, I'm trying to figure out how to write a function that programmatically retrieves a background-color css attribute and creates two outputs (one slightly darker than the background-color, one slightly lighter). The idea is being able to generate a very basic linear gradient from a single color selection. Anyone have any ideas? ...