cwarn23 387 Occupation: Genius Team Colleague Featured Poster

Well try checking your cookies for a cookie from one of your sites and I think the cookie by default is called PHPSESSID. If find that cookie while browsing your website that is using sessions then that is living proof that sessions usually use a single cookie for identity.

cwarn23 387 Occupation: Genius Team Colleague Featured Poster

I have being trying to make a javascript code that will show different submenus depending on what was selected on the previous menu. Although my script has no bugs according to Internet Explorer it seems to not work in IE nor Crome. Can anybody see what's wrong with this code because it looks perfect but just doesn't work as in won't display the submenus on selection.

<head><script language=javascript type='text/javascript'>
function showprojecttype(var1) { 
if (document.getElementById) { // DOM3 = IE5, NS6 
    document.getElementById('divmodify').style.visibility = 'hidden';
    document.getElementById('divcreate').style.visibility = 'hidden'; 
    } else { 
    if (document.layers) { // Netscape 4 
        document.divmodify.visibility = 'hidden';
        document.divcreate.visibility = 'hidden';
        } else { // IE 4 
        document.all.divmodify.style.visibility = 'hidden';
        document.all.divcreate.style.visibility = 'hidden';
        } 
    }

if (var1=='divcreate') {
    if (document.getElementById) { // DOM3 = IE5, NS6 
        document.getElementById('divcreate').style.visibility = 'visible'; 
        } else { 
        if (document.layers) { // Netscape 4 
            document.divcreate.visibility = 'visible'; 
            } else { // IE 4 
            document.all.divcreate.style.visibility = 'visible'; 
            } 
        } 
    } else {
    if (document.getElementById) { // DOM3 = IE5, NS6 
        document.getElementById('divmodify').style.visibility = 'visible'; 
        } else { 
        if (document.layers) { // Netscape 4 
            document.divmodify.visibility = 'visible'; 
            } else { // IE 4 
            document.all.divmodify.style.visibility = 'visible'; 
            } 
        } 
    }
}
</script></head><body onload=javascript:showprojecttype('divcreate');>
<form method='post' style='margin:0px; padding:0px;' name='form1'>

Modify or Create:<select name='modify||create' size=1 onchange='javascript:showprojecttype(this.options[this.selectedIndex].value);'>
<option value='divcreate'>
<option value='divcreate'>Create
<option value='divmodify'>Modify
</select><br>
<select id='divmodify' name='divmodify' size=1 style='display:none;'>
<option value='1'>option a
<option value='1'>option b
<option value='1'>option c
<option value='1'>option d
</select>
<div id='divcreate' name='divcreate' style='display:none;'>
If this text shows it probably works.
</div>
</form></body>
cwarn23 387 Occupation: Genius Team Colleague Featured Poster

We decided not to use that solution because of the rare case when someone has cookies disabled.

Just a note on that. Sessions do use cookies. For a session to know which computer the session applies to, the session must either send a cookie to the client as proof of identity or have that identity code in the url. So in most cases it doesn't matter if the user doesn't have cookies enabled since without cookies there ain't sessions unless identity is sent via url.

cwarn23 387 Occupation: Genius Team Colleague Featured Poster

Try the following:

<?php

   function showproducts($catid, $page, $currentpage, $newpage)
   {
      $query = "Select count(prodid) from products where catid = $catid";
      $result = mysql_query($query);
      $row = mysql_fetch_array($result);
      if ($row[0] == 0)
	  
      {
         echo "<h2><br>Sorry, there are no products in this category</h2>\n";
      }
      else
      {
         $thispage = $page;
         $totrecords = $row[0];
         $recordsperpage = 3;
         $offset = ($thispage - 1) * $recordsperpage;
         $totpages = ceil($totrecords / $recordsperpage);
         echo "<table width=\"100%\" cellpadding=\"1\" border=\"0\">\n";
         $query = "SELECT * from products WHERE catid=$catid LIMIT $offset,$recordsperpage";
         $result = mysql_query($query); 
         $var=1;
         while ($var=mysql_fetch_array($result, MYSQL_ASSOC))
         {
         unset($var);
         echo '<tr>';
         for ($x=0; $x<4, $row=mysql_fetch_array($result, MYSQL_ASSOC) ; $x++) {
            $prodid = $row['prodid'];
            $description = $row['description'];
            $price = $row['price'];
            $quantity = $row['quantity'];
            $onsale = $row['onsale'];

            echo "<td>\n";
               echo "<img src=\"showimage.php?id=$prodid\" width=\"150\" height=\"150\">\n";

			     echo "<a href=\"$newpage&id=$prodid\">$description\n";
               echo "$" . $price . "\n";

            if ($onsale)
               echo "On sale!\n";
            else
               echo "&nbsp;\n";
            echo "</td>\n";
            }
         echo '</tr>';
         $var=$row;
         }
         echo "</table>\n";   // Code to implement paging
         if ($thispage > 1)
         {
            $page = $thispage - 1;
            $prevpage = "<a href=\"$currentpage&cat=$catid&page=$page\">Previous page</a>";
         } else
         {
            $prevpage = " ";
         }         if ($thispage < $totpages)
         {
            $page = $thispage + 1;
            $nextpage = " <a href=\"$currentpage&cat=$catid&page=$page\">Next page</a>";
         } else
         {
            $nextpage = " ";
         }         if ($totpages > 1)
            echo $prevpage . "  " . $nextpage;      }
   }

?>

I just tested that script for the unknown error you mentioned and found that the for loop opening line needed to be replacing with the following:

for ($x=0; $x<3, $row=mysql_fetch_array($result, MYSQL_ASSOC) ; $x++) {

Then that just leaves the …

cwarn23 387 Occupation: Genius Team Colleague Featured Poster

Well I guess you could try updating the module via command line but I don't think it's possible to just edit the dll because what is actually happening is that php has been compiled with the dll as lets say version 2.0. Then what usually happens is that the module or php compilation get updated to another version such as 2.1 for example while the other is the previous version. So in your case as an example, php may be trying to read version 2.1 while your dll is version 2.0. The best way to fix that is to make them match the same version and the best way to make them match is by recompiling the library.

cwarn23 387 Occupation: Genius Team Colleague Featured Poster

Whats the maximum session time limit?

Well time()+600 == 10 minutes. And if that code is placed in each page, it will reset the cookie that holds the session to ten minutes from the current time.

cwarn23 387 Occupation: Genius Team Colleague Featured Poster

I thank yo Cwarn23, I tried the code and unfortunately it did not work. It came out exactly like the result I had. The only difference is that it minus by one, the amount of item shown on the page.

I am trying the code below, but I am getting undefine variable for $table and my content for row on the $table .= "<td>{$row}</td>"; line I think is wrong. Because it mark as undefine
This is the code that I am now trying from Keith. Knowing me I am screwing up something. The other guy from the other thread successfully made his page work just like how I want mines to work. But I don't know what I am doing wrong. I even found out by messing aournd with Cwarn and Keith code that my table I had thought was going from left to right I made it wrong. So now I have another problem because it is going downward: vertically. But I think it might correct itself if the page is set up for the images to display as:
image image image
image image image
image image
next page

Well by reading that I don't 100% understand how you want the images to be displayed. From that it looks like you want to have an empty cell at the end of the table due to the number of images. And do you want pegination? Looks like it judging by the next page text at …

cwarn23 387 Occupation: Genius Team Colleague Featured Poster

If ya want to expire the session 10 minutes after the last page visit then simply place the following code at the top of every page.

<?
session_start();
setcookie(session_name(), $_COOKIE[session_name()], time()+600, '/');

That will make the session last for 10 minutes after visiting the page and unless the user visits another page, the session will expire.

cwarn23 387 Occupation: Genius Team Colleague Featured Poster

Well, all this things will do php script...Let me explain what exactly i'm going to do and how it will work:
-assume that you're a teacher in our school
-when you sign-up and create school class with student names&surnames, etc., php code will automatically create an Excel file(on server) that contains all information you entered in sign-up phase. So, client doesn't worry about place where the file is saved-php code will do this.
My problem is that i cant make the excel file editable online=>you have to download it and then upload after you worked on it...

Well the check the library I mentioned earlier as it has a save function that you can save the file directly to the server without the client doing anything. It's at http://phpexcel.codeplex.com/Release/ProjectReleases.aspx?ReleaseId=10715
All you need to do is call the save function/method like $worksheet->save('path_to/file.xls'); or something like that. That's just off the top of my head from when I used the library in the same fashion.

cwarn23 387 Occupation: Genius Team Colleague Featured Poster

now you can see the elements of array.

<?
$myarray="";
$myarray=explode(',',$checkstring);
print_r($myarray);
?>

Still buggy.
Try replacing your second line with $myarray='1,0,1,0,0,1,1,0'; Also you have an invalid input into the explode function as the variable $checkstring hasn't been set.
So your example should be the following:

<?
$myarray='1,0,1,0,0,1,1,0';
$myarray=explode(',',$myarray);
echo '<xmp>';
print_r($myarray);
echo '</xmp>';
?>

That should fix all your bugs.

cwarn23 387 Occupation: Genius Team Colleague Featured Poster

it is printing as array

That is because the example BzzBee posted isn't very good. Try mine and just as a reminder is as follows:

$tmp =$_REQUEST["check1"];
$tmp .=',' . $_REQUEST["check2"];
$tmp .=',' . $_REQUEST["check3"];
$tmp = str_replace(',,',',',$tmp);
 
//now to turn into an array
$darray = explode(',',$tmp);
 
//now to display the array
echo '<xmp>';
print_r($darray);
echo '</xmp>';
cwarn23 387 Occupation: Genius Team Colleague Featured Poster

Hi, any more suggestions for sample scripts to make?
I've just added a site security tester script.

cwarn23 387 Occupation: Genius Team Colleague Featured Poster

The way I would do for performance and speed is as follows:

$tmp =$_REQUEST["check1"];
$tmp .=',' . $_REQUEST["check2"];
$tmp .=',' . $_REQUEST["check3"];
$tmp = str_replace(',,',',',$tmp);

//now to turn into an array
$darray = explode(',',$tmp);

//now to display the array
echo '<xmp>';
print_r($darray);
echo '</xmp>';
cwarn23 387 Occupation: Genius Team Colleague Featured Poster

Why not just set the session cookie to expire 10 minutes after login. Below is a example of what you would need to place into your login processor:

setcookie(session_name(), $_COOKIE[session_name()], time()+600, '/');

Also note that code needs to go after session_start();

cwarn23 387 Occupation: Genius Team Colleague Featured Poster

Well I have the same annoying error under my php-gtk compilation and as far as I am aware the only way around it is to uninstall the library and recompile the library via command line. But for me since I have about 7 modules with that error it would be just too difficult to recompile them via command line so I simply just ignore those errors unless you are trying to compile a new library.

cwarn23 387 Occupation: Genius Team Colleague Featured Poster

Try the following:

<?php

   function showproducts($catid, $page, $currentpage, $newpage)
   {
      $query = "Select count(prodid) from products where catid = $catid";
      $result = mysql_query($query);
      $row = mysql_fetch_array($result);
      if ($row[0] == 0)
	  
      {
         echo "<h2><br>Sorry, there are no products in this category</h2>\n";
      }
      else
      {
         $thispage = $page;
         $totrecords = $row[0];
         $recordsperpage = 3;
         $offset = ($thispage - 1) * $recordsperpage;
         $totpages = ceil($totrecords / $recordsperpage);
         echo "<table width=\"100%\" cellpadding=\"1\" border=\"0\">\n";
         $query = "SELECT * from products WHERE catid=$catid LIMIT $offset,$recordsperpage";
         $result = mysql_query($query); 
         $var=1;
         while ($var=mysql_fetch_array($result, MYSQL_ASSOC))
         {
         unset($var);
         echo '<tr>';
         for ($x=0; $x<4, $row=mysql_fetch_array($result, MYSQL_ASSOC) ; $x++) {
            $prodid = $row['prodid'];
            $description = $row['description'];
            $price = $row['price'];
            $quantity = $row['quantity'];
            $onsale = $row['onsale'];

            echo "<td>\n";
               echo "<img src=\"showimage.php?id=$prodid\" width=\"150\" height=\"150\">\n";

			     echo "<a href=\"$newpage&id=$prodid\">$description\n";
               echo "$" . $price . "\n";

            if ($onsale)
               echo "On sale!\n";
            else
               echo "&nbsp;\n";
            echo "</td>\n";
            }
         echo '</tr>';
         $var=$row;
         }
         echo "</table>\n";   // Code to implement paging
         if ($thispage > 1)
         {
            $page = $thispage - 1;
            $prevpage = "<a href=\"$currentpage&cat=$catid&page=$page\">Previous page</a>";
         } else
         {
            $prevpage = " ";
         }         if ($thispage < $totpages)
         {
            $page = $thispage + 1;
            $nextpage = " <a href=\"$currentpage&cat=$catid&page=$page\">Next page</a>";
         } else
         {
            $nextpage = " ";
         }         if ($totpages > 1)
            echo $prevpage . "  " . $nextpage;      }
   }

?>
cwarn23 387 Occupation: Genius Team Colleague Featured Poster

Or you use xampp or install the services individually.
In any case, as a biginner I would recommend using a program called notepad++ and the wikipedia article about it is at: http://en.wikipedia.org/wiki/Notepad%2B%2B
The advantage with a boosted version of notepad is that it contains a syntax highlighter making code more readable and easier to spot errors. And to save a file as a php file, simply select the option All files (*.*) and add at the end of the filename .php To view the files, place them in your active server directory which is usually called something like htdocs or public_html. Then after that to view it in the browser you need to type in the website address or if the website/webpages are not on the internet but on the computer you are using then you use the website http://localhost/file.php with file.php being a file inside the htdocs or public_html folder.

cwarn23 387 Occupation: Genius Team Colleague Featured Poster

Well actually, there is a phrase error or bug in that code and should be the following:

<?php
error_reporting(E_ALL ^ E_NOTICE); //this has been fixed

$to  = 'whom@yahoo.com'; 
$subject = 'The Playboys!';
$message = '
<html>
<head>
  <title>TESTING!</title>
</head>
<body>
  <p>Playboy in the Philippines</p>
  <table>
    <tr>
      <th>Name</th><th>Sex</th><th>Age</th><th>Vitamin</th>
    </tr>
    <tr>
      <td>Tukmol</td><td>Twice a Day</td><td>75</td><td>Viagra</td>
    </tr>
    <tr>
      <td>Tamulmol</td><td>M ...W.....F</td><td>80</td><td>Tongkat Ali</td>
    </tr>
  </table>
</body>
</html>
';

// Content-type header 
$headers  = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";

// Additional headers

$headers .= 'From: Birthday Reminder <business@your_website.com>' . "\r\n"; //this has been fixed
$headers .= 'Bcc: you@hotmail.com' . "\r\n";


if (mail($to, $subject, $message, $headers)) //this has been fixed
{
   echo "mail sent...";
} else {
   echo "unable to send mail";
}

?>
cwarn23 387 Occupation: Genius Team Colleague Featured Poster
tempcontainer+=(descriptionprefix[0]==1)? descriptionprefix[1]+(i+1) : ""

I'm kinda guessing here but I think if your replace the above line with the below it might solve the problem:

tempcontainer+=galleryarray[i][0];
cwarn23 387 Occupation: Genius Team Colleague Featured Poster

but have not been able to learn it to program from scratch.

Well I was like that when I started but found a really useful recourse at http://www.php.net where I found all the recourses I needed to memorise the basics of php. Also if you are into books, try a book called 'php & mysql for dummies'. That book offers the basic concepts of php which you should be able to memorise. Then when you are finnished memorising that, try 'php5 and mysql bible'. Note with the book links I've posted you can view the table of contents of each book in internet explorer.

So the basic way to learn is to make a html webpage. Then start with forms and text files. And then mix the knowledge that you learn't with processing advanced forms with the knowledge of how to process a page while memorising all of that knowledge. But other than that the books mentioned will help you get started particularly the php & mysql for dummies.

cwarn23 387 Occupation: Genius Team Colleague Featured Poster

I just checked the script and very buggy in my opinion. I've debuged it and is as follows:

$query3 = "SELECT size, in_stock, colour, itemline_id FROM itemline WHERE item_id = '" . mysql_real_escape_string($row['item_id']) . "'";
  $result3 = mysql_query($query3) or die(mysql_error());
  
    echo "test" . mysql_num_rows($result3);
	echo "<form method='post' action='ppp.php'><select name='id'>";
	while ($row3 = mysql_fetch_array($result3)) {
        $size = $row3['size'];
		$colour = $row3['colour'];
		$in_stock = $row3['in_stock'];
    	$id = $row3['itemline_id'];

		if ($in_stock != 0){
    		echo "<option value='" . $id . "'>Size: " . $size . " -- Colour: " . $colour . " -- In Stock: " . $in_stock . "</option>";
   		}
		else{
       		echo "<option disabled='disabled'>Size: " . $size . " -- Colour: " . $colour . " -- OUT OF STOCK</option>";
   		}
   		
   }
   if ($in_stock != 0){
       		echo "<option value='" . $id . "'>Size: " . $size . " -- Colour: " . $colour . " -- In Stock: " . $in_stock . "</option>";
      		}
   		else{
          		echo "<option disabled='disabled'>Size: " . $size . " -- Colour: " . $colour . " -- OUT OF STOCK</option>";
   		}

   echo "</select><input name='action' type='hidden' value='addtocart' /><input type='hidden' name='id' value ='".$row['item_id']."' /><p><input type='submit' value='Add to basket' ></p></form>";
cwarn23 387 Occupation: Genius Team Colleague Featured Poster

I have just managed to make basic communication between javascript and php using cookies and an iframe and my script is as follows:
index.html

<head><title>Tester</title>
<script>
function CookieVal(c_name) {
    if (document.cookie.length>0)
      {
      c_start=document.cookie.indexOf(c_name + "=");
      if (c_start!=-1)
        { 
        c_start=c_start + c_name.length+1; 
        c_end=document.cookie.indexOf(";",c_start);
        if (c_end==-1) c_end=document.cookie.length;
        window.variable.field.value = unescape(document.cookie.substring(c_start,c_end));
        } 
      }
    window.setTimeout("CookieVal", 900);
    }
function getCookie()
{
document.write("<form name='variable' style='margin:0; padding:0;'><input type='text' name='field' style='border: 0; width: 512px;'></form>");
CookieVal('text');
}</script>
</head><body>
<form method='post' action='processor.php' target='frame'>
Enter a cookie value: <input type='text' name='text'>
<input type='submit' value='submit'>
</form>
<iframe src ='processor.php' width=1 height=1 marginheight=0 marginwidth=0 scrolling='no' frameborder=0 name='frame'>
</iframe> The cookie value was:<br>
<script>getCookie();</script>
</body>

And processor.php

<?
if (isset($_POST)) {
//set the cookie to be display on main page
setcookie ('text',$_POST['text'], time()+3600);

/* do whatever with $_POST values */
}
?>

Also notice that when changing the value of the cookie, the page does not refresh to display the new cookie value and that the php code is executed when the form is submitted. Now thats a propper way of getting php to communicate with javascript.

cwarn23 387 Occupation: Genius Team Colleague Featured Poster

Since how I have the rest of the night to wast, I will try and invent a proper way of javascript communicating with php using 1 iframe + cookies.

cwarn23 387 Occupation: Genius Team Colleague Featured Poster

...
I believe that someone, millions of years ago, we are just tiny speck of particles that evolved into something new life form, and that it kept on evolving until it evolve to what we are now. Hope that it will stop here though.

Well the only thing I hope for with evolution is that we don't evolve into some sort of moster that ya see on those science fiction shows. I just hope we evolve into an advanced species like the Achients from Stargate.

cwarn23 387 Occupation: Genius Team Colleague Featured Poster

Cwarn23, If you read all the posts, you will see I have no where insulted him. I am just giving a dose of his own medicine, in a sarcastic way.
As I already said in my previous post, he had no respect whatsoever for the other posters. I don't expect that from a new member (and I am sure most of the people here agree with me).
I also think there is a limit for everything. He (rm_daniweb) has surely crossed it.

The only thing is that when you put that into an equation it doesn't exactly add up. An example equation is rm_daniweb's number of post devided by your number of post which would be the percentage of return abbuse if you want to put it that way:

23/3497=0.00645
Above is the ration then convert to percent
0.0064577*100=0.64%

So using that equation 0.64% is the percentage of abuse you can send back to him although I would not recommend it. Just one way looking at it.

how about if the JAVASCRIPT function is refreshing a new PHP page or loading a NEW PHP page and that page IS FULL OF PHP COMMANDS. What will happen....like location.etc...header() in php....

Just let us explore the possibilitiies...

Well there is one option for 2 way processing is the following script:

index.html:

<head><title>Tester</title></head><body>
<form method='post' action='processor.php' target='frame'>
<input type='text' name='value'>
<input type='submit' value='submit'>
</form>
<iframe src ='processor.php' width=1 height=1 marginheight=0 marginwidth=0 scrolling='no' frameborder=0 name='frame'>
</iframe>
</body>

processor.php

<?
if …
cwarn23 387 Occupation: Genius Team Colleague Featured Poster

You don't need to be so insulting Nav33n. This is a person relatively new to daniweb.com. I don't know about you but I value our new members 100%. So if you dislike a person that much just chat to another about something different. There is no good reason for insulting new members that could make a difference.

cwarn23 387 Occupation: Genius Team Colleague Featured Poster

Just a note to finnish off. Try viewing in the browser view->source of that code in your previous post and you will probably see what everybody has been talking about.

cwarn23 387 Occupation: Genius Team Colleague Featured Poster

And also to test your theory below is some code the will prove that javascript cannot communicate with php:

<?
function myfunction($var){
return $var;
}
?>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<script language="javascript" type="text/javascript">
function ILovePHP(var1) {
b = "<?=myfunction('var1');?>";
alert(b);
}
</script>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Untitled Document</title>
</head>
<body>
<form action="" method="post"><input name="armandecastro" name="armandecastro" type="text" onChange="ILovePHP('this is a test string');"></form><p>
</body>
</html>

Now in the above example, the alert box should contain the text 'this is a test string' but instead it just has var1 because it cannot pass variable 1 to php. So try entering the text in the javascript function and getting php to process it and you will get the above results.


Edit:
By saying that, there is nothing stoping you from linking to an invisible iframe that will do php processing 4 you.

Will Gresham commented: Better explaination than mine, hopefully it'll be understood :) +1
cwarn23 387 Occupation: Genius Team Colleague Featured Poster

Well preg match will do the job. Try the following:

<?
preg_match_all('/\<object(.*)\<\/object\>/is',$page_contents,$tmp);
$matches=$tmp[0]; unset($tmp);

//display the first one on the page
echo $matches[0];
?>
cwarn23 387 Occupation: Genius Team Colleague Featured Poster

Also, I just realised a slight flaw in my validator and that mysql_escape real would escape the slashes which would be converted to unicode leaving random slashes. To solve this ya just need to swap the order of the functions. So an update to the code is a follows:

function validate($input) {
$input = htmlentities($input);
$input = mysql_real_escape_string($input);
return $input;
}
$_GET = array_map( 'validate',$_GET );
cwarn23 387 Occupation: Genius Team Colleague Featured Poster
Original Location
C:/wamp/www/prawin/new/locations/test/admin/getpics.php

Try replacing your locations to something like the following.

New Location possibilities
file://C:/wamp/www/prawin/new/locations/test/admin/getpics.php
http://localhost/prawin/new/locations/test/admin/getpics.php
http://localhost/new/locations/test/admin/getpics.php

Probably find that the browser just can't use the style path you used.

cwarn23 387 Occupation: Genius Team Colleague Featured Poster

Well as I mentioned earlier, the following function should be able to validate anything that goes into the url bar.

function validation($input) {
$input = mysql_real_escape_string($input);
$input = htmlentities($input);
return $input;
}

And if you wanted to make sure that your $_GET variables are always varified then use the following script.

function validate($input) {
$input = mysql_real_escape_string($input);
$input = htmlentities($input);
return $input;
}
foreach ($_GET AS $key => $val) {
$_GET[$key]=validate($val);
}
OmniX commented: nice input and custom functions! +2
cwarn23 387 Occupation: Genius Team Colleague Featured Poster

Is this what your looking for? It uses google to search a selected site for selected keywords.

<?php

function search($search_term,$site)
{
global $dsite;
$bits = explode('/', $site);
if ($bits[0]=='http:' || $bits[0]=='https:')
	{
	$site=$bits[0].'//'.$bits[2].'/';
	} else {
	$site='http://'.$bits[0].'/';
	}
$dsite=$site;
$site=urlencode($site);
$search_term=urlencode($search_term);
$curl_handle=curl_init('http://www.google.com.au/search?hl=en&q=site%3A'.$site.'+'.$search_term.'&meta=');
curl_setopt($curl_handle, CURLOPT_HEADER, false);
curl_setopt($curl_handle, CURLOPT_FAILONERROR, true);
curl_setopt($curl_handle, CURLOPT_HTTPHEADER, Array("User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.15) Gecko/20080623 Firefox/2.0.0.15") ); // request as if Firefox   
curl_setopt($curl_handle, CURLOPT_POST, false);
curl_setopt($curl_handle, CURLOPT_NOBODY, false);
curl_setopt($curl_handle,CURLOPT_CONNECTTIMEOUT,4);
curl_setopt($curl_handle,CURLOPT_RETURNTRANSFER,1);
$buffer = curl_exec($curl_handle);
curl_close($curl_handle);

$bufferb=strip_tags($buffer,'<cite>');
preg_match_all("/<cite>[^ ]+ - [0-9]+k - <\/cite>/",$bufferb,$match['url']);
unset($bufferb);
$match['url'][0]=preg_replace('/<cite>([^ ]+) - [0-9]+k - <\/cite>/','$1',$match['url'][0]);
$bufferb=strip_tags($buffer,'<br><div>');
preg_match_all("/<div[^>]+>[^<]+<br>/",$bufferb,$match['des']);
unset($bufferb);





$bufferb=strip_tags($buffer,'<a>');
preg_match_all("/<a href=\"[^\"]+\"\ class\=l[^>]+>[^<]+<\/a>/",$bufferb,$match['title']);
$id=0;
while (isset($match['title'][0][$id]))
    {
    $match['title'][0][$id]=strip_tags($match['title'][0][$id]);
    $id+=1;
    }

$result['url']=$match['url'][0];
$result['des']=$match['des'][0];
$result['title']=$match['title'][0];
unset($match);
unset($buffer);
unset($bufferb);
unset($id);

return $result;
}

echo "<form method='post' style='margin:0; padding:0;'><table border=0 cellpadding=0 cellspacing=0>
<tr><td align='right'>Website:</td><td><input type='text' size=40 name='site'></td></tr>
<tr><td align='right'>Search Term:</td><td><input type='text' size=40 name='searchval'><input type='submit' value='search'></td></tr></table></form><br>";
if (isset($_POST['searchval']) && strlen($_POST['searchval'])>=1)
    {
    $result=search($_POST['searchval'],$_POST['site']);
    $id=0;
    echo "<table border=0 cellspacing=0 cellpadding=0 width=640><tr><td bgcolor='#66CCFF'><table border=0 cellpadding=3 cellspacing=0><tr><td>".
    '<b>Website searched: '.$dsite.'<br> There were '.count($result['title'])." results found with the term '<i>".$_POST['searchval']."</i>'</b></td></tr></table></td></tr>";
    while (isset($result['url'][$id]) && isset($result['des'][$id]))
        {
        echo '<tr><td><a href="http://'.$result['url'][$id].'"><font color=#0000FF>'.$result['title'][$id].'</font></a></td></tr><tr><td>'.$result['des'][$id].'</td></tr><tr><td height="16px"></td></tr>';
        $id+=1;
        }
    echo "</table>";
    }
?>
jyotiu commented: He is the Great cwarn23!!! +1
cwarn23 387 Occupation: Genius Team Colleague Featured Poster

Although you didn't entirely answer my question (scan the website or single webpage) I will assume you want to scan the website in which case will require a bot. I have recently written a bot to scan for site security holes and the bot template is as follows:

<?
set_time_limit(0);
function domain($domainb) {
	$bits = explode('/', $domainb);
	if ($bits[0]=='http:' || $bits[0]=='https:')
		{
		return $bits[0].'//'.$bits[2].'/';
		} else {
		return 'http://'.$bits[0].'/';
		}
	unset($bits);
	}
if (isset($_GET['site'])) {
    echo '<head><title>Bot scanning website - '.domain($_GET['site']).'</title></head><body>';
    } else {
    echo '<head><title>Bot scanner</title></head><body>';
    }
echo '<center><font size=5 face=\'arial black\'><b>PHP Bot Scanner</b></font><br><form method=\'get\' style=\'margin:0px; padding:0px;\'><input type=\'text\' name=\'site\' size=64 value="'.$_GET['site'].'"><input type=\'submit\' value=\'Scan\'></form></center>';
if (substr_replace($_GET['site'],'',3)=='ftp') {
exit('You may not connect to the ftp protocole');
}
if (!isset($_GET['site'])) { exit(''); }

$_GET['site']=domain($_GET['site']);

function url_exists($durl)
		{
		// Version 4.x supported
		$handle   = curl_init($durl);
		if (false === $handle)
			{
			return false;
			}
		curl_setopt($handle, CURLOPT_HEADER, true);
		curl_setopt($handle, CURLOPT_FAILONERROR, true);  // this works
		curl_setopt($handle, CURLOPT_HTTPHEADER, Array("User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.15) Gecko/20080623 Firefox/2.0.0.15") ); // request as if Firefox   
		curl_setopt($handle, CURLOPT_NOBODY, true);
		curl_setopt($handle, CURLOPT_RETURNTRANSFER, true);
		$connectable = curl_exec($handle);
		curl_close($handle);  
        if (preg_match('/200 OK/i',substr_replace($connectable,'',30))) {
            return true;
            } else {
            return false;
            }
		}
//below function will only get links within own domain and not links outside the site.
function getlinks($generateurlf) {
    $datac=file_get_contents($generateurlf);
    preg_match_all('/(href|src)\=(\"|\')[^\"\'\>]+/i',$datac,$media);
    unset($datac);
    $datac=preg_replace('/(href|src)(\"|\'|\=\"|\=\')(.*)/i',"$3",$media[0]);
    $datab=array();
    foreach($datac AS $dfile) {
        $generateurle=$generateurlf;
        if (!in_array(substr_replace($dfile,'',4),array('http','www.'))) {
            if (substr_replace($generateurle,'',0, -1)!=='/') {
                $generateurle=preg_replace('/(.*)\/[^\/]+/is', "$1", $generateurle);
                } else {
                $generateurle=substr_replace($generateurle,'',-1);
                }

            if (substr_replace($dfile,'',1)=='/') {
                if (domain($generateurle)==domain($generateurle.$dfile)) {
                    if (in_array(strtolower(preg_replace('/(.*)[.]([^.\?]+)(\?(.*))?/','$2',basename($generateurle.$dfile))),array('html','htm','xhtml','xml','mhtml','xht','mht','asp','aspx','adp','bml','cfm','cgi','ihtml','jsp','las','lasso','lassoapp','pl','php','php1','php2','php3','php4','php5','php6','phtml','shtml','search','query','forum','blog','1','2','3','4','5','6','7','8','9','10','11','12','13','14','15','16','17','18','19','20','01','02','03','04','05','06','07','08','09','go','page','file')) || substr($generateurle.$dfile,-1)=='/' || !preg_match('/[\.]/i',basename($generateurle.$dfile))) {
                        $datab[]=$generateurle.$dfile;
                        }
                    } …
Amanda_12 commented: Great solving, thanks! +0
cwarn23 387 Occupation: Genius Team Colleague Featured Poster

Are you talking about a 'web page' or an entire 'web site'. Because with a webpage you can just use file_get_contents() to retrieve the data then use regex to find the keywords. However, if you are talking about a 'website' or network of pages then that will require a bot that indexs the website to a database and the search form would check the database. Both ways I can help you just need to know which one.

cwarn23 387 Occupation: Genius Team Colleague Featured Poster

Sorry cwarn but the file you uploaded only contains the code that I displayed.

Well I shall post what was in the file but with every second character on that line being a space so the web browser or daniweb validator doesn't mess it up.

<?
//mysql connections

//then the function
function validation($input) {
$input = mysql_real_escape_string($input);
$ i n p u t   =   s t r _ r e p l a c e ( a r r a y ( ' " ' , ' \ ' ' , ' < ' , ' > ' ) , a r r a y ( ' & # 3 4 ; ' , ' & # 3 9 ; ' , ' & # 6 0 ; ' , ' & # 6 2 ; ' ) , $ i n p u t ) ; 
return $input;
}
?>

Now if you remove every second character on the 6th line which are all spaces then you will see what I mean. Also I checked the text file and yes it does contain the appropriate code which was not posted correctly earlier.

cwarn23 387 Occupation: Genius Team Colleague Featured Poster

why not use htmlentities()?

Another function I wasn't aware of. With that function the script would look like the following:

function validation($input) {
$input = mysql_real_escape_string($input);
$input = htmlentities($input);
return $input;
}
cwarn23 387 Occupation: Genius Team Colleague Featured Poster

Well the php code will allways run when the page firsts loads and not when javascript or html calls it. However, by saying that, javascript can still display the data that was proccessed during the loading of the page but not displayed in the first place.

cwarn23 387 Occupation: Genius Team Colleague Featured Poster

Never thought I would have to explain that but it is because you didn't set the database connection and ya probably didn't create the table too. More info about that can be found at http://www.tizag.com/mysqlTutorial/mysqlconnection.php

cwarn23 387 Occupation: Genius Team Colleague Featured Poster

Well what I can't stress enough is that javascript doesn't trigger the php event. It just retrieves the results from the function being triggered during the page load. Below is an example based on your first example the explains more of what is happening:

<?php
$x="I love PHP  by Arman de Guzman de Castro :-)!";
$returnstring=$x;
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<script language="javascript" type="text/javascript">
function ILovePHP() {
b = "<? echo $returnstring; ?>";
alert(b);
}
</script>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Untitled Document</title>
</head>
<body>
<form action="" method="post"><input name="" name="" type="text" onChange="ILovePHP();"></form><p>
</body>
</html>

The above example does exactly the same thing as the example on post #1. The only difference is a few lines are written differently to make it look more realistic/better.

cwarn23 387 Occupation: Genius Team Colleague Featured Poster

Then heres another example to show that for input it won't work:

<?php
function myfunction(){
mysql_query('INSERT INTO `table` SET `column`="value"') or die(mysql_error());
return 0;
}
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<script language="javascript" type="text/javascript">
function ILovePHP() {
b = "<?=myfunction();?>";
alert(b);
}
</script>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Untitled Document</title>
</head>
<body>
<form action="" method="post"><input name="" name="" type="text" onChange="ILovePHP();"></form><p>
</body>
</html>

If you check the above example, the mysql query cannot be ran more than once and will only ever be ran when the page loads.

cwarn23 387 Occupation: Genius Team Colleague Featured Poster

Well the code you posted is not what is in the text file because in the text file I str_replaced those characters with the unicode equivilent but daniweb code box just doesn't show unicode characters as the code and there for makes the 3rd line look incorrect. So try comparing what you posted to what is in the file I submitted and you will see the difference on the str_replace line.

cwarn23 387 Occupation: Genius Team Colleague Featured Poster

Well the only problem if your example is that the function will execute when the page loads and not when it is called. So say you had a mysql query that inserts something into a database when the function is called. You will find that before the page is finnished loading, the value would have been inserted into the mysql database even though the user hasn't done anything to call the function. So your method may sometimes work for data output but never for data input.

cwarn23 387 Occupation: Genius Team Colleague Featured Poster
mail($to,"Discount offer",$message,"From: noreply@bisnis-indonesia.biz\n MIME-Version: 1.0\n Content-type: text/html; charset=iso-8859-1 \n Reply-To: promo@bisnis-indonesia.biz\nX-Mailer: PHP/");

why is not didn't work www.bisnis-indonesia.biz ? server problem or code problem ?

Try the following:

mail($to,"Discount offer",$message,"From: noreply@bisnis-indonesia.biz\r\nMIME-Version: 1.0\r\nContent-type: text/html; charset=iso-8859-1\r\nReply-To: promo@bisnis-indonesia.biz\nX-Mailer: PHP/\r\n");
cwarn23 387 Occupation: Genius Team Colleague Featured Poster

I agree with kkeith29 because below is an example of what happens when you put real php in the function:

<?php
function myfunction(){
die("The script has now ended.");
return 0;
}
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<script language="javascript" type="text/javascript">
function ILovePHP() {
b = "<?=myfunction();?>";
alert(b);
}
</script>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Untitled Document</title>
</head>
<body>
<form action="" method="post"><input name="" name="" type="text" onChange="ILovePHP();"></form><p>
</body>
</html>

If you try running the script above, the php die() function will end the script before the page is loaded instead of on the onchange event. The reason, the php function is being executed before the page is loaded weather there is an onchange event or not.

cwarn23 387 Occupation: Genius Team Colleague Featured Poster

I have just completed the first version of the script. The main script is as follows:

<?
set_time_limit(0);
ini_set('magic_quotes_gpc','Off');
include('db.php');
mysql_connect($dbhost,$accountname,$password)
or die("Could not connect to MySQL server");
mysql_select_db($database) or die(mysql_error()." Could not select database");

$data=file_get_contents('wordlist.txt');
$words=explode("
",$data);
unset($data);

    
function generate($langto,$dword,$result) {
    $data=file_get_contents('http://langtolang.com/?selectFrom=english&selectTo='.$langto.'&txtLang='.$dword.'&submitButton=Search');
    $data=preg_replace('/(.*)\<tr class=(\"|\'|)title(\"|\'|)\>(.*)\<td([^\>]+)?\>[^\<]+\<\/td\>(.*)\<td([^\>]+)?\>[^\<]+\<\/td\>(.*)/is',"$1",$data);
    preg_match_all('/\<td width\=\"40%\"\>[^\<]+\<\/td\>/is',$data,$matches);
    unset($data);
    $dtranslations=preg_replace('/\<td width\=\"40%\"\>([^\<]+)\<\/td\>/i',"$1",$matches[0]);
    for ($a=0, $b=1; isset($dtranslations[$b]); $a+=2, $b+=2) {
        //if ($dtranslations[$a]==$dword) {
            $c=$a/2;
            if (count($result['english'])<=$c) {
                //$result['english'][]=$dtranslations[$a];
                $result['english'][]=$dword;
                }
            $result[$langto][]=$dtranslations[$b];
            //}
        }
    unset($dtranslations);
    return $result;
    }
echo '<head><title>Word Indexer</title></head><body>'.str_repeat(" ", 256).'<br>'; flush();
foreach ($words AS $word) {
$check = mysql_query('SELECT * FROM `translations` WHERE `english`="'.mysql_real_escape_string($word).'"') or die(mysql_error());
if (mysql_num_rows($check)==0) {
$time_start = microtime(true);
$translation = generate('albanian',$word,array());
$translation = generate('arabic',$word,$translation);
$translation = generate('breton',$word,$translation);
$translation = generate('catalan',$word,$translation);
$translation = generate('chinese_simplified',$word,$translation);
$translation = generate('chinese_traditional',$word,$translation);
$translation = generate('corsican',$word,$translation);
$translation = generate('czech',$word,$translation);
$translation = generate('danish',$word,$translation);
$translation = generate('dutch',$word,$translation);
$translation = generate('esperanto',$word,$translation);
$translation = generate('estonian',$word,$translation);
$translation = generate('finnish',$word,$translation);
$translation = generate('french',$word,$translation);
$translation = generate('gaelic',$word,$translation);
$translation = generate('georgian',$word,$translation);
$translation = generate('german',$word,$translation);
$translation = generate('greek',$word,$translation);
$translation = generate('hebrew',$word,$translation);
$translation = generate('hungarian',$word,$translation);
$translation = generate('icelandic',$word,$translation);
$translation = generate('indonesian',$word,$translation);
$translation = generate('italian',$word,$translation);
$translation = generate('japanese',$word,$translation);
$translation = generate('korean',$word,$translation);
$translation = generate('kurdish',$word,$translation);
$translation = generate('latvian',$word,$translation);
$translation = generate('lithuanian',$word,$translation);
$translation = generate('malagasy',$word,$translation);
$translation = generate('norwegian',$word,$translation);
$translation = generate('polish',$word,$translation);
$translation = generate('portuguese_brazil',$word,$translation);
$translation = generate('portuguese_portugal',$word,$translation);
$translation = generate('romanian',$word,$translation);
$translation = generate('russian',$word,$translation);
$translation = generate('serbo_croat',$word,$translation);
$translation = generate('slovak',$word,$translation);
$translation = generate('slovenian',$word,$translation);
$translation = generate('spanish',$word,$translation);
$translation = generate('swahili',$word,$translation);
$translation = generate('swedish',$word,$translation);
$translation = generate('turkish',$word,$translation);
$translation = generate('vietnamese',$word,$translation);
$translation = generate('yiddish',$word,$translation);
$translation = generate('walloon',$word,$translation);
$translation = generate('welsh',$word,$translation);

for ($i=0;isset($translation['english'][$i]);$i++) {
mysql_query('INSERT INTO `translations` SET `english`="'.mysql_real_escape_string($translation['english'][$i])
.'", …
tortoiseman commented: very thorough solution to my problem +1
cwarn23 387 Occupation: Genius Team Colleague Featured Poster

Perhaps this code will help. I noticed that the imagecreatefromgif was trying to open a jpeg file.

$ext = end(explode('.', $final_file));
if(strtolower($ext) == 'jpg' || strtolower($ext) == 'jpeg'){
    $ext_new = 'jpeg';
    $imgsave='imagejpg';
    } elseif (strtolower($ext) == 'gif'){
    $ext_new = 'gif';
    $imgsave='imagegif';
    } else {
    die ('Invalid Extension.');
    }

$po="imagecreatefrom".$ext_new;
//////////////////Resize///////////////
// Im abit confused but the directories look wrong/confusing
// $po, $finalfilename, $src
$finalfilename="share/".$final_file;
$src = $po($finalfilename);
list($width,$height)=getimagesize($finalfilename);
$newwidth=200;
$newheight=200;
$tmp=imagecreatetruecolor($newwidth,$newheight);
imagecopyresampled($tmp,$src,0,0,0,0,$newwidth,$newheight,$width,$height);
$filename = "share/".$final_file;
if ($imagesave=='imagejpg') {
    $imagesave($tmp,$filename,100);
    } else {
    $imagesave($tmp,$filename);
    }
imagedestroy($src);
//unlink($final_file);
imagedestroy($tmp);
////////////////watermark///////////////////////////
$orgimage=$po($finalfilename); // your image
$watermark=imagecreatefrompng("logo.png");  //transparent watermark logo
// $watermark=imagecreatefromgif("yourlogo.gif");  
imagecopy($orgimage,$watermark,0,0,0,0,imagesx($watermark),imagesy($watermark));

imagejpeg($orgimage,$filename,100);
imagedestroy($watermark);
imagedestroy($orgimage);$ext = end(explode('.', $final_file));
cwarn23 387 Occupation: Genius Team Colleague Featured Poster

Just for an update, what error messages are you getting for the most recent code and what is the most recent code your using?

cwarn23 387 Occupation: Genius Team Colleague Featured Poster

Hi

If you are including a block of code into each page, but you only want it to show on one page, a simple fix would be to retrieve the url, explode it and find the last chunk - if it is 'index.php', then show the flash block, otherwise do not show it.

<?php
$url = $_SERVER['REQUEST_URI'];
$pieces = explode('/', $url);
$page = $pieces[sizeof($pieces) - 1];

if($page == 'index.php')
{
//FLASH CODE HERE
}

?>

A more efficient version of that code is as follows:

if (basename($_SERVER['PHP_SELF']) == 'index.php')
{
//FLASH CODE HERE
}
cwarn23 387 Occupation: Genius Team Colleague Featured Poster

I have attached to this reply a script that will validate both for displaying on the webpage and for mysql queries. Couldn't post it due to the daniweb validator.