mschroeder 251 Bestower of Knowledge Team Colleague

Yes, if you're not filtering it for a specific value.

In the foreach loop, you can test $key or $value for anything you want to compile the counts etc.

mschroeder 251 Bestower of Knowledge Team Colleague

Well i'm going to assume you're using at least PHP 5, so look at this idea and lets see if we can't craft something that will speedup your results:

<?php

//Multidimensional array of printers.
//This can be ANY depth.
$printers = array(
	array('Printer_B', 'IDDHARMAHE'),
	array('Printer_B', 'IDSIRIKINE'),
	array('Printer_C', 'IDSUPRIY1'),
	array('Printer_A', 'IDSUSANTEN'),
	array('Printer_A', 'IDSUSANTEN'),
	array('Printer_B', 'IDSEPTIATR'),
);

//PrinterFilter class to filter our iterator and ONLY return values that start with Printer_
class PrinterFilter extends FilterIterator
{
	public function accept()
	{
		//Only accept values that start with Printer_
		if( false !== strpos(parent::current(), 'Printer_') ){
			return true;
		}
		return false;		
	}
}

//Create a new Iterator for the array
//Create a RecursiveArrayIterator around our array
//Create a RecursiveIteratorIterator around that so we can easily navigate it
//Create a PrintFilter interator around that so we can filter only values starting with Printer_
$iterator = new PrinterFilter( new RecursiveIteratorIterator( new RecursiveArrayIterator( $printers ) ) );

//Simply iterate over the iterator add new keys as necessary
//Increment existing keys.
$counts = array();
foreach( $iterator as $key => $value ){
	if( isset( $counts[$value] ) ){
		++$counts[$value];
	} else {
		$counts[$value] = 1;
	}
}

print_r($counts);
Array
(
    [Printer_B] => 3
    [Printer_C] => 1
    [Printer_A] => 2
)
mschroeder 251 Bestower of Knowledge Team Colleague

What have you tried so far?

mschroeder 251 Bestower of Knowledge Team Colleague

Hopefully this illustrates something that might get you on your way.
I also applied some corrections to your code in general.
Tried to comment as much as possible.

//THERE IS A FORM ON ANOTHER PAGE WITH TEXTBOX NAMED "search",
//THAT COMES TO THIS PAGE.

//Global variables should be CAPITALIZED functions should not unless they are capitalized.
$search = $_POST['search'];

//Get words from search string		
$words = explode(' ',$search);

//Drop any empty search terms and trim remaining ones to avoid any extra whitespace
$words = array_map('trim', array_filter($words));

//Format the search terms into a string surrounded by single quotes
//e.g. 'word1 word2 word3'
$search_terms = sprintf("'%s'", implode(' ', $words) );

//Connect to the database
//Should REALLY be using mysqli not mysql functions
$conn = mysql_connect($dbhost, $dbuser, $dbpass) or die ($sql_connect_error);
mysql_select_db($dbname);
						
//Do a Boolean full-text search on the searchkey column
//searchkey MUST have an index to work IN BOOLEAN MODE
//@see http://dev.mysql.com/doc/refman/5.1/en/fulltext-boolean.html
$sql = 'SELECT * FROM items WHERE MATCH(\'searchkey\') AGAINST ('.$search_terms.' IN BOOLEAN MODE)';
mschroeder 251 Bestower of Knowledge Team Colleague

[OFFTOPIC]
-ardav
Pfft we can get much more dynamic than that

<?php
//PHP > 5.3.0
$l = range('a', 'z');
$a = $l[3].$l[24].$l[13].$l[0].$l[12].$l[8].$l[2];
$b = function(){
	return array();
};
$$a = $b($a);

[/OFFTOPIC]

mschroeder 251 Bestower of Knowledge Team Colleague

Define what you mean by "dynamic array" ?

mschroeder 251 Bestower of Knowledge Team Colleague

Create hashes for the common fields that change. I'm thinking the title and content/body of each article. Store these two hashes with each item in your database.

When you process the feed again, generate the same hashes and look for any records where both hashes match. If you find a result disregard the item from the rss feed as it is identical to one in the database already.

When you find a mismatched title or body hash, update whichever of the fields does not match with the changes.

When you find no match on the title or body hash, insert the new item into your database.

mschroeder 251 Bestower of Knowledge Team Colleague

I agree it entirely depends on what the function is doing. However I disagree with the code example. If you're going to write classes you should be using PHP 5 syntax.

  • No reason to have a constructor as the variables default to 'NULL' you could also default them in the class.
  • Variables and functions should have scope, public/protected/private etc.
  • If you're not going to return anything from your function returning $this will allow you to chain your method calls together. See Below
class person
{
  public $firstname = '';
  public $lastname = '';

  public function setFirstname( $firstname )
  {
    $this->firstname = $firstname;
    return $this;
  }

  public function getFirstname()
  {
    return $this->firstname;
  }
}

By returning $this from functions that don't have a return value, usually setters, you can chain the method calls together.

<?php
$person = new person();
echo $person->setFirstname('John')->getFirstname(); //John
echo $person->setFirstname('John')->setFirstname('Joe')->setFirstname('Bill')->getFirstname(); //Bill

This example is not a very good example of method chaining but take something like the following example:

<?php

class Person
{
  public $firstName;
  public $lastName;
  public $birthday;

  public function setFirstname( $name ){ ... }
  public function setLastname( $name ){ ... }
  public function setBirthday( $bday ){ ... }
}

Each setter function would return $this. By using method chaining we can keep calling methods on the return of each function as each function will always return a reference to itself.

e.g.

<?php
$person = new Person();
$person->setFirstname('John')
       ->setLastname('Doe')
       ->setBirthday('01/01/2011');

There is no benefit to this over just calling $person->method(); in multiple statements, …

mschroeder 251 Bestower of Knowledge Team Colleague

There is nothing php related that can just push files to a user's computer without the user's interaction. The same goes for anything built around javascript and php.

The user would need some kind of client on their pc that could interact with your server and handle the transfer.

TySkby I agree, that was the same conclusion I arrived at 12 posts ago. Although cURL is really designed for pulling and pushing, just not to a remote users computer. cURL is a very valuable tool to developers for interacting with a whole variety of protocols including ftp, scp etc. Which would be bi-directional communication.

Now we wait and see if the OP arrives at the same conclusion. You can lead a horse to water but you can't make him drink.

mschroeder 251 Bestower of Knowledge Team Colleague

Absolutely:

<?php
$day[] = $data['od_week'];

$day will be a numerically indexed array.

mschroeder 251 Bestower of Knowledge Team Colleague

There is nothing php related that can just push files to a user's computer without the user's interaction. The same goes for anything built around javascript and php.

The user would need some kind of client on their pc that could interact with your server and handle the transfer.

mschroeder 251 Bestower of Knowledge Team Colleague

Try this:

<?php

$handle = fopen('ftp://user:password@ftp.server.com/path/to/image.jpg', 'rb');

header("Content-type: image/jpeg");
echo stream_get_contents($handle);

fclose($handle);

I just ran this code locally and could pull from a remote ftp server without any issue.
Essentially what would change is you would need to specify headers like you did originally and read the stream from the ftp connection to the browser. This should work for any file, just watch for timeouts.

mschroeder 251 Bestower of Knowledge Team Colleague

Yep, pretty much anything's possible in today's programming world. You just have to concentrate.

First off, since PHP would try to subtract that $date variable, we need to make it a string so make it this:

$date = '1990-12-3';

It also seems you've mispelled a function in your code (mysqli_query should be mysql_query). Maybe that could be the problem?

Also, you don't need to put $j inside the array of the row - it should work just fine, depending on how your $day array is set up.

$date = '1990-12-3';

$viewSchedule = "select * from schedule where id_user = '$idHairstlylist'";
$scheduleResult = mysql_query($dbConn,$viewSchedule) or die(mysqli_error($dbConn));

while ($data = mysql_fetch_array($scheduleResult))
{
    for ($j = 0; $j <= 4; $j++)
    {
        $day[$j] = $data['od_week'];

        // Only one line of processing after the statement... no need for brackets
        if ($day[$j] != $date)
           echo 'hi';
    }
}

sutt0n is correct about your date needing to be in a string.

However, you should NEVER use the mysql* family of functions unless you're using a very old version of MySQL. The mysqli* functions as you used in your code, are designed to work with the "new" functionality that exists in MySQL since version 4.1.

Also, while not wrong it is a pet peeve, you should always code to a standard. Eliminating those braces is just lazy programming IMO. You lose the ability to tell where the control structure begins or ends and if you were to add additional code after echo 'hi'; you will have issues if …

mschroeder 251 Bestower of Knowledge Team Colleague

Do you need to use cURL for this? Why not use the FTP functions in php?
http://php.net/manual/en/book.ftp.php

You could also use the ftp://wrapper http://docs.php.net/manual/en/wrappers.ftp.php
with the filesystem functions

mschroeder 251 Bestower of Knowledge Team Colleague

I understand that there is some theoretical benefit in separating the view part from the logic and variables but I'm not sure if there is a real payback to make it worthwhile. Any thoughts on (real) benefits?

It is not a theoretical benefit to separate the view from logic, it is a real benefit. By separating the view from your logic you create another component that can be replaced on the fly.

For example, you have a site that sells a product. We'll say the url is domain.com/product/####, to view a specific product. When a user browses to that url, the system is looking for a format parameter (format/html, format/json, format/xml) it doesn't find one so the controller defaults to rendering the default html view. This might produce a page of a shopping cart for someone to buy the product directly from you. Now you have a third party who comes to you and says they would also like to sell your cogs in their store.

In a system where the view and logic is intermixed, you would need to replicate the page and/or code and adapt it to be some kind of readable format. If the logic and view is separated, its just a matter of rendering a different view. So the additional retailer says I can read any kind of json data in, so you create a json view that takes an array representation of your product model and json_encode it, and serve it …

mschroeder 251 Bestower of Knowledge Team Colleague

What have you tried so far?

mschroeder 251 Bestower of Knowledge Team Colleague
mysql> quit

You also have to finish statements from the command prompt with semi-colons.

show databases;

If you can access it via the command line and everything is working, from your localhost you should NOT have a firewall/port issue as the request never leaves the local machine.

mschroeder 251 Bestower of Knowledge Team Colleague

Can you access mysql via the command line? If so can you successfully log in as your root user?

mschroeder 251 Bestower of Knowledge Team Colleague

-ardav

Since xml is very well structured it would be relatively trivial to serialize an array or object returned from a database into xml automatically if needed. It also gives a very defined point to introduce caching into your system where the cache would be an xml fragment or entire document.

You're not really storing data in the xml long-term you're more so using it as an intermediate.

When I first played with the concept I was really worried about the performance overhead that the serializing to xml might introduce, but I was really surprised when I started benchmarking it in terms of speed and memory usage.

mschroeder 251 Bestower of Knowledge Team Colleague

But what about the simplicity of:

<?php foreach( $users as $user): ?>
<option value="<?php echo $value; ?>"><?php echo $value; ?></option>
<?php endforeach; ?>

There is shorthand syntax for almost, if not, all control structures in php.
If you were to use short php tags, which I will never, advocate you'd get <?=$value?> instead.

But it really is just semantics, if it works for your needs and it is a simple solution than it is a good solution.

As far as xml/xslt/xpath/xquery goes, it is a really powerful set of tools because they are not just relevant to php. In fact most browsers have very good support natively.

The following is simplified from a w3school example.

<?xml version="1.0" encoding="ISO-8859-1"?>
<!-- Edited by XMLSpy® -->
<catalog>
	<cd>
		<title>Empire Burlesque</title>
		<artist>Bob Dylan</artist>
		<country>USA</country>
		<company>Columbia</company>
		<price>10.90</price>
		<year>1985</year>
	</cd>
</catalog>
<?xml version="1.0" encoding="ISO-8859-1"?>
<!-- Edited by XMLSpy® -->
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
  <html>
  <body>
    <h2>My CD Collection</h2>
    <table border="1">
      <tr bgcolor="#9acd32">
        <th>Title</th>
        <th>Artist</th>
      </tr>
      <tr>
        <td><xsl:value-of select="catalog/cd/title" /></td>
        <td><xsl:value-of select="catalog/cd/artist" /></td>
      </tr>
    </table>
  </body>
  </html>
</xsl:template>
</xsl:stylesheet>

The general idea is that you supply an xml document to an xslt template and the template then pulls its data from the xml.

In PHP the transformation would work something like:

$doc = new DOMDocument();
$xsl = new XSLTProcessor();

$doc->load('/path/to/xsl/template.xsl');
$xsl->importStyleSheet($doc);

//Load XML from string		
$doc->loadXML('xml string...');
$html = $xsl->transformToXML($doc);
		
echo $html;
mschroeder 251 Bestower of Knowledge Team Colleague

Alright, I'll bite the bullet and throw some fuel on the fire.

Having more than a decade of php development under my belt now, I've run the gamut of template engines. I've even spun a few of my own over the years, but alas I've settled back into using purely php in my views.

Template engines are great in theory, they separate your logic from your display. Until you work with a designer who takes one look at your template language and pitches a fit, because they don't get it, and they don't want to get it.

In my opinion it is reinventing the wheel, adding a layer to your view rendering (in mvc terms) that takes a template and then has to parse over your code to replace some form of tags with values and also be able to find and execute logic, that just replaces it with php.

I've yet to find substantial reason to defend using {$variable} vs. <?php echo $variable;?> The earlier requires understanding of the template library and Rain is very simple compared to most. But when looking at some of the popular engines out there the template syntax becomes infinitely more complex than using natural php.

Now, if you want to talk REAL template languages, than I would highly advocate XSLT. I've used this in several cases and have really enjoyed working with it as a template engine/language. Using the PHP XSL extension (http://php.net/manual/en/book.xsl.php) you can simply …

mschroeder 251 Bestower of Knowledge Team Colleague

This is really the wrong place for a thread like this...

But, since I'm already here, domain names are a dime a dozen in my experience. Prices are usually within a couple bucks of one another. Personally most of my domains are registered through 1and1.com these days. Godaddy has a nice interface but to each their own.

As far as hosting goes, you get what you pay for and anyone who tells you differently is full of it. Stay away from unlimited plans as they tend to be a way for hosts to bring in lots of low budget low resource sites and pack them onto a very oversold server. There is a reason HostGator charges $175/m for a dedicated server with hard limited bandwidth and disk space but only charges $5/m for unlimited hosting...

There are good low-budget hosts though. But use your best judgement. No one is going to sell you terabytes of bandwidth and hundreds of gigabytes of space for a few dollars a month.

I recommend checking out www.webhostingtalk.com if you're looking for a very active community built specifically around the very topic of hosting. It is also a great place to find good deals at very reputable hosting companies.

From personal experience one of the best companies I have ever worked with, both shared and dedicated hosting has to be LiquidWeb (www.liquidweb.com) Their support is absolutely top notch and I've sent them some pretty …

Nick Evan commented: Thank you for helping us fight spam! I also really like your avatar :) +16
mschroeder 251 Bestower of Knowledge Team Colleague

Naming your constructor method the same as the class, although not technically incorrect, should be avoided.

With PHP 5 you have the __construct() method for this particular purpose. When a class can not find a defined __construct() method it will, for backwards compatibility reasons, look for a function named identical to the class to use as a constructor.

**As of PHP 5.3.3 the backwards compatibility of naming a constructor the same as the class has been removed.

That aside, if you're going to do this properly, you should be returning a value from the constructor. The catch here is that this return value is ONLY available when the constructor is called directly. e.g. parent::__construct() or $obj->__construct()

In the case of initializing an object you will always get the instance of the object.

<?php 
class X 
{ 
	function __construct()
	{ 
		if( $_POST['break'] == 'yes' ){
			return false;
		} 
		return true;
	} 
} 
 
class Y extends X
{ 
	function __construct()
	{ 
		if( true === parent::__construct() ){
			print("Y_constructor_finished"); 
		}
	} 
} 
 
$_POST['break'] = 'no'; 
$new_Y=new Y();  // will print "Y_constructor_finished";

http://www.php.net/manual/en/language.oop5.decon.php

mschroeder 251 Bestower of Knowledge Team Colleague
$query_birthdate = "SELECT day(user_birthday) as Day FROM users WHERE username='kkjay'";
$birthdate = mysql_query($query_birthdate, $connections) or die(mysql_error());
$row_birthdate = mysql_fetch_assoc($birthdate)

echo $row_birthdate['Day'];

Always use the mysql functions in your queries when you can, as you have done, the database server has that functionality for a reason. No reason to reinvent the wheel.

This only works because you're returning 1 row in the query. If you were returning multiple rows, you would have to loop over the $result to get each row's value.

Finally, if you're working with mysql 4.1 or greater you should NOT be using the mysql extension and really should be using the mysqli or PDO extensions to access the database. These allow access to the newer features provided by the mysql database server.

mschroeder 251 Bestower of Knowledge Team Colleague

In my opinion the best way to do this would be to name your fields using an array index.

<input name="field[]" type="text" size="20" maxlength="40" />
<input name="field[]" type="text" size="20" maxlength="40" />
<input name="field[]" type="text" size="20" maxlength="40" />

Then when you process the fields with PHP it is as simple as:

<?php
foreach( $_POST['field'] as $field ){
  //Do something with the value of $field.
}

No counter needed, will scale to an infinite size, and $_POST will be a numerically indexed array of values that were submitted so you can iterate over it with any of the array functions etc.

epicrevolt commented: Defninitely a new method. I need to look more into arrays for my projects. +1
mschroeder 251 Bestower of Knowledge Team Colleague
mschroeder 251 Bestower of Knowledge Team Colleague

It doesn't look like you posted your entire table structures, hence there is no reasonable way to know where Exam_category.categoryid joins to the three other tables.

I'd also like to know the conditions of your joins.
e.g.
Can a user take the same exam more than once. ( Fail, Fail, Pass etc.)
Can an exam have more than one category and if so how does this connection between exams and categories get made.

These questions will drastically affect the kind of joins that should be used.

Please post your entire sql structure for your tables.

mschroeder 251 Bestower of Knowledge Team Colleague

Performance wise, you should avoid loading an entire file into memory when possible.
The following code relies on the SPL (standard php library) which is mostly > php 5.1
Although this can also be done using the file functions in php.

<?php
$email = 'user@domain.com';

$file = new SplFileObject('filename.txt');
$file->setFlags(SplFileObject::DROP_NEW_LINES);

$match = false;
foreach($file as $line){
	if( false !== stripos( $line, $email ) ){
		$match = true;
		break;
	}
}

if( true === $match ){
	//we found a match
} else {
	//No Match
}

This reads through a file while only having a single line in memory at a time.
If/when it finds a match, it sets $match = true, you could implement this however you would like, but then breaks out of the foreach loop to stop from having to check the rest of the file.

If you're using a version of php that supports the SplFileObject you should really check it out. http://php.net/manual/en/class.splfileobject.php

Shankye commented: Thank you for help +1
mschroeder 251 Bestower of Knowledge Team Colleague

[rant]

use sessions to do login and logout pages.. and contact display page only for logged in members..

How does something like this get upvoted?!

-OP you should use PHP to handle your login and logout. <- I expect this to be upvoted as well.
[/rant]

Now in all seriousness, ardav is the only here who has posted anything of any real value.
I agree with both of his suggestions for structuring this, with the exception of:

For contacts = members only:

id [PK, int]
user_id [int]
contact_id [int]

I would drop the id column as a user (user_id) would never be joined to the same contact (contact_id) more than once. So user_id, contact_id would form a composite primary key making the id superfluous.

mschroeder 251 Bestower of Knowledge Team Colleague

How about you post some code so we can see what you're talking about...

mschroeder 251 Bestower of Knowledge Team Colleague

I have to agree with richieking here. There are numerous open source e-commerce packages that will probably offer more than you will possibly need. Pick one, learn it, install modules/plugins/etc and/or customize it where necessary.

If you are just learning php and starting out with web development, this is not the kind of project to tackle if you intend to release it to a production environment. Not only is the scope enormous but the amount of technical and security hurdles to overcome will not lend itself well to learning.

mschroeder 251 Bestower of Knowledge Team Colleague
<?php
$url = 'http://domain.com';
$curl_arr = array();
$master = curl_multi_init();
 
for($i=0; $i<100; $i++)
{
	$curl_arr[$i] = curl_init();
	curl_setopt($curl_arr[$i], CURLOPT_URL, $url );
	curl_setopt($curl_arr[$i], CURLOPT_RETURNTRANSFER, 1);
	curl_setopt($curl_arr[$i], CURLOPT_SSL_VERIFYHOST, FALSE);
	curl_setopt($curl_arr[$i], CURLOPT_SSL_VERIFYPEER, FALSE);
	//curl_setopt($curl_arr[$i], CURLOPT_CONNECTTIMEOUT, 20);
	//curl_setopt($curl_arr[$i], CURLOPT_NOBODY, true);
	//curl_setopt($curl_arr[$i], CURLOPT_HEADER, true);
 
	curl_multi_add_handle($master, $curl_arr[$i]);
}
 
do {
    curl_multi_exec($master,$running);
} while($running > 0);
 
for($i=0; $i<100; $i++)
{
	$result = curl_multi_getcontent ($curl_arr[$i]);
	var_dump($result);
}

I've run this code with and without those three lines commented out.
Each time I got 100 results without an issue and no problems.

If php is timing out, you could extend the timeout on each loop iteration, but that to me says something is timing out with one of your connections. Add the CURLOPT_CONNECTTIMEOUT and set the value low. Lower the better but more likely the connection will timeout.

Also, if you're displaying the full content from each connection the actual echoing of the data is going to consume a lot of execution time.

mschroeder 251 Bestower of Knowledge Team Colleague

The code below works flawlessly for me.
What version of php and curl are you using? You can find the curl version in phpinfo

<?php
$url = 'http://www.daniweb.com';
$curl_arr = array();
$master = curl_multi_init();
 
for($i=0; $i<10; $i++)
{
	$curl_arr[$i] = curl_init();
	curl_setopt($curl_arr[$i], CURLOPT_URL, $url );
	curl_setopt($curl_arr[$i], CURLOPT_RETURNTRANSFER, 1);
	curl_setopt($curl_arr[$i], CURLOPT_SSL_VERIFYHOST, FALSE);
	curl_setopt($curl_arr[$i], CURLOPT_SSL_VERIFYPEER, FALSE);
 
	curl_multi_add_handle($master, $curl_arr[$i]);
}
 
do {
    curl_multi_exec($master,$running);
} while($running > 0);
 
for($i=0; $i<10; $i++)
{
	$result = curl_multi_getcontent ($curl_arr[$i]);
	var_dump($result);
}
mschroeder 251 Bestower of Knowledge Team Colleague

url isnt an array anymore

mschroeder 251 Bestower of Knowledge Team Colleague

There are other profiling tools but they're all going to require installing some kind of extension in my experience.

mschroeder 251 Bestower of Knowledge Team Colleague
$url = 'http://www.website.com';
$curl_arr = array();
$master = curl_multi_init();

for($i=0; $i<100; $i++){

  //Add curl to array like before but use $url instead of $nodes[$i]
}

....

for($i = 0; $i<100; $i++)
{
	$results = curl_multi_getcontent  ( $curl_arr[$i]  );
	$results = explode("<br>", $results);
	  echo $results[0];
	  echo "<br>";
	  echo $results[1];
	  echo "<br>";
	  echo udate('H:i:s:u');
	  echo "<br><br>";
}

something like that should give you the general idea.

mschroeder 251 Bestower of Knowledge Team Colleague

You can use xdebug to profile the code: http://www.xdebug.org/docs/profiler

mschroeder 251 Bestower of Knowledge Team Colleague

If you had the xdebug php extension installed, which is what I use on my development machine, hence why I use var_dump a lot more than print, you would see that those headers are actually a series of lines separated by newline chars. If you view source on your output you will probably see that the output has newlines in there.

string 'HTTP/1.1 200 OK

Date: Wed, 22 Dec 2010 13:43:24 GMT

Server: Apache/2.2

X-Powered-By: PHP/5.1.6

Set-Cookie: bblastvisit=1293025404; expires=Thu, 22-Dec-2011 13:43:24 GMT; path=/; domain=.daniweb.com

Set-Cookie: bblastactivity=0; expires=Thu, 22-Dec-2011 13:43:24 GMT; path=/; domain=.daniweb.com

Cache-Control: private

Pragma: private

X-UA-Compatible: IE=7

Vary: Accept-Encoding

Content-Type: text/html; charset=utf-8



' (length=430)

So knowing that, you essentially want to get the first line of the request. This can be done with explode, or a substring etc, whatever way you prefer. But you want to parse out the first line "HTTP/1.1 200 OK" for the response code, 200 in this case. Here is a good breakdown of the common ones: http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html

How you choose to get the response code from that string is up to you, consider regular expressions, exploding it via the spaces, using strpos to find the first space and then taking a substr of that through the next three characters etc.

If you need more help post up what you're attempting and we'll go from there.

mschroeder 251 Bestower of Knowledge Team Colleague

The OP is not generating a pdf...the OP is creating an FDF document and specifying a form fillable pdf that loads with the populated data.

-dangerousdayton
When I have generated xFDF the xml version of fdf, the checkboxes have all been setup as unique fields, e.g. Payment_Visa, Payment_Mastercard, Payment_Amex etc. Then to fill a particular checkbox I would pass it the value of Yes.

When I look at the fillable form, the checkboxes, under the options tab, have the Export Value of 'Yes' without the quotes.

Hope this helps.

mschroeder 251 Bestower of Knowledge Team Colleague

Something like this will work for you. It will only return the headers as results.

$nodes = array('http://www.google.com', 'http://www.daniweb.com', 'http://www.yahoo.com');
$curl_arr = array();
$master = curl_multi_init();

for($i = 0, $count=count($nodes); $i < $count; $i++)
{
	$url =$nodes[$i];
	$curl_arr[$i] = curl_init();
	curl_setopt($curl_arr[$i], CURLOPT_RETURNTRANSFER, true);
	curl_setopt($curl_arr[$i], CURLOPT_URL, $nodes[$i] );
	curl_setopt($curl_arr[$i], CURLOPT_CONNECTTIMEOUT, 20);
	curl_setopt($curl_arr[$i], CURLOPT_NOBODY, true);
	curl_setopt($curl_arr[$i], CURLOPT_HEADER, true);
	
	curl_multi_add_handle($master, $curl_arr[$i]);
}

do {
    curl_multi_exec($master,$running);
} while($running > 0);

for($i = 0; $i < $count; $i++)
{
	$results = curl_multi_getcontent  ( $curl_arr[$i]  );
	var_dump($results);
}
$end = microtime(true);
mschroeder 251 Bestower of Knowledge Team Colleague

The problem is, even though you only need the headers, a lot of time the web server will step in and execute the request as a GET and then return just the HEAD of the request. I'm not sure if this is still the problem, but I did work on a script that checked pages and availability across many servers and the best solution I found was batch executing about 10 curl requests in parallel using the multi curl functions. You wait until all requests complete to get a result, but essentially if you send 10 and each on average takes about 1s to return the whole request takes maybe 2s to complete all 10.

mschroeder 251 Bestower of Knowledge Team Colleague

Really two ways to do commonly do this.
First, using a socket

<?php
$fp = fsockopen("www.daniweb.com", 80, $errno, $errstr, 5);
if (!$fp) {
    echo "$errstr ($errno)<br />\n";
} else {
    $out = "HEAD / HTTP/1.1\r\n";
    $out .= "Host: www.daniweb.com\r\n";
    $out .= "Connection: Close\r\n\r\n";
    fwrite($fp, $out);
    while (!feof($fp)) {
        echo fgets($fp);
    }
    fclose($fp);
}

Second using cURL

<?php
$ch = curl_init();
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt ($ch, CURLOPT_URL, 'http://www.daniweb.com');
curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, 20);

// Only calling the head
curl_setopt($ch, CURLOPT_HEADER, true); // header will be at output
curl_setopt($ch, CURLOPT_NOBODY, true);

$content = curl_exec ($ch);
curl_close ($ch);

Both of those only make a HEAD request so they don't actually load the page. This is the same way shorturl resolvers work, like on twitter. The only data returned should be the headers like this:

HTTP/1.1 200 OK
Date: Tue, 21 Dec 2010 18:42:34 GMT
Server: Apache/2.2
X-Powered-By: PHP/5.1.6
Set-Cookie: bblastvisit=1292956954; expires=Wed, 21-Dec-2011 18:42:34 GMT; path=/; domain=.daniweb.com
Set-Cookie: bblastactivity=0; expires=Wed, 21-Dec-2011 18:42:34 GMT; path=/; domain=.daniweb.com
Cache-Control: private
Pragma: private
X-UA-Compatible: IE=7
Vary: Accept-Encoding
Content-Type: text/html; charset=utf-8

If you don't need the response code, simply a check like this:

$fp = fsockopen("www.daniweb.com", 80, $errno, $errstr, 5);
if (!$fp) {
    echo "$errstr ($errno)<br />\n";
} else {
    fclose($fp);
}

I checked both of the first ones and they average about 1s, the last check averages 0.002s to complete. But this will not give you the availability of the response code.

There is also the ability to run multiple curl commands in parallel: …

mschroeder 251 Bestower of Knowledge Team Colleague

There is absolutely no need to create your class files with a .class.php extension, or any special naming convention.

However, many of the larger projects these days have moved to the PEAR standard for naming classes (http://pear.php.net/manual/en/standards.naming.php). This is completely optional of course.

I don't quite understand your question fully as it is very open ended. Are you simply asking how you would use a class within a function of another class, or are your location, links etc classes parts of the User_Registration class? e.g. User_Registration is composed of a "location" (instance of Location) and composed of n "links" (array of Link objects) etc?

mschroeder 251 Bestower of Knowledge Team Colleague

Honestly, the state of php6 is so widely unknown at this point, and with adoption of php 5.3 only starting to become common, your best bet would be to lose the 6.0.0-dev build, and develop on 5.3 if you want bleeding edge and any chance of actually having something deployed. 5.2 if you want the best compatibility across the board. I think we will see php 5.4 long before we see an official php 6 release as it looks like they've even removed php 6 from the snapshots downloads.

My guess is something in jpgrah is looking for the major version of php to be 5 and that is why you're getting that error.

mschroeder 251 Bestower of Knowledge Team Colleague

I'm glad my suggestions made sense.

Your current errors are because your are referencing the $_POST superglobal array using lowercase. PHP is case sensitive $_post and $_POST are two different things.

The problem I see, is this is very very basic php. Without an understanding of the basics, you will not know where to look. I think developing a better understanding of that will greatly help you.

For myself, if I were to get an error like that, knowing the basics, I would realize that $_POST, $_GET etc are special variables within php. If I did not know that one of the first things I would do is google for "post, php" and look through and results from php.net first and foremost.

This page comes up as my second result: http://php.net/manual/en/reserved.variables.post.php upon looking at this page you will see that $_POST is ALWAYS referenced in capital letters. If you knew that post was a superglobal in php you might find the manual page for superglobals in php: http://php.net/manual/en/language.variables.superglobals.php

You would also notice that there is NEVER a space between a variable and its array key, again basic php. If you don't know about php arrays refer again to the manual: http://php.net/manual/en/language.types.array.php

Using the information I have provided, what do you think the necessary corrections should be?

imti321 commented: I HAD BEEN A NEW COMMER TO PHP .CAME ACROSS THIS WEBSITE AND FIRST OF ALL THIS PERSON HELPED PROMPTLY AND ACCURATELY .HE IS REALLY A MASTER.I APPRITITATE HIS PROMPT AND ACCURATE HELP +0
mschroeder 251 Bestower of Knowledge Team Colleague

The php parser almost always points you right to the problem. In this case it has directed you to line 7.

I took a quick glimpse and immediately realized the left parenthesis was typo'd with a left curly brace: $connect = mysql_connect {"localhost","root","webdesigning1") or die ("couldnt connect to mysql data base "); This error exists in the original code you posted. If you don't make an effort to understand the problem or in this case, don't even look at the error message you're going to quickly find no one here wants to make an effort either.

Rule of thumb, when you get parse errors, look for mismatched/missing parenthesis, mismatched/missing quotes and missing semi-colons at the end of your lines. These are the most common I see on these forums.

kvprajapati commented: :) { +11
mschroeder 251 Bestower of Knowledge Team Colleague

I thought it was odd you were trying to open notepad with php...next time you need to describe your problem exactly like your last post.

You have a few ways to achieve what you're trying to do. You can either make the form post directly to your local windows environment with the form values, process the request, and then redirect the user back to your webhosting environment.

-OR-

You can have the form post to your webhosting environment, process the request and as part of the processing have that machine make a POST request to your home server using cURL or Sockets. Your home machine won't know the difference between the requests, except the user will be unaware of the additional request happening.

The other variation on this, would be if the the communication does not need to be in real time. In which case you could handle the transaction on your hosting machine, and have a cron task that runs at an interval, determines your home machine is available, attempts to send n number of pending requests to it and then updates your hosting machine with some form of result.

This allows the process to happen in the background and not slow down the user's experience on your site.

http://php.net/manual/en/book.curl.php
http://php.net/manual/en/book.sockets.php

mschroeder 251 Bestower of Knowledge Team Colleague

My guess is the error is on line 1 somewhere...

mschroeder 251 Bestower of Knowledge Team Colleague

You would need to use runas on windows to run notepad.exe as the specified user:

<?php
exec('runas /user:ComputerName\UserName "notepad"');

However, if the user account requires a password it will prompt and can not be completed via the command line directly. You could create a vb script or something that fills the password automatically if this is a requirement. There are lots of examples of automating the runas logins using vb and such via google.

http://www.microsoft.com/resources/documentation/windows/xp/all/proddocs/en-us/runas.mspx?mfr=true
http://www.tek-tips.com/faqs.cfm?fid=2760

mschroeder 251 Bestower of Knowledge Team Colleague

If your input is always going to be HTML/XML this would be ridiculously easy using SimpleXML and an xpath query:

<?php

$string = <<<XML
<body>  
<img src="page.jpg" border="0" usemap="#fghf"  />
<map name="fghf" id="fghf">
<area shape="rect" coords="10,71,258,236" href="#" alt="some_alt" title="some_title" />
<area shape="rect" coords="258,72,506,237" href="#" alt="some_alt" title="some_title" />
<area shape="rect" coords="155,79,150,200" href="#" alt="some_alt" title="some_title" />
<area shape="rect" coords="88,22,400,217" href="#" alt="some_alt" title="some_title" />
</map> 
</body>
XML;

$xml = new SimpleXMLElement( $string );
$results = $xml->xpath('//area/@coords');

foreach($results as $coords){
	echo $coords.PHP_EOL;
}

You can supply the html/xml as a string any way you wish. Then using an xpath query, we find the coords attribute (@coords) of all area elements in the document.

diafol commented: ridiculously easy! +7