php

How to get UNIX_TIMESTAMP to not offset a datetime field when in different time zones?

I have built a small forum where users can post messages. My server is in the United States, but the userbase for the forum is in Taiwan (+15hrs). When someone posts to the form, I store the time in my mySQL database in the format YYYY-MM-DD HH:MM:SS. When I look in the database, the time displays the proper time (the time that the pe...

PHP array, Are array indexes case sensitive?

I don't know if this is a problem yet but wanted to start thinking about it. Question: "Are PHP array indexes case sensitive"? Example: $a=array("a"=>"Dog","b"=>"Cat","c"=>"Horse","A"=>"Dog","B"=>"Cat","C"=>"Horse"); print_r($a); Results: Array ( [a] => Dog [b] => Cat [c] => Horse [A] => Dog [B] => Cat [C] => Horse ) I've run a ...

php header redirect based on post variables

I have visitors coming to my site from 5 seperate sources, each one sends a variable in the url based on where its from, in the event these sources sends visitors I want to send them to a seperate page thats more relevant to the user <?php $var = $_GET["var"]; if( $var='site1') { header('Location: ' . "http://www.mysite.com/site1page"...

How would this lookup table example work?

Say I have a products table that stores off the shelf products that are not customizable and have static pricing. I also have 1 product in this same table that is customizable and it's price and all sorts of characteristics vary based on the configuration. The final price for this customizable product is based on an equation, not a sum...

MYSQL - Date query and display(PHP) question

I am currently trying to write a little program to track time-off requests for employees. I'm fairly new to MYSQL and PHP, so it's a learning project for me as well. I've run into this problem which I do not seem to be able to figure out. I want to display time off requests for a given week (Mon-Fri). I've got the requests in a table 'r...

Why rawurldecode doesn't works?

I have UTF-8 string(from DB), and when i run: echo rawurldecode('S = &#40; a &#43; b ) &#42; &#40; a &#43; b ) : 4'); as result i see: 'S = &#40; a &#43; b ) &#42; &#40; a &#43; b ) : 4' I can't to get full access to this project. What can be wrong? ...

PHP multidimensional array

I have an array declared above the beginning of a for loop as: $array = array(); Now, in the for loop I start inserting values into it. At some point I make one of its index as another array as $array[$j]=array(); And insert some values like, $array[$j][$l] = id; and so on. Now, when I use print_r ($array) ; inside the loop I get the e...

How to count the occurences of multiple patterns in a long string?

I have a long string, and an array of country names. So the array looks something like this: array('Afghanistan', 'Bulgaria', 'United States', 'Bulgaria', ...) I need to count the number of times each country appears in the string. Is there a quick and nifty way of doing this, i.e., some kind of magical preg_match_all which receives ...

Testing whether a Facebook session is valid?

I'm not sure if the php server side Facebook library validates sessions on load. So then I want to know if there is a best practice for insuring that I really do have a valid FB session and not some crackers altered $_COOKIE data. $fb = new Facebook(); if( $fb->session_expires !== 0 && $fb->session_expires < time() ) { die('bad and/or...

cp command within php resulted in a partial copy

I have a small PHP script I wrote to help me push changes from staging to production. I run both staging and prod on the same server so my script copies changes from staging folders to prod folder. This has been working fine until today when I had a few instances when files were only partially copied over resulting in some down time....

How to force php to work in my browser?

Hi, I just installed PHP on my computer (Ubuntu). If I create a test.php file with simple code and then run "php test.php", it works fine (I get what I expect). However, if I open this file (test.php) with my browser (Mozilla) it ask me how to open this file. Not a problem. I click "open with" and then I select "/usr/bin/php" and... noth...

PHP MySQL SELECT text truncated

I have a MySQL table with a column 'full_description' of type 'text'. In that column is a standard lorem ipsum (plus the word END): Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris n...

Pear Log MDB2 message length and errors

Hey all, I recently set up a SQL logging framework with PEAR, and everything was working fine. However, I thought that the default length of the message field (VARCHAR 200) was a little short, so I changed my database structure in phpmyadmin to increase this to 512. However, I quickly realized that this changed completely stopped loggi...

Building a real object oriented framework in PHP, suggestions wanted

I've been using the CodeIgniter framework, however after learning Java and awesome features like Interfaces, Abstract classes, packages, and that PHP 5 also supports most of these features, I'm ready to graduate and build a real OO framework in PHP which uses all of these features (including namespaces), so I can build much more elegant ...

Why I cannot use my apache server?

Hi, I just installed apache server on my local machine. I executed the following command for that: sudo apt-get install apache2 sudo apt-get install php5 sudo apt-get install libapache2-mod-php5 sudo /etc/init.d/apache2 restart However, if I put my test.php file in /var/www and open it with my browser I see nothing (I supposed to see ...

Emacs not indenting PHP correctly, although C/C++ do?

I am running GNU Emacs 22.2.1 on a HP notebook running Ubuntu 9.04 with the latest patches. Recently, I need to handle some PHP codes, so I added Ubuntu's php-mode package, thinking what I have in my .emacs would cover the basics. Well, almost. The following short snippet shows the symptom: <?php # main() /* * * */ { $fpath="...

MySQL: Creating a list of conversations (last msgs to/from user_id)

Hi, I have a mysql table containing messages: id (INT) sender_id (INT) recipient_id (INT) sent_time (INT) read_time (INT) body (TEXT) I need to retrieve a list of most recent messages user X received from or sent to other (distinct) users. In other words I'd like to create a full list of conversations with other users, sorted by sen...

Mysql Order By Calculated Value - User Defined Weightings of Categories

Hi All, I have a small problem with some late additions to a project, mysql and PHP. We have a table in mysql with 200,000 rows, each with an assigned category. Originally the select statement would just pull out the required items based on a where clause and order by an indexed id. Very quick. However we had some users request the ab...

Jquery ajax loaded content refuses jquery to work

hi guys, This is my first time here so go easy with me. I am keen on mastering codeignter and jquery for web app dev. I have made progress but I am at a point I was hoping I would pick on your great minds over. I have links where I click and they fill up a div with content and this works but I use the $.ajax({}); not get or post or loa...

Is it possible to write strictly typed PHP code?

For example, is it possible to write code like this: int $x = 6; str $y = "hello world"; bool $z = false; MyObject $foo = new MyObject(); And is it possible to define functions like this: public int function getBalance() { return 555; //Or any numeric value } ...