php

To convert PHP's while loop to a for -loop

How can you convert the following while loop to a for -loop in PHP? while( $row2 = pg_fetch_row( $result_tags ) While -loops are a source of errors for me. I see the while -loop as follows. for ( $i = 0 ; $i < count(pg_fetch_row( $result_tags )) ; $i++ ) ...

loop categories with assigned forums

forumcats: id, name forums: id, name, cat_id How can i join these together and print the forums assigned to the categories under them Would really appriciate if someone could give me a hand This is what i mean: A category A forumA forum A 2nd category Another forum Another forum Another forum A 3rd catagory Another forum A...

Can this watermark function be improve (PHP)

Below is a watermark function I made for my php photo upload script. I am curious if there is a better way of doing the parts that check for the file type, notice I had to use that part of code 2 times <?PHP function watermark($source_file,$source_width,$source_height,$image_type) { //first image below will be large then small in 1...

php $_POST array empty upon form submission...

Hi folks, I'm baffled on this after much googling. This issue is simple, I have a custom CMS i've built that works perfectly on my dev box (Ubuntu/PHP5+/MySQL5+). I just moved it up to the production box for my client and now all form submissions are showing up as empty $_POST arrays. I found a trick to verify the data is actually being...

Simple page submit - vs - Ajax loader

There are many ways to handle forms. one is to simply submit the form and the get variables on php and another one that i'm thinking of, is to send data with ajax and during this process we can show a dialog and show the information about processing the data with a progress bar. despite the fact that ajax is faster than the standard tec...

Bad quality of GIF image in PHP GD

I have a watermark script I am working on, the results are good on PNG and on JPG images however a gif image, not so good. I am using PHP and GD Below you can see the difference in quality of the watermark. Anyone know how to improve this? For the gif version I am using $image = imagecreatefromgif($source_file); imagecopymerge($imag...

Combine 2 php arrays?

How can I combine these 2 array? $array1 = array("gif" => "gif", "jpg" => "jpeg", "jpeg" => "jpeg", "png" =>"png"); $array2 = array("gif" => "0", "jpg" => "90", "jpeg" => "90", "png" => "8"); I tried $array1 = array("gif" => "gif" => "0", "jpg" => "jpeg" => "90", "jpeg" => "jpeg" => "90", "png" =>"png" => "8"); But of course it di...

UTF-8 validation in PHP without using preg_match()

Hi, I need to validate some user input that is encoded in UTF-8. Many have recommended using the following code: preg_match('/\A( [\x09\x0A\x0D\x20-\x7E] | [\xC2-\xDF][\x80-\xBF] | \xE0[\xA0-\xBF][\x80-\xBF] | [\xE1-\xEC\xEE\xEF][\x80-\xBF]{2} | \xED[\x80-\x9F][\x80-\xBF] | \xF0[\x90-\xBF][\x80-\xBF]{2} | [\xF...

GeoLocation API

Hello all, I have just come across this great API: http://ipinfodb.com/ip%5Flocation%5Fapi.php However, I would like to also retrieve the continent. Is this even possible as I can not find it. Maybe there is another API that is freely available that will offer city, country and continent? I have tried Googles AJAX API but they don't o...

Create dynamic subdirectories using htaccess and php

Every single time a user registers on my site I would like them to have their own subdirectory with their registered "username". Every user subdirectory will have the same "index.php" file which will do something. For example: "/users/username1/" and "/users/username2/" If some one wants to access the subdirectory they would simple go ...

Setting a part of a site with other functions (PHP/Apache)

I'm trying to set up a part of a site with apache to use shell_exec, while the others have this function restricted though this is my first time so I really have no clue where I'm looking at. What I need is to call it with a different port (ex. http://localhost:8080, go with other) and practically change the document root, a more "libe...

PHP question Forum Attachment Feature Help

HI I have a forum and I'm trying to think of how to do an "attachment" feature. You know if you make a thread you can chose to upload a file and attach it in the thread. Should I make a table called attachment with id of the file id in table files?? Whats the best way. And I want you to be able to upload more than 1 attachment. and if ...

How to get URL of current page in PHP

In PHP, how can I get the URL of the current page? Preferably just the parts after http://domain.com. ...

What is the correct way to make web form input safe for a variety of contexts?

What do you all think is the correct (read: most flexible, loosely coupled, most robust, etc.) way to make user input from the web safe for use in various parts of a web application? Obviously we can just use the respective sanitization functions for each context (database, display on screen, save on disk, etc.), but is there some gener...

Generating Color Gradients

I had an idea to programmatically generate matching color schemes however I need to be able to generate a linear gradient given a set of two colors (Hex or RGB values). Can anyone provide me the (pseudo-)code or point me in the right direction to accomplish this task? EDIT: I forgot to mention, but I also need to specify (or know) the ...

PHP vs JSP: Which Should I Learn?

I already have some knowledge in Java and I was looking to start writing scripts for web development. I was wondering if I should just learn .jsp since I already have a Java background or is PHP that much better I should take the time and learn it. I'm looking for some pros and cons for each, or just a straight out witch ones better!...

How to fix Server Status Code: 302 Found by SQL Inject Me Firefox Addon

Hi folks. I scanned my login script using SQL Inject Me Firefox addon According to the Test Results, my script was vulnerable to SQL Injection. Result by example Results: Server Status Code: 302 Found Tested value: &#49&#39&#32&#79&#82&#32&#39&#49&#39&#61&#39&#49 Server Status Code: 302 Found Tested value: &#x31;&#x27;&#x20;&#x4F;&#x52...

Zend_Pdf calculating length of text string in current font for line wrapping

Hi Does anyone have an easy way to calculate how many points across a page a piece of text will consume in a particular font and size? (easy = minimal lines of code + computationally cheap). Zend_Pdf doesn't appear to have a function that does this, except for some very expensive calls for each character to getGlyphForCharacter(), getU...

Referencing column names with pg_fetch_row in PHP

How can you reference column names with PHP's pg_fetch_row? Example about the code which we have been debugging with Cha. $dbconn = pg_connect("host=localhost port=5432 dbname=noa user=noa password=123"); $result_titles_tags = pg_prepare( $dbconn, "query777", "SELECT question_id, title FROM questions WHERE question_id IN ...

strange php problem... require_once ignored on windows

strange problem with php on windows... my application loads a 'core' file that loads a settings file, registers autoloads, does initialization etc. at the top of the core file I have include_once("config.php"); this works fine for anything in the current directory, if I include the core file from a separate directory though it just silen...