cwarn23 387 Occupation: Genius Team Colleague Featured Poster

The only problem with using referer page is that some browsers don't send that information to php making $_SERVER empty. This would mean that some users would find it impossible to browse the website. An example is the option in Opera where the user can choose if the browser should submit the referer information. So I find that it is best at all costs to avoid the $_SERVER variable unless you mix some javascript with it which in this case wouldn't be very secure.

cwarn23 387 Occupation: Genius Team Colleague Featured Poster

I checked that each time I re-added the extension and it is not listed under php_info() even though it's in the php.ini file. The php.ini file I located from php_info(). I don't understand why php can't read it when I have followed the tutorials accurately.

cwarn23 387 Occupation: Genius Team Colleague Featured Poster

Would this code do the trick?

<?
$array = array("amit", "hello", "amit", "world", "hello");

/* Sort into an array */
$i=0;
foreach ($array AS $value){
    $result[$value][]=$i;
    $i++;
    }
/* Dump Result */
echo '<xmp>';
print_r($result);
echo '</xmp><hr>';

/* Display Results */
foreach ($result AS $name=>$var) {
    echo $name.' ';
    foreach ($var AS $arrayposition) {
        echo $arrayposition.', ';
        }
    echo '<br>';
    }
?>
cwarn23 387 Occupation: Genius Team Colleague Featured Poster

Anybody at all because this error is really beginning to annoy me. I have followed 3 tutorials all resulting with the same problem. It seems theres something either in the Visual C++ settings or php.ini making the extension unable to communicate with php. I've been spending day and night, every piece of my spair time to try and solve this problem and although I have eliminated all the #define bugs in php itself as reported on the internet, it seems like if there is a missing link between the dll and php. With the exploration of this error, I now understand exactly how the c++ code works and what most of the Visuall C++ options mean.
Also I have tried using C code instead of C++ code and yet the same problem occures. The only modification in the php.ini file was extension=php_talkphp.dll so does anybody have any idea of what this might be?

cwarn23 387 Occupation: Genius Team Colleague Featured Poster

I've just added a url validator for you but it requires the curl extension to be enabled which we all hope is enabled on your server. Below is the new script with a url validator and the error line fixed:

<?php  
  
$url = $_GET['DLURL'];  
  
// Fetch page  
$string = FetchPage($url);  
  
// Regex that extracts the urls from links  
  
$links_regex = '/\<a[^\/\>]*'.  
  
'href=["|\']([^javascript\<b\>\<\/b\>\:].*)["|\']/Ui';  
  
preg_match_all($links_regex, $string, $out, PREG_PATTERN_ORDER);  
  
echo "<pre>"; print_r($out[1]); echo "</pre>";  
  
function FetchPage($path)  
{
$handle   = curl_init($path);
if ($handle!==false){
curl_setopt($handle, CURLOPT_HEADER, false);
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, false);
$connectable = curl_exec($handle);
curl_close($handle);
} else {
$connectable=false;
}
if ($connectable) {
$file = fopen($path, "r");   
}
if (!$file || !$connectable) {
exit("The was a connection error!");  
}   
$data = '';
while (!feof($file)) {  
// Extract the data from the file / url   
$data .= fgets($file, 1024);  
}  
return $data;  
}  
?>
cwarn23 387 Occupation: Genius Team Colleague Featured Poster

I always thought the first was the start recoed and the second was the last record.

I think 3,3 is wrong run an if statement to make sure the count variable is not equal to or greater to 3 this would confuse MySql's brain.

Below is a direct quote from the select syntax of the official mysql manual:

LIMIT {[offset,] row_count | row_count OFFSET offset}

As you can see, it makes an if statement. It can be broken down to two parts. The first is:

LIMIT {row_count}

The above statement make just the row count and note that when something is in brackets it is an optional parameter optional. However, if you were to fill in the optional parameter, since there are now two parameters, the if statement would change to the following where the offset is at the end:

LIMIT {row_count OFFSET offset}

And now for the part that is confusing most people in this thread. An offset is never relative to the row_count. So say you wanted to limit from rows 6 to row 8 you would use LIMIT 6, 2 as you are telling mysql how many rows to count on after six. That's what offset means in any language weather it's mysql, graphics, english etc.

So to explain what LIMIT 3, 3 does. It will limit from result 3 to result 6 as it has counted three rows from result 3. I would have to say that if anything was the error it would be …

OmniX commented: Nice informative post! +3
cwarn23 387 Occupation: Genius Team Colleague Featured Poster

I've followed a tutorial for making php extensions in C++ and although there are no compilation errors, the extension just won't communicate with php. The tutorial is at http://www.talkphp.com/vbarticles.php?do=article&articleid=49&title=creating-custom-php-extensions and my code is as follows:

main.cpp

#include "stdafx.h" 

ZEND_FUNCTION(fetch_talkphp_links); 

zend_function_entry talkphp_ext_functions[] = { 
    ZEND_FE(fetch_talkphp_links, NULL) 
    {NULL, NULL, NULL} 
}; 

zend_module_entry talkphp_ext_module_entry = { 
    STANDARD_MODULE_HEADER, 
    "TalkPHP Extension", 
    talkphp_ext_functions, 
    NULL, NULL, NULL, NULL, NULL, 
    "1.0", 
    STANDARD_MODULE_PROPERTIES 
}; 

ZEND_GET_MODULE(talkphp_ext); 

ZEND_FUNCTION(fetch_talkphp_links) 
{ 
     
    bool useHtml = false; 
    char *link = ""; 

    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|b", &useHtml) == FAILURE) 
    { 
        RETURN_STRING("Missing Parameter", true); 
    } 

    if (useHtml == true) 
    { 
        link = "<a href=\"http://www.talkphp.com\">Visit TalkPHP.com!</a>"; 
    } 
    else 
    { 
        link = "http://www.talkphp.com"; 
    } 

    RETURN_STRING(link, true); 
}

stdafx.h

#pragma once 

// Include the Zend Win32 header and the general PHP header 
#include "zend_config.w32.h" 
#include "php.h"

Php Code:

<?
echo fetch_talkphp_links(true);
?>

Error:

Fatal error: Call to undefined function fetch_talkphp_links()...

Also, I have rebooted apachie and recompiled this code many times and yet still it will not communicate with php. I have even double checked and re-checked the tutorial to make sure I haven't done anything wrong. And I'm using Visual C++ 2008 with Windows XP Pro and PHP 5.
I just can't see any reason why the extension won't communicate with php. Any alternative tutorials for making php extensions in c++ are welcome as I have also tried replacing the code with code from a second tutorial without any luck. It's almost as if php needs something enabled even though I've added …

cwarn23 387 Occupation: Genius Team Colleague Featured Poster

All fixed. Try this:

<?php  
  
$url = $_GET['DLURL'];  
  
// Fetch page  
$string = FetchPage($url);  
  
// Regex that extracts the urls from links  
  
$links_regex = '/\<a[^\/\>]*'.  
  
'href=["|\']([^javascript:].*)["|\']/Ui';  
  
preg_match_all($links_regex, $string, $out, PREG_PATTERN_ORDER);  
  
echo "<pre>"; print_r($out[1]); echo "</pre>";  
  
function FetchPage($path)  
{  
$file = fopen($path, "r");   
  
if (!$file)  
{  
exit("The was a connection error!");  
}   
  
$data = '';  
  
while (!feof($file))  
{  
// Extract the data from the file / url  
  
$data .= fgets($file, 1024);  
}  
return $data;  
}  
?>
cwarn23 387 Occupation: Genius Team Colleague Featured Poster

I would suggest using sessions to check what stage the user is at then make php exit the script with a message if the user has viewed a page in the wrong order. Below is an example:

<? session_start();
//page1.php

$_SESSION['pagestatus']=1;
?>
<a href='page2.php'>Next page</a>
<? session_start();
//page2.php
if ($_SESSION['pagestatus']!==1) {
    die('You have viewed the pages in the wrong order.');
    } else {
    $_SESSION['pagestatus']=2;
    }
?>
<a href='page3.php'>Next page</a>
<? session_start();
//page3.php
if ($_SESSION['pagestatus']!==2) {
    die('You have viewed the pages in the wrong order.');
    } else {
    $_SESSION['pagestatus']=3;
    }
?>
Final page
m-hrt commented: thanx for the help +1
cwarn23 387 Occupation: Genius Team Colleague Featured Poster

There are a few bugs and security holes in that script. So try the following:

mysql_connect(" ") ; //add variables in function
mysql_select_db(" "); //add variables in function

if(!empty($_GET["c"]) && !preg_match('/[^0-9]/',$_GET['k']))
{ $k = $_GET["k"] ; $cnt = $k; $k += 3;  }
else
{$cnt = 0; $k = 3;}
 
$table = '<table  >';
 

$result = mysql_query('SELECT var1 FROM '.mysql_real_escape_string($tab1).' LIMIT '.mysql_real_escape_string($cnt).', 3') or die(mysql_error());  

//for loops are faster than while loops when used properly.
for ($i=0;$row = mysql_fetch_assoc( $result );$i++)
{
       $var1 = $row['name'];
if ( $i == 3 ) {
            $table .= '</tr><tr>';
            $i = 0;
        }
 

$result1 = mysql_query('SELECT * FROM tab2 WHERE var2= "'.mysql_real_escape_string($var1).'"');
$row = mysql_fetch_assoc( $result1 );
$var2 = $row['var2'];
        $table .= "<td > blah blah blah";
 
}
 
$table .= "<tr><td  ><a href=link.php?c=next&k=".$k.">next</a></td></tr>";
echo $table;
csharplearner commented: Amazingly clean code! Thanx :) +1
cwarn23 387 Occupation: Genius Team Colleague Featured Poster

Hi,
Have you considered saving the Excel data as a CSV file, then reading the content of the file into PHP using file_get_content.

Since how this has already been bumped I shall add if you can export the excel file to a CSV file, phpmyadmin will allow you to import the CSV file. Very simple and nearly every server has phpmyadmin.

As a note to FreeGroup, please do not bump very old topics unless your the original author.

cwarn23 387 Occupation: Genius Team Colleague Featured Poster

Yes you sure can and any other mysql syntax.

cwarn23 387 Occupation: Genius Team Colleague Featured Poster

For sms and php you need to sign up to a subscription with a sms provider and a simular thread is at http://www.daniweb.com/forums/thread161220.html
An example php script is located at http://www.clickatell.com/developers/php.php but as for the rest of your question, mysql databases should be able to solve that. Just the sms part that will cost you. I wish it was free!

cwarn23 387 Occupation: Genius Team Colleague Featured Poster

If you are doing $_POST then I have found that the php default settings for slashes are a bit messy and another function needs to be used. So below is an example that only applies for $_POST.

function sqlencrypt($var) {
    return mysql_real_escape_string(htmlentities($var, ENT_QUOTES));
    }
$variable=stripslashes($_POST['variable']);
mysql_query('SELECT * FROM `stringtable` WHERE `string`="'.sqlencrypt($variable).'"');

However a more professional way is as follows:

function sqlencrypt($var) {
    return mysql_real_escape_string(htmlentities($var, ENT_QUOTES));
    }
mysql_query('SELECT * FROM `stringtable` WHERE `string`="'.sqlencrypt(stripslashes($_POST['variable'])).'"');

I hope that doesn't confuse you too much because with the $_POST array, by default the quotation marks are automatically escaped and extra slashes are recorded into the database if not removed.

cwarn23 387 Occupation: Genius Team Colleague Featured Poster

Well the only real changes to be made in the script is the variable $height and what is in the mysql query. So that you can compare, below is another example of the same type thing:

function sqlencrypt($var) {
    return mysql_real_escape_string(htmlentities($var, ENT_QUOTES));
    }
$variable='This is a test.';
mysql_query('SELECT * FROM `stringtable` WHERE `string`="'.sqlencrypt($variable).'"');
cwarn23 387 Occupation: Genius Team Colleague Featured Poster

The Aa1` thing is just random data to be inserted.
Also the htmlentities($var, ENT_QUOTES) converts the quotes and < > tags. All of the conversion techniques I have placed into a custom function called sqlencrypt which returns the result. And the best performance usage I have specified in the previous post.

cwarn23 387 Occupation: Genius Team Colleague Featured Poster

I'm not sure what you mean by overhead but if you are meaning will it take more cpu and longer to load then yes is the answer. And is that a java class because they are meant to be called via html code and not php unless you have worked out how to make php communicate with java.

cwarn23 387 Occupation: Genius Team Colleague Featured Poster

thank you. should i even allow " quotation marks? or is that taking a big risk?

Well in my opinion, the following script shows the best practise for stopping hackers from getting into your database as I have made an unbeatable function.

function sqlencrypt($var) {
    return mysql_real_escape_string(htmlentities($var, ENT_QUOTES));
    }
$height='aA1`';
mysql_query('INSERT INTO `table` SET `column`="'.sqlencrypt($height).'"');

And as for the question about what characters should be allowed, well generally all characters should be allowed into the database but is best if you convert quotes and < > tags. The < > tags are converted so that when you display the mysql query, no malicious code can be executed and instead the raw code will be displayed. Also the reason why convert the quotes - that is because then if the mysql_real_escape_string() function fails to escape there is no way the user can extend the mysql query. You may have also noticed that I used single quotes through the entire script instead of double quotes. That is because single quotes are believed to be slightly faster by a few microseconds and when so many are used the time of execution adds up. The main difference between single quotes and double quotes are that double quotes can contain "$var" and "\n\r" where as single quotes will display those literal characters instead of what they represent. So it is best to use single quotes when possible.

cwarn23 387 Occupation: Genius Team Colleague Featured Poster

The mysql_real_escape_string() will need to be the last change to the variable before entering the mysql query because it adds some slashes before characters such as the apostrophie, quotation marks etc. So when the mysql_real_escape_string() is used then that variable generally can then only be used in a mysql query and nothing more and it is important that you use mysql_real_escape_string() all the time for security and debugging reasons.

cwarn23 387 Occupation: Genius Team Colleague Featured Poster

Probably because your not using the mysql_real_escape_string() function to escape your mysql strings. For security reasons you should allways escape mysql query's. Below is an example:

$height='aA1`';
$value=preg_replace("/[^\`a-z,. \'\-\d]/i", "", $height);
$value=mysql_real_escape_string($value);
mysql_query("INSERT INTO `table` SET `column`='$value'") or die(mysql_error());
cwarn23 387 Occupation: Genius Team Colleague Featured Poster

Two other options are as follows:

$height='aA1`';
echo preg_replace("/[^\`a-z,. \'\-\d]/i", "", $height);
$height='aA1`';
$height=str_replace(array('?','`'),array('','?'),$height);
$height=preg_replace("/[^\?a-z,. \'\-\d]/i", "", $height);
echo str_replace('?','`',$height);
cwarn23 387 Occupation: Genius Team Colleague Featured Poster

Well what seems to be the problem because when I try the following code the apostrophie is allowed:

<?
$height='aA1`';
echo preg_replace("/[^`a-z,. \'\-\d]/i", "", $height);
?>
cwarn23 387 Occupation: Genius Team Colleague Featured Poster

I just checked the script for that error and turns out that the table variable wasn't assigned to the mysql query. So the following updated script should do the job providing the variables at the top are configured correctly.

<?
$username='admin'; //Mysql access username
$password=''; //Mysql access password
$database='mydatabase'; //Database to connect to - not the table name.
$tablename='mytable'; //the name of the table - not the database.
$idfieldname='id'; //the column name for the id field.
//configure above variables

//DO NOT CHANGE THE BELOW
//==========================
mysql_connect('localhost', $username, $password) or die('Invalid login details.<hr>'.mysql_error());
mysql_select_db($database) or die('Cannot connect to selected database.<hr>'.mysql_error()); 
mysql_query('UPDATE `'.$tablename.'` SET `'.$idfieldname.'`=""') or die(mysql_error());
$result=mysql_query('SELECT * FROM `'.$tablename.'`');
if (mysql_num_rows($result)>0) {
    for ($row=1; $data=mysql_fetch_assoc($result); $row++) {
        $where='';
        foreach ($data AS $key => $val) { 
            $where.='`'.$key.'`="'.mysql_real_escape_string($val).'" AND';
            }
        $where=substr($where,0,-3);
        $where.='LIMIT 1';
        mysql_query('UPDATE `'.$tablename.'` SET `'.$idfieldname.'`="'.$row.'" WHERE '.$where) or die(mysql_error());
        unset($where);
        unset($key);
        unset($val);
        }
    echo 'ID field updated';
    } else {
    echo 'Nothing to update';
    }
?>
cwarn23 387 Occupation: Genius Team Colleague Featured Poster

I think what you are looking for is .htaccess files which is part of the apachie rewrite module. With .htaccess files, you can make fake urls that on the server side rewrite to the real file.

Example - real url:
site.com/index.php?username=cwarn23&id=blog
Fake url:
site.com/cwarn23/blog/

I would provide some code but I just need to know your real url is including what goes after the ? symbol.

cwarn23 387 Occupation: Genius Team Colleague Featured Poster

Depending on your dictionary I am guessing you will need a numbered id field if there are non a-z0-9 characters. To solve this, the following script will automatically fill in the id field for you:

<?
$username='admin'; //Mysql access username
$password=''; //Mysql access password
$database='mydatabase'; //Database to connect to - not the table name.
$tablename='mytable'; //the name of the table - not the database.
$idfieldname='id'; //the column name for the id field.
//configure above variables

//DO NOT CHANGE THE BELOW
//==========================
mysql_connect('localhost', $username, $password) or die('Invalid login details.<hr>'.mysql_error());
mysql_select_db($database) or die('Cannot connect to selected database.<hr>'.mysql_error()); 
mysql_query('UPDATE `table` SET `'.$idfieldname.'`=""') or die(mysql_error());
$result=mysql_query('SELECT * FROM `'.$tablename.'`');
if (mysql_num_rows($result)>0) {
    for ($row=1; $data=mysql_fetch_assoc($result); $row++) {
        $where='';
        foreach ($data AS $key => $val) { 
            $where.='`'.$key.'`="'.mysql_real_escape_string($val).'" AND';
            }
        $where=substr($where,0,-3);
        $where.='LIMIT 1';
        mysql_query('UPDATE `'.$tablename.'` SET `'.$idfieldname.'`="'.$row.'" WHERE '.$where) or die(mysql_error());
        unset($where);
        unset($key);
        unset($val);
        }
    echo 'ID field updated';
    } else {
    echo 'Nothing to update';
    }
?>

I made this script as part of a mysql tutorial. Hope it helps.

cwarn23 387 Occupation: Genius Team Colleague Featured Poster

Well just as another validator option, try making your php file the following:

<?php
 
$target_path = "uploads/";
 
$target_path = $target_path . basename( $_FILES['uploadedfile']['name']);
if (!empty($_FILES)) {
    if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) {
        echo "The file ".  basename( $_FILES['uploadedfile']['name']).
        " has been uploaded";
    } else{
        echo "There was an error uploading the file, please try again!";
    }
}
?>
cwarn23 387 Occupation: Genius Team Colleague Featured Poster

I read that about 2 days ago and the example code seems to be buggy on my compiler and can't seem to load up the online demo. So I guess currently it is only possible for text to speech to be done on .jar files and not .class files. I'll see what else I can get Java to do though as I have only began to learn Java. I think a 2d online game engine would be cool but might be challenging.

cwarn23 387 Occupation: Genius Team Colleague Featured Poster

I just checked links and one of them says that it needs to be a jar file while the plugin link links doesn't have much. As for the IDE, I have been using the Netbeans IDE and it appears that it isn't possible to mix .jar files with .class files because the option appears under the project section where it effects all files. And so I guess somehow I am going to have to program an interface between to two compiled Java programs as they would need to be compiled separately. Also, I have found another api called fetival which I will check out but other than that, does anybody know of any other text to speech Java software?

cwarn23 387 Occupation: Genius Team Colleague Featured Poster

I just tried multiple classes like adatapost suggested and I haven't yet had any luck but what I am trying to figure out is how to have a combination of .jar and .class files working together so that the browser communicates with the .class file while the system communiticates with the .jar file.
So far I managed to compile the project in 3 .class files (one that lets them communicate) and am trying to make one of them a .jar file. So does anybody know how to make a .jar file in netbeans or even in Java or is there some option inside the compiler instead of some code that needs adding?

Currently my code is as follows:
voice.java

import com.sun.speech.freetts.Voice;
import com.sun.speech.freetts.VoiceManager;
import com.sun.speech.freetts.audio.JavaClipAudioPlayer;

public class voice {
public void main(String[] args) {


        String voiceName = (args.length > 0)
            ? args[0]
            : "kevin16";


        /* The VoiceManager manages all the voices for FreeTTS.
         */
        VoiceManager voiceManager = VoiceManager.getInstance();
        Voice helloVoice = voiceManager.getVoice(voiceName);

        /* Allocates the resources for the voice.
         */
        helloVoice.allocate();

        /* Synthesize speech.
         */
        helloVoice.speak("Thank you for giving me a voice. "
                         + "I'm so glad to say hello to this world.");

        /* Clean up and leave.
         */
        helloVoice.deallocate();
///        System.exit(0);
    }
    }

voicedisplay.java

// required when you create an applet
import java.applet.*;
// required to paint on screen
import java.awt.*;






public class voicedisplay extends Applet {
public class voicedisplayin extends voicedisplay {

    public void init()
        {

        }

// This method gets called when …
cwarn23 387 Occupation: Genius Team Colleague Featured Poster

Hi, I have been trying to get the Jsapi (Java Speech API) embeded into my web applet but have had quite a few troubles. The script for the Jsapi from what I can see was designed for .Jav files where as I am trying to make a .class file. So my problem is that when I use the following code, although netbeans can view to code fine other than the draw function. But when I export the file and try it in the web browser the web browser repeats the following error hundreds of times:

Exception in thread "AWT-EventQueue-5" java.lang.NullPointerException
	at java.awt.LightweightDispatcher$3.run(Unknown Source)
	at java.awt.event.InvocationEvent.dispatch(Unknown Source)
	at java.awt.EventQueue.dispatchEvent(Unknown Source)
	at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
	at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
	at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
	at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
	at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
	at java.awt.EventDispatchThread.run(Unknown Source)

And my code is as follows:

// required when you create an applet
import java.applet.*;
// required to paint on screen
import java.awt.*;

import com.sun.speech.freetts.Voice;
import com.sun.speech.freetts.VoiceManager;
import com.sun.speech.freetts.audio.JavaClipAudioPlayer;




public class voice extends Applet {


    public void init()
        {

        }

// This method gets called when the applet is terminated
// That's when the user goes to another page or exits the browser.
    public void stop()
        {
        // meant be be empty.
        }

// The standard method that you have to use to paint things on screen
    public void paint(Graphics g)
        {
        //in here is the paint data.
        g.drawString("This is a sample",10,20);
        }
    public static void main(String[] args) {


        String voiceName = (args.length > 0)
            ? args[0]
            : "kevin16";


        /* The …
cwarn23 387 Occupation: Genius Team Colleague Featured Poster

Try something like this:

<?php
error_reporting(E_ALL);

header("location: index.php");
include("conn.php");
$mode=$_GET["mode"];
if($mode=="add") {
$MachineNo=$_POST["MachineNo"];
$MnfgDate=$_POST["MnfgDate"];
$PRD='tablename'; //make sure $RPD is assigned to the table name
$sql="insert into $PRD(MachineNo,MnfgDate) values('".
mysql_real_escape_string($MachineNo)."','".mysql_real_escape_string($MnfgDate)."')";
$result=mysql_query($sql) or die(mysql_error());


} elseif($mode=="update") {
//use stripslashes if magicquotes are on.
$MachineNo=stripslashes($_POST["MachineNo"]);
$MnfgDate=stripslashes($_POST["MnfgDate"]);
$sn=stripslashes($_POST["MnfgDate"]);
$sql="update $PRD set MachineNo='".mysql_real_escape_string($MachineNo)."',MnfgDate='".
mysql_real_escape_string($MnfgDate)."' where MnfgDate='".mysql_real_escape_string($sn)."'";
//echo $sql;
$result=mysql_query($sql) or die(mysql_error());
header("location: index.php");
}
?>
cwarn23 387 Occupation: Genius Team Colleague Featured Poster

why are you using sessions?

Just have img.php read the image file and resize it and display it.

On the page where the images are suppose to be displayed call the image using the id in the database. i.e. <img src="img.php?id=image_id_here" /> . In the img.php use $_GET to resize and display the proper image.

Great idea then the server is dual processing since it is processing multiple php files at the same time. As for the code index.php is as follows:

<?
//database connections
mysql_connect('localhost','root','');
mysql_select_db('mydatabase');

$result_images = mysql_query("SELECT image_path FROM userfolders");
for ($row=0;$row<mysql_num_rows($result_images);$row++) {
echo '<img src="img.php?id='.$row.'">';
}
?>

Then img.php is as follows:

<?
if (!preg_match('/[^0-9]/',$_GET['id'])) {
header('Content-Type: image/jpeg');
// generating a array with image paths 
mysql_connect('localhost','root','');
mysql_select_db('mydatabase');

$result_images = mysql_query('SELECT image_path FROM userfolders LIMIT '.$_GET['id'].',1');
if (mysql_num_rows($result_images)>0) { //protect from integer injection bugs
$record_images = mysql_fetch_assoc($result_images);

// generating a thumbnail 
$thumb_height = 100;
list($width, $height) = getimagesize($record_images['image_path']);
$ratio = ($height/$width);
$newheight = $thumb_height;
$newwidth = ($thumb_height/$ratio);

$img = imagecreatetruecolor($newwidth, $newheight);
$source = imagecreatefromjpeg($record_images['image_path']);

imagecopyresized($img, $source, 0, 0, 0, 0, $newwidth, $newheight, $width, $height);
// displaying thumbnail (no echo or print)
imagejpeg($img);
}
}
?>

Note that the ONLY thing to change in img.php is the database connections.
Also the code in index.php can be added to your existing script. I have tested it to make sure the code works.

cwarn23 387 Occupation: Genius Team Colleague Featured Poster

The $_SESSION is just an array that contains all of the picture data to send to the next page where it can be displayed via html <img src= code. But as for the error, I have just tested the code and it appears as if $_SESSION is not binary safe. Also I have updated the code to the following:

<? session_start();

// generating a array with image paths 
mysql_connect('localhost','root','');
mysql_select_db('mydatabase');


$query_images = "SELECT image_path FROM userfolders" ;
$result_images = mysql_query($query_images);

for ($row=0;$record_images = mysql_fetch_assoc($result_images);$row++) {
$filename = $record_images['image_path'] ;

// generating a thumbnail 
$thumb_height = 100;
list($width, $height) = getimagesize($filename);
$ratio = ($height/$width);
$newheight = $thumb_height;
$newwidth = ($thumb_height/$ratio);

$_SESSION['img'][$row] = imagecreatetruecolor($newwidth, $newheight);
$source = imagecreatefromjpeg($filename);

imagecopyresized($_SESSION['img'][$row], $source, 0, 0, 0, 0, $newwidth, $newheight, $width, $height);
  // displaying thumbnail
echo '<img src="img.php?id='.$row.'">';
}

?>
<? session_start();
sleep(1);
if (!preg_match('/[^0-9]/',$_GET['id'])) {
header('Content-Type: image/jpeg');
imagejpeg($_SESSION['img'][$_GET['id']]);
imagedestroy($_SESSION['img'][$_GET['id']]);
}
?>

From a number of tests on the code such as displaying what $_SESSION[0] contains, it appears when storing binary data, the data is rejected and just an empty string is stored. So this will make it a little harder to solve. An alternative solution to sessions is longer lasting cookies which is like a variation of cookies and sessions combined.

cwarn23 387 Occupation: Genius Team Colleague Featured Poster

The following will do the job and I have even debugged a php timezone problem in this script.

if (ini_get('date.timezone')=='') {
    ini_set('date.timezone','Europe/London');
    }
date_default_timezone_set(ini_get('date.timezone'));

echo 'Current time: '.date('h:i:s').'<br>'; //current time
echo 'In 10 Minutes:'.date('h:i:s',strtotime('+10 minutes')); //future time
cwarn23 387 Occupation: Genius Team Colleague Featured Poster

Hi BzzBee,
I don't know about you but I prefer xampp. Although I haven't tried wamp I find xampp really easy to make modifications to and it even has a status control panel. Although xampp and wamp are basically the same I guess it doesn't really matter which you choose unless somebody can state what makes wamp special/popular.

cwarn23 387 Occupation: Genius Team Colleague Featured Poster

If you are trying to send php code to the file then perhaps it is better to use single quotes like the following so variables inside the string do not display their values:

$idhandle = fopen($filename, 'r+') or die("can't open file");
$id = '<?php $lastid = "$lastid"; ?>';

fwrite($idhandle, $id);
fclose($idhandle);

Or if you just want the value of the second variable substituted with its value while the first variable stays as it is:

$id = '<?php $lastid = "'.$lastid.'"; ?>';

Or if you want all of the variable names substituted with their values

$id = "<?php $lastid = \"$lastid\"; ?>";

It is unclear exactly what result you want in the text file but I hope the above examples help solve the question.

cwarn23 387 Occupation: Genius Team Colleague Featured Poster

I just tested the script and found out that 2 variable names I placed were incorrect. So replace the end bit with the following:

list($width, $height) = getimagesize($file_tmp);
           //calculate the image ratio
           if ($width>$height) {
               $ratio=$height/$width;
               $newwidth=200;
               $newheight=$newwidth*$ratio;
               } else {
               $ratio=$width/$height;
               $newheight=200;
               $newwidth=$newheight*$ratio;
               }           
           //function for resize image.
           if (function_exists(imagecreatetruecolor)){
           $resized_img = imagecreatetruecolor($newwidth,$newheight);
           }else{
                 die("Error: Please make sure you have GD library ver 2+");
           }
           //the resizing is going on here!
           imagecopyresized($resized_img, $new_img, 0, 0, 0, 0, $newwidth, $newheight, $width, $height);
           //finally, save the image
           ImageJpeg ($resized_img,"$path_thumbs/$rand_name.$file_ext");
           ImageDestroy ($resized_img);
           ImageDestroy ($new_img);
 
 
        }
 
        //ok copy the finished file to the thumbnail directory
		move_uploaded_file ($file_tmp, "$path_big/$rand_name.$file_ext");
cwarn23 387 Occupation: Genius Team Colleague Featured Poster

Do you mean like this:

//make sure this directory is writable!
		$path_thumbs ='c:/wamp/www/thumb';
		
		//the new width of the resized image, in pixels.
		$img_thumb_width = 200; // 

		$extlimit = "yes"; //Limit allowed extensions? (no for all extensions allowed)
		//List of allowed extensions if extlimit = yes
		$limitedext = array(".gif",".jpg",".png",".JPG",".JPEG",".jpeg",".bmp");
		
		//the image -> variables
	    $file_type = $_FILES['vImage']['type'];
        $file_name = $_FILES['vImage']['name'];
        $file_size = $_FILES['vImage']['size'];
        $file_tmp = $_FILES['vImage']['tmp_name'];

        //check if you have selected a file.
        if(!is_uploaded_file($file_tmp)){
           echo "Error: Make sure Your Image is not More 2MB before You Upload!. <br><a href=profilephoto.php>back</a>";
           exit(); //exit the script and don't process the rest of it!
        }
       //check the file's extension
       $ext = strrchr($file_name,'.');
       $ext = strtolower($ext);
       //uh-oh! the file extension is not allowed!
       if (($extlimit == "yes") && (!in_array($ext,$limitedext))) {
          echo "Wrong file extension.  <br>--<a href=profilephoto.php>back</a>";
          exit();
       }
       //so, whats the file's extension?
       $getExt = explode ('.', $file_name);
       $file_ext = $getExt[count($getExt)-1];

       //create a random file name
       $rand_name = md5(time());
       $rand_name= rand(0,999999999);
       //the new width variable
       $ThumbWidth = $img_thumb_width;

	   //////////////////////////
	   // CREATE THE THUMBNAIL //
	   //////////////////////////
	   
       //keep image type
       if($file_size){
          if($file_type == "image/pjpeg" || $file_type == "image/jpeg"){
               $new_img = imagecreatefromjpeg($file_tmp);
           }elseif($file_type == "image/x-png" || $file_type == "image/png"){
               $new_img = imagecreatefrompng($file_tmp);
           }elseif($file_type == "image/gif"){
               $new_img = imagecreatefromgif($file_tmp);
           }
           //list the width and height and keep the height ratio.
           list($width, $height) = getimagesize($file_tmp);
           //calculate the image ratio
           if ($width>$height) {
               $ratio=$height/$width;
               $newwidth=200;
               $newheight=$width*$ratio;
               } else {
               $ratio=$width/$height;
               $newheight=200;
               $newwidth=$height*$ratio;
               }           
           //function for resize image.
           if (function_exists(imagecreatetruecolor)){
           $resized_img = imagecreatetruecolor($newwidth,$newheight);
           }else{
                 die("Error: Please make sure you have GD library ver 2+"); …
cwarn23 387 Occupation: Genius Team Colleague Featured Poster

Hi,
I have been trying to find a way to get my databases on two external hard drives plus one internal hard drive but I just can't find a way to place each database on a separate drive. The only thing I have come across is windows junctions but can't find tutorials on windows junctions but not sure if that will even work. Does anybody know how I can place 3 MySQL databases on 3 different drives without merging the drives?

Operating System: Windows XP Pro
Hard Drive Sizes: 500GB, 1.5TB, 300GB
MySQL Version: 5.1.30

cwarn23 387 Occupation: Genius Team Colleague Featured Poster

Yes I agree.
How to confirm, the use of the -> symbol combination and also with the use of the terms public function and private function

cwarn23 387 Occupation: Genius Team Colleague Featured Poster

Also, you may want to note that the following script commonly used will cause an error on some servers:

//mysql connections

$result=mysql_query('SELECT * FROM `table`');
while ($row=mysql_fetch_array($result)) {
    echo 'test didn\'t work. There shouldn\'t be any rows in the table.';
    break;
    }

Instead the following should be used:

//mysql connections

$result=mysql_query('SELECT * FROM `table`');
if (mysql_num_rows($result)>0) {
while ($row=mysql_fetch_assoc($result)) {
    echo 'test didn\'t work. There shouldn\'t be any rows in the table.';
    break;
    }
}
cwarn23 387 Occupation: Genius Team Colleague Featured Poster

It appears that you have echo'ed the picture instead of displaying it. And I am guessing that the image is attached to an email so it may be kinda hard to fix since those scripts are usually very large. So if the picture is an attachment then check that the attachment is the correct format and that it is being sent in binary style. If however you are trying to display the picture in the email then you will need to find another method to do so as you are only displaying the binary contents instead of the picture contents.
Sorry that I can't help you much just that email with attachments is one of the few things that send my head dizzy. lol

cwarn23 387 Occupation: Genius Team Colleague Featured Poster

Well then what type of condition exactly do you want no access to display. Is it when no rows are found in the loop above or is it when the variable is empty. What type of if action do you want done?

cwarn23 387 Occupation: Genius Team Colleague Featured Poster

There is a nice thread at http://www.daniweb.com/forums/showthread.php?t=185571&highlight=session+expire
and to change the session expiry time (if the session id is not in the url) you can simply use the following code:

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

Hope that helps.

cwarn23 387 Occupation: Genius Team Colleague Featured Poster

Although I don't fully get how those 2 scripts merge I can tell you now that you should never store the raw password in a cookie. Instead you should hash it or use sessions like you've suggested. To use sessions it is really really easy. Using sessions is like using variables. Below is an example of 2 pages using sessions where the data will be passed between each other:

<? session_start();
//no browser output before session start
$_SESSION['variable']='asldfkjas;ldfasldkfjasldkjfa;lsdkjfa;';
?>
<a href='page2.php'>Next page</a>

Above is index.php and below is page2.php

<? session_start();
//no browser output before session start!
echo $_SESSION['variable'];
?>

As you can see in the above example it is really simple stuff however when using sessions, only store the username in the session and to check if they are logged in use the following:

if (isset($_SESSION['username'])) {
// logged in.
}

Hope that all helps you understand and the one thing people must note is to never keep a record of somebodys password on their computer and preferable not in the servers long term memory too.

cwarn23 387 Occupation: Genius Team Colleague Featured Poster

Try changing the if statement at the end of your script to the following:

if($row['user']=='' || !isset($row['user'])) {
echo "No Access";
/*echo '<script type="text/javascript>
document.validate.name.focus();
</script>';*/
} else {
echo " Acces"; 
}
?>
</body>
</html>
cwarn23 387 Occupation: Genius Team Colleague Featured Poster

Edit: Accidental double posted my post as my internet was so slow.

cwarn23 387 Occupation: Genius Team Colleague Featured Poster

Well then you didn't replace the file properly and left some random bits left at the end. In the below quote is what the entire files should be.

The script will need to be spreaded over two php files and so your current file should be as follows:

<? session_start();

// generating a array with image paths 

$query_images = "SELECT image_path FROM userfolders" ;
$result_images = mysql_query($query_images);
confirm_query($result_images);

for ($row=0;$record_images = mysql_fetch_assoc($result_images);$row++) {
          $image_list[] = $record_images['image_path'] ;


// generating a thumbnail 

$thumb_height = 100;


//$filename=$record_images['image_path'];
$filename = $image_list[];
list($width, $height) = getimagesize($filename);
$ratio = ($height/$width);
$newheight = $thumb_height;
$newwidth = ($thumb_height/$ratio);

$thumb = imagecreatetruecolor($newwidth, $newheight);
$source = imagecreatefromjpeg($filename);

$_SESSION['img'][$row] = imagecopyresized($thumb, $source, 0, 0, 0, 0, $newwidth, $newheight, $width, $height);

  // displaying thumbnail

echo '<img src="img.php?id='.$row.'">';
}
?>

Then img.php should be as follows:

<? session_start();
if (is_int($_GET['id'])) {
header('Content-Type: image/jpeg');
imagejpeg($_SESSION['img'][$_GET['id']]);
imagedestroy($_SESSION['img'][$_GET['id']]);
}
?>
cwarn23 387 Occupation: Genius Team Colleague Featured Poster

now using this code u posted i m getting the output as

'; } ?>

Well the large code box in post #11 (my last set of code) was designed to be the entire page. If you have more to the page then post the entire php file and I shall help you embed the code. Or perhaps you forgot to delete the last line when replacing the file. In any case just let me know weather there is more code to the page and if there is please post it to see how you have embeded my sample code.

cwarn23 387 Occupation: Genius Team Colleague Featured Poster

Well for starters, the php.ini file configures the functions associated with php and has nothing to do with .htaccess files. So basically, the php.ini file is a default settings file. If however you want to enable .htaccess files then it is the apache httpd.conf file that you need to modify so that the rewrite module is enabled.