php

PHP: What does pcntl_fork() really do?

PHP's pcntl_fork funcion is supposed to fork a process just as the standard fork function in C. But I was wondering if this function really forks the process or if it emulates that behavior in a different way. If it really forks the process then it's clear which process that is: one of Apache's child processes. That's OK as long as Apach...

How to retrieve the Selected checkbox names ( Multiple Selected) in PHP?

I had multiple checkbox which is generated using loop. After submitting the form I want to get the names of the selected individual checkbox to store it in database as id. Please help me.. Thanks in advance Code i used for generating checkbox in loop: while($arrayRow = mysql_fetch_assoc($rsrcResult)) { $strA = $arrayRow["area_...

CPU load with file_exists in php

Hi, i own a site with a high load cpu httpd request per minute. I've noticed i use "file_exists" on each httpd request. Is that function to much heavy? ...

Routing Problem With Symfony

So I have a module that displays articles. And I tried to make an action that displayed all article of a certain publication when that publication was clicked. I tried following the way to do this on the symfony jobeet tutorials but I ran into some new headaches. Since publications and authors can sometime be url unfriendly, I want to us...

Do I need a trailing semicolon here?

Example: <?php $formElement->display()?> Is this fine, or should I provide a ; ? Well I guess that the PHP interpreter is clever enough to see that the line is finished and the expression done because of the ?> at the end. Right? ...

How to put a dot after three digits of a number.

Hi, do you know how can i put a dot (.) after 3 digits of a number(starting from the end) in php? example: the number 1254631 to be shown as 1.254.631?? ...

Cookies not working on different pages

Ok I have a cookie set, and I can clearly see it if I go to private data in Firefox... ok so when I echo it on one page in a certain directory it works, (www.example.com/dir), but on the index page of the site (www.example.com), it wont echo, it says the cookie is not set. Yes I have cookies enabled, yes I tried clearing cache and all th...

Can't set parent hidden input from iframe!

I have an iframe on my main page, and this iframe uses php code mostly (src is php file). At the bottom of this iframe I have this: window.parent.document.getElementById("qry_str").value='hey'; And in the main (parent) file, I have this hidden input which I am trying to set from the iframe with js: <input type="hidden" i...

"Back to search results" problem

I have a form with many inputs, but not all inputs must be filled in. Form action is set to a php file, which checks which inputs are set and builds a query to query MySQL. Then I display the results on the main page, and the users may click on an ad to show. When clicked an ad, a new page opens with several options for the user (chang...

PHP dump variable as PHP code

I'm looking for a function to dump a multi-dimension array so that the output is valid php code. Suppose I have the following array: $person = array(); $person['first'] = 'Joe'; $person['last'] = 'Smith'; $person['siblings'] = array('Jane' => 'sister', 'Dan' => 'brother', 'Paul' => 'brother'); Now I want to dump the $person variable ...

Should I really be using PDO and prepared statements?

PDO and prepared statements are still kind of confusing to me, no matter how much I read about them so far. So I know they are more "secure" but is it really that important? I mean I can get the same end result using basic mysql with mysql_real_escape_string() and htmlspecialchars() right? ...

PHP setting input values with isset

Hi, I was wondering if there is a shorter way of writing the following code: <input type="text" name="username" value="<?if(isset($_POST['username'])){ echo $_POST['username']; }?>" /> I hate having to do this will all my forms as the isset() check really messes up my HTML and scares away the frontenders. ...

How can I use an exception without the script dying?

I'd like to use an exception for error handling in a part of my code but if the code should fail, I would like the script to continue. I want to log the error though. Can someone please help me figure this out? try{ if($id == 4) { echo'test'; } } catch(Exception $e){ echo $e->getMessage(); } echo'Hello, you shou...

PHP: Create new node inside parent

I have a root XML node called and I am trying to add a new child called to this but I am getting errors. Inside there is also children. Here is my code: $xml = new DomDocument(); $xml->load(X_ASSETS); $xml->formatOutput = true; $new_id = $this->getNewAssetId(); // Root $xpath = new DOMXPath($xml); $asset...

Performing an action when finding same values in two PHP arrays

Hello guys, I have two associative arrays in PHP that are defined as following: $this_week[] = array( "top_song_id" => $row["view_song_id"], "top_place" => $i, "top_move" => "0", "top_last" => $i, "top_peak" => $i, "top_rating" => get_song_rating_by_id($row["view_song_id"]), "top...

Image processing class in PHP

I need to build a PHP photo processing class, I know there are MANY that already exist to the public but I need to build one to do just what I need done and nothing extra and nothing less. I need my class to do this... 1) I create a new instance of my class and I pass in either a URL of a photo, or the path to a local photo being up...

Why can I use SELECT but not INSERT on a SQLite database in PHP?

I am able to retrieve information from a SQLite database in PHP, but not write to it. For example, this code works perfectly fine: $db = new PDO("sqlite:foo.db"); $rowCount = $db->query("SELECT COUNT(*) FROM tblname;")->fetchColumn(0); echo $rowCount; // works as it should However, the following snippet results in an, 'unable to open ...

php - display links to related content

I am looking to implement a 'youtube related videos' style related content system. I have 5 tags/keywords for each of my pages, a title and a description. I would like to display links to the two most similar pages. I am guessing a mysql query based around order by relevance. many thanks. ...

How to fire off an AJAX request and redirect AFTER making the request?

Hello all, I am making use of JQuery to fire off an AJAX request. As soon as that PHP script is initiated I want to redirect my browser to a different page. But the AJAX request must have been fired off successfully, it doesn't matter what that scripts returns. Currently I do the following, but it redirects instantly whilst the script w...

Will a PHP script maintain its session if it is run via exec?

Hello all, I would like to run a PHP script from another PHP script so that the parent comes back with a success when it initiates the child script. The parent will be initiated from the browser where I am using sessions. Will the child script be able to make use of the same session and session variables if run via exec? Thanks all fo...