chrelad 4 Light Poster

Heya jrivera,

Yeah, the site is still up. Which links did you try that didn't work?

The first three links are actually named anchors, so they won't take you to a different page, just down to a section of the current page. If the entire contents of the page are visible, you probably won't notice a change when you click the top three links.

The bottom three links are probably what you are looking to try; those are the links to the tests.

I also have to appologize for not adding more tests. I was hoping that I would waiting to get more feedback to determine whether it was even worth putting time into. I know there are other sites now like http://www.phpbench.com/ that offer essentially the same thing; but I still like to see a simple pie chart that tells me which solution is the fastest for a given goal.

chrelad 4 Light Poster

Right now, I'm just sorting by the average time each test takes (out of twenty runs per test).

Is there a better way you can think of?

Thanks,

Chrelad

chrelad 4 Light Poster

Hi everyone,

I made a very quick and dirty PHP speed testing system (chrelad.awardspace.com/speed) and was looking for feedback on different tests that I could add to it. I've only got two tests going right now:

Comparison of string concat/replace methods

  • Heredoc with interpolation
  • Double quote with interpolation
  • Double quote concat
  • Single quote concat
  • Heredoc with multiple str_replace's
  • Heredoc with bulk str_replace
  • Heredoc with sprintf
  • Heredoc with preg_replace

Comparison of loop methods

  • Foreach
  • Foreach with array_keys
  • For with size identified in for statement
  • For with size identified before for statement

I like that it's got graphs (using Google Charts API) and it gives me a quick way to see which method is the quickest.

I plan on adding some other tests like the following:

  • String replace/concat with larger text
  • Comparison of looping constructs with different sizes/types

Any other ideas are welcome! Also, please let me know if I'm missing anything or could improve the accuracy of these tests. If you would like to know more about the inner workings of the testing system, let me know.

By the way, the numbers may vary from page load to page load, but they seem to give the same results pretty much every time for me. Also, I'm working to get the upper number of the individual tests to show properly in the graphs. Right now, some of them just show zero for the min and max.

chrelad 4 Light Poster

Hi lifeworks,

Look into cURL (Client URL library). It allows you to connect to HTTP resources via a GET/POST request. It has tons of options that you can customize for each request, but it should definitely be able to do what you need it to do.

Hope that helps,

Chrelad

chrelad 4 Light Poster

It may help to see what is being passed in the POST array when you click the next button. I would throw the following code in where you have your comment for creating a new array with the checked ID's:

print_r($_POST['dname']);

That will get you something like this after you submit the form with a couple of employees checked:

Array(
  0 => 21,
  3 => 34,
  7 => 31
);

Now, I'm totally guessing and making these numbers up, but you should have the array of checked values right in your $_POST array. Then you can loop through them and validate each ID or whatever it is you want to do with 'em.

foreach($_POST['dname'] as $employeeId)
{
  // Do your magic stuff here
}

Hope that helps, let me know if I totally misunderstood your question :)

Great one jackakos,

Chrelad

chrelad 4 Light Poster

Now that I think about it, the aforemtioned solution should work with any antivirus that allows you to call it from within PHP on explicit files and gives you the option to delete the file if the file is found to be malicious. Mint, I'll remember that myself :D

Hope that helps, again,

Chrelad

chrelad 4 Light Poster

First off, it depends on quite a few things... But this is how I do it and requires some prerequisites.

1. Should work on Windows/Linux/Mac
2. Install ClamAV
3. Make sure FreshClam is working and running
4. Read up on your version of ClamAV's command line arguments and how to call it from within PHP
5. In your PHP script, first make sure the file was successfully uploaded to the TMP directory (wherever that is on your system).
6. In your PHP script, run ClamAV on the uploaded file and have ClamAV delete it if it's a nasty file. Probably using proc_open, system, etc.
7. Check that the uploaded file still exists
8. If it doesn't, ClamAV found a virus and deleted it and you can output some nasty message to the virus uploader (if you wanted to).

This way, you don't have to worry about getting a response back from your antivirus program in order to tell if it was a virus or not. Whether or not the file was deleted or not will tell you if it was a virus.

Hope that helps!

Chrelad

chrelad 4 Light Poster

Hi veledrom,

This is what I would do:

<?php

while($array = mysql_fetch_assoc($result)) // Iterate through list of students
{
	$id = $array['id'];
	$name = $array['name'];

        if($_POST['student_' . $id]) $class = 'current';
?>
<tr>
	<td><?php echo $id; ?></td>
	<td><?php echo $name; ?></td>						
	<td><input type="submit" name="student_<?php echo $id; ?>" value="Details"></td>
</tr>
<?php
}

?>
chrelad 4 Light Poster

That's kind of a tough question and it certainly depends on a number of variables. Here are a few sites I visit more often:

Semantics

http://www.w3c.org
http://www.webdevout.com
http://digg.com/search?section=all&s=html

CSS

http://digg.com/search?section=all&s=css
http://www.csszengarden.com
http://www.positioniseverything.com
http://www.fiftyfoureleven.com/weblog/web-development/css

Browser Compatibility

http://www.quirksmode.org/

Ajax

http://www.ajaxian.com
http://developer.mozilla.org/en/docs/AJAX:Getting_Started
http://digg.com/search?section=all&s=ajax

Hope some of these help :)

If you need sites that meet a more refined criteria, just let us know what type of sites you want in particular.

Great question and one I wish I had asked back when I was starting out :)

Good luck,

Chrelad

chrelad 4 Light Poster

Hi Papa Awortwe,

Looks like you can do it a couple ways... The way I would recommend (mostly because I use it and I find it easier) is as follows:


The first page:

<?php

session_start();
$_SESSION['my'] = 'blue';

echo '<a href="show_session_var.php">Click here to go to next page</a>';

?>


The second page:

<?php

session_start();
echo 'My favouite color is....' . $_SESSION['my'];

?>

I hope this works for you.

Thanks for the great question Papa,

Chrelad

chrelad 4 Light Poster

Hi martinkorner,

You may have better luck using regular expressions to find the search term instead of using '==' syntax. There are flags which tell preg_match/ereg_match to ignore whitespaces and the like... You could try that and see what you come up with. That's where I'd start anyway :)

chrelad 4 Light Poster

Hi Arun.N,

Sounds like your looking for cURL... Have a look at the cURL documentation and see what you think.

cURL + regular expressions (preg_match_all) = exactly what your looking for.

I've written a few of these "crawlers" myself, so I'll include some foundational code for a very a simple one for you:

<?php

// Return a handle to a curl connection to the site you want to pull info from
$ch = curl_init('http://finance.google.com/finance');

// Set some options for the connection
curl_setopt($ch,CURLOPT_HEADER,0); // Don't return header information, although, this can be handy ;)
curl_setopt($ch,CURLOPT_RETURNTRANSFER,1); // Give us the page source

// Open the connection with the options specified
$cr = curl_exec($ch);

// Run your regular expression against the source to pull what you want, you can use external programs to format the html for easier parsing if you want before you scan it.
preg_match_all('/href="()"/i',$cr,$pm,PREG_SET_ORDER);

// So you can see what you found
print_r($pm);

// Display the results again :D
foreach($pm as $pv) echo $pv[1] . "\r\n";

?>

Hope this helps!

chrelad 4 Light Poster

Hi avmaza,

It appears you've stumbled onto Microsoft's proprietary filters. This is fine for Internet Explorer browsers, but anything else is going to choke on this CSS rule and spit out the results in the normal orientation.

Here is an interesting way to do it... Works at least in IE 6.0, not in Firefox:

http://home.tampabay.rr.com/bmerkey/examples/landscape-test.html

This is another discussion about trying to get as many browsers to work as possible (hint: you may consider using the aforementioned link's information instead of this link's ActiveX approach for IE):

http://edacio.us/forum/comments.php?DiscussionID=39

Hope you can get something out of these links... If not, try:

http://www.google.com/search?hl=en&q=landscape%2Bcss&btnG=Search

chrelad 4 Light Poster

Hi halifaxer,

Great question... Using cURL, I came up with this:

<?php

$ch = curl_init('http://www.cheapsmells.com/viewProduct.php?id=3978');
curl_setopt($ch,CURLOPT_HEADER,0);
curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
$cr = curl_exec($ch);

preg_match_all('/([ a-z]+) (&pound;)([0-9]+\.[0-9]+)/i',$cr,$cp);

print_r($cp);

?>

When the script is run, you get this output:

Array
(
    [0] => Array
        (
            [0] => Original Price &pound;36.00
            [1] => Our Price &pound;22.54
            [2] => Saving &pound;13.46
        )

    [1] => Array
        (
            [0] => Original Price
            [1] => Our Price
            [2] => Saving
        )

    [2] => Array
        (
            [0] => &pound;
            [1] => &pound;
            [2] => &pound;
        )

    [3] => Array
        (
            [0] => 36.00
            [1] => 22.54
            [2] => 13.46
        )

)

Then you could loop through the array like this:

for($i=0; $i<count($cp[1]); $i++) echo $cp[1][$i] . ' is equal to ' . $cp[2][$i] . $cp[3][$i] . "\r\n";

The result would be:

Original Price is equal to &pound;36.00
Our Price is equal to &pound;22.54
Saving is equal to &pound;13.46

I'm not sure if that would be helpful.

chrelad 4 Light Poster

Hi wrstrong,

Looks like someone else is having the same problem you are... This is the thread that was produced for review:

http://www.webmasterworld.com/php/3304270.htm

And here is the final result PHP that was used to manipulate the flat file database:

<?php

$selLine = $_GET['id'];
$delType = $_GET['type'];
$file = "store/" . $delType . ".txt";
$news = file($file);
$cnt = 0;

foreach ($news as $key => $line) {
if ($key!= $selLine) { $result[] = $line; }
$cnt+1;
}
if ($key!= 0) {
$fh = fopen($file, "w");
foreach ($result as $nyhet) {
fwrite($fh, $nyhet);
}
fclose($fh);
}
elseif ($key == 0) {
$fh = fopen($file, "w");
fwrite($fh, "");
fclose($fh);
}

?>

Nice solution as far as I can tell, hope it helps you out. :)

chrelad 4 Light Poster

Hi martinkorner,

Try using strpos along with fread. Aside from that, you could read in a line of the file at a time:

<?php
$handle = @fopen("/tmp/inputfile.txt", "r");
$token = '<!-- STOP HERE -->';
if ($handle) {
    $superbuffer = array();
    while (!feof($handle)) {
        $buffer = fgets($handle);
        if($buffer == $token) {
          echo 'Stopping...';
          // Jump out of this loop
        } else {
          $superbuffer[] = $buffer;
        }
    }
    fclose($handle);
    echo join('<br>',$superbuffer);
}
?>

Of course, I didn't try the code above, but in theory, that would do what you want it too. You can also specify a length for fgets to read so that it only reads the first 39 characters or whatever.

I hope this is somewhat close to what you are looking for.

Great question by the way!

chrelad 4 Light Poster

Hi orr16875,

It appears that I'm still able to get it to work... What version of IE7 are you running (Help -> About Internet Explorer -> Version: XXXXXXX)?

Here's an image of it working on my IE7 install version 7.0.5730.13.

http://img216.imageshack.us/my.php?image=screenshotjg0.png

chrelad 4 Light Poster

Hi orr16875,

Hmmm, well, sorry about misleading you there. Could you provide us with an error or anything that seams amiss?

Thanks orr16875

chrelad 4 Light Poster

Hi rnr8,

Well, in that case (positioning bullets), positioning via CSS is a great way to achieve the desired effect.

I'm in the same boat with you (blah.style.backgroundImage not always working). The className approach hasn't failed me yet and works in every browser I've laid my hands on thus far.

Let us know if you have any other questions rnr8

chrelad 4 Light Poster

Cool beans and glad to hear it!

I'll remember to check for dependant files when dealing with any future JavaScript issues, something easily overlooked.

Thanks for teachin' me somethin' new today Atticus :)

chrelad 4 Light Poster

Hi Dsiembab,

That sounds like a great plan (ie. using regular expressions to check for perl junk).

And/Or if you are running on a Linux system (unless you have Perl installed on a Windows server), you can set a permission mask to not allow executing files where you are storing your uploaded files. chmod -Rv -x /var/uploadedfiles will take care of that for you. Also, investigate setting permission masks so that any file that goes into that directory becomes un-executable.

The extension checking scheme you've posted is about as bulletproof as it get's for extension checking.

You could also (if you wanted an added layer of security) use a program like mencoder or some other program (that can read information about many multimedia file types) to output information about the file (bitrate, samples, fps, etc) that would only appear if it was truly a valid format and returns an error code if it isn't. Run the file through the program (using system, exec, or passthru perhaps) and if it returns an error code, scrap the file and present an error to the user showing them that they aren't as clever as they thought they were.

The aforementioned are just a couple ideas but it sounds like you are definitely on the right track.

By the way, could you post the link to the information regarding perl attacks via file uploads? I'm sure everyone on the site would be grateful :)

chrelad 4 Light Poster

Hi orr16875,

Security has nothing to do with it as far as I can tell... We are just refering to the DOM elements incorrectly.

Check it out, changed parts are bolded:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-Transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en" dir="ltr">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>form test</title>

<script type="text/javascript">
<!--
document.write("If this text is displayed, your browser supports scripting!")

function validate([B]el[/B])
{
  if([B]el.Fname[/B].value=="")
  {
    alert("Please enter first name");
    [B]el.Fname[/B].focus();
    return false;
  }
  if([B]el.Lname[/B].value=="")
  {
    alert("Please enter last name");
    [B]el.Lname[/B].focus();
    return false;
  }
  return true;
}
//-->
</script>
<noscript>JavaScript is NOT enabled!</noscript>

</head>
<body>
<form action="mail.php" name="thisForm" id="thisForm" method="post" enctype="text/plain" onSubmit="return validate([B]this[/B]);">

<p>First Name <input type="text" name="Fname" id="Fname" size="30" maxlength="25" /></p>
<p>Last Name <input type="text" name="Lname" id="Lname" size="30" maxlength="25" /></p>
<p>Password &nbsp;&nbsp;<input type="password" name="psswd" size="30" maxlength="8" /></p>

<h4>your favorite food</h4>
<p><input type="checkbox" name="food" value="pizza" checked="checked" />Pizza<br />
<input type="checkbox" name="food" value="chicken" />chicken<br />
<input type="checkbox" name="food" value="eggs" />eggs<br /></p>

<h4>Your gender</h4>
<p><input type="radio" name="gender" value="female" checked="checked" />female<br />
<input type="radio" name="gender" value="male" />male<br /></p>

<p><input type="submit" value="send" /><input type="reset" value="clear" /></p>
</form>

<p><a href="http://validator.w3.org/check?uri=referer"><img src="http://www.w3.org/Icons/valid-xhtml10" alt="Valid XHTML 1.0 Strict" height="31" width="88" /></a></p>

</body></html>

Works in IE and Firefox!

chrelad 4 Light Poster

Hi nicolechuah,

Try this out:

<html>
<head>
<script type="text/javascript">
function insRow()
{
var x=document.getElementById('myTable').insertRow(1);
var y=x.insertCell(0);
var a=x.insertCell(1);
var b=x.insertCell(2);
var d= '<input type="button" value="Delete" onclick="deleteRow(this)">';
var e= '<input type="text" id="answer" />';
var f= '<input type="text" name=num; id="answer1" />';
y.innerHTML=e;
a.innerHTML=f;
b.innerHTML=d;
}

function deleteRow(r)
{
var i=r.parentNode.parentNode.rowIndex;
document.getElementById('myTable').deleteRow(i);
}

function check([B]el[/B])
{
document.getElementById("answer").value=[B]el.getAttribute('value1')[/B];
document.getElementById("answer1").value=[B]el.getAttribute('value2')[/B];
}

function this_total( for_what )
{
var total = 0;
var i;

for (i = 1;i<10;i++){
var this_col = for_what.parentElement.parentElement.colIndex;
var num = this_col.getElementsById("answer1")[i].value;

total += num;
}

for_what.getElementById("ans").value = total;
return;
}
</script>

</head>
<body>
<p>What's your favorite browser?</p>

<form>
<input type="radio" name="browser" onClick="insRow();check([B]this[/B])" value1="Burger" value2="5.00">Burger<br />
<input type="radio" name="browser" onClick="insRow();check([B]this[/B])" [B]value1[/B]="Fried Rice" value2="4.00">Fried Rice<br />
<input type="radio" name="browser" onClick="insRow();check([B]this[/B])" [B]value1[/B]="Nescafe" value2="2.50">Nescafe<br />
<input type="radio" name="browser" onClick="insRow();check([B]this[/B])" [B]value1[/B]="Orange Juice" value2="3.60">Orange Juice<br />
<br />

</form>

<table id="myTable" border="1">
<tr>
<td>Title</td>
<td>Price</td>
<td>Cancel</td>
</tr>
<tr>
<td>Total: </td>
<td><input type="text" name="total" id="ans"></td>
<td><input type="button" onClick="this_total( this )" value="calculate"></td>
</tr>
</table>
<br />

</body>
</html>

Hope this helps :) Tested in IE and Firefox

chrelad 4 Light Poster

Hi Atticus,

Couple things you can check:

  1. Open the site/page in IE/Firefox and check for JavaScript errors
  2. If #1 produces no errors, add a simple alert('Hello') to a section of the lightbox script that runs first
  3. If it doesn't run, and the alert resides in a function, make sure the function is being called
  4. Make sure the file is properly included using a <script></script> tag, place the tag at the very bottom of your page right before the closing <body> tag, append an alert('Hello'); to the end of the included file and it should pop up when the page loads.
  5. If the aforementioned alert doesn't show up, make sure the <script> tag has the type="text/javascript" attribute, that the file has read permissions, that the file page in the src="..." attribute is correct, and the tag has a closing tag and see if it works.
chrelad 4 Light Poster

Hi rnr8,

Instead of using the DOM to change the backgroundImage property, try changing the className property of the element and creating a stylesheet rule for the class name.

JavaScript:

el.className = 'hover';

Stylesheet:

li.hover{
  background-color:#f90;
  font-weight:bold;
  text-decoration:underline;
}

Remember though, it's better to change the styles of anchors instead of li's when dealing with mouseover's due to incomplete support for mouseover event handling and the like in different browsers. Anchor's (<a>) already have :hover, :active, :visited, etc stylesheet capabilities in the revision 1 of the w3c's specification (http://www.w3.org/TR/CSS1#anchor-pseudo-classes). Try changing the background image on the anchors instead of the li's if you want to keep your menu/list viewable by the widest possible audience. Just a tip :)

Great question rnr8

NettSite commented: Thanks! Saved me a lot of time. +4
chrelad 4 Light Poster

Hi mithesh,

Could you expound on your question?

  • Will you be pulling information from your portal into your outlook calendar?
  • Will you be synchronizing information between the outlook calendar and your web portal?
  • Are you using a collaboration server of any kind with outlook?
  • Will this solution be implemented on your computer alone or distributed to multiple clients?
  • Anything else that would help us understand your situation (topography, protocols, etc)

I'm almost positive there is a solution, however, finding the correct one depends on your situation.

If you want to get started quickly, you may want to head over to the Visual Basic side of daniweb and ask how to use CURL to retrieve information and then add it to outlook's alerts.

Thanks mithesh

chrelad 4 Light Poster

Hi ManOnScooter,

In order to make certain that your results are displayed in order, include a date field or ID field in the order clause after the name:

$sql = "select id, name from student_adv WHERE name LIKE '%$search%' or name like '%$w1%' or name like '%$w2%' order by name, [B]id[/B] asc limit $startIndex, $perPage";
chrelad 4 Light Poster

Hi rogelioz,

I've tried the code you posted and found that $dates[1][0] is not set. That is why you are getting a wierd date. I manually set the $date2 variable to 'Nov 7, 2007' and got the correct results.

<?php

$date = 'Nov 7, 2007';
echo date('Y-m-d', strtotime($date));

//$date2 = $dates[1][0];
echo $date2 = 'Nov 7, 2007';
echo date('Y-m-d', strtotime($date2));

?>

Check the code that sets the $dates[1][0] variable or post it for us to check out.

chrelad 4 Light Poster

Hi justted,

Could you elaborate on what exactly the problem is? All I'm getting as far as a question is:

"How do I add the image map HTML to the global.inc.php file?"

Am I right, and if so:

global.inc.php

<?php

$map = <<<END
<img name="headerbanner0" src="headerbanner.gif" width="950" height="125" border="0" usemap="#headerbanner" alt="" />

<map name="headerbanner">
<area shape="rect" coords="224,93,385,125" alt="newsroom">
<area shape="rect" coords="585,90,793,2081874365" href="http://cyberpetcity.com/view_page.php?page=1363&game=1" alt="cybertown">
<area shape="rect" coords="411,90,564,125" href="http://cyberpetcity.com/free_food.php?game=1" alt="soup">
<area shape="rect" coords="806,94,943,125" href="http://cyberpetcity.com/view_page.php?page=1362&game=1" alt="contact">
</map>
END;

if ($getGame[use_logo] == "1"){
  $gameName = "<img src=$base_url/images/user_images/opg_$game/logo.gif>";
}

?>
chrelad 4 Light Poster

Hi akbar ali butt,

Without knowing further details, it's hard to say if it's possible or not. It is certainly possible to open, create and modify PDF's using PHP's built in PDF functions. You may benefit from reading through the PDF functions that PHP offers and deciding for yourself if that will be enough to suit your needs:

http://www.php.net/manual/en/ref.pdf.php

Let us know if you have further questions.

chrelad 4 Light Poster

Hi nav33n,

May I suggest using modified preorder tree traversal for the tree handling logic. It has worked wonders for me in every instance of tree traversal I have encountered. Take a look and see if you can put it to use for your situation:

http://www.sitepoint.com/article/hierarchical-data-database/

Have fun :)

chrelad 4 Light Poster

Hi joshua.tilson,

It appears that this can be streamlined even more, however, you will have to put some safegaurds in to make sure there is no fowl play (which should be done anyway). This is what it could be:

<?php

require((preg_match('/(contacts|about|home)/i',$_GET['p'])) ? $_GET['p'] : 'fowlplay.php');

?>
chrelad 4 Light Poster

Hi Dsiembab,

Should I save these files without the extension and add the extension only when called?

It shouldn't really make a difference if you keep them out of the web root and set appropriate permissions on them.

Should I put these uploaded files in my cgi-bin?

No, put them outside the web root altogether and grant them the most restrictive permissions possible while still making them readable by PHP or whatever will be streaming/delivering them.

If so lets say I have videos or some sort of other file type will I be able to stream from my cgi-bin?

If PHP/streamer/etc has permissions to read the files, yes.

How does someone make a file with a friendly extension and use it with a different scripting
language?

Can you elaborate on "friendly extension?" Is this friendly extension for the uploaded files?

Also, make sure you are not *just* checking the file extension and that you *are* using mime type checking as an extra measure of security.