premiso
Members-
Posts
6,951 -
Joined
-
Last visited
-
Days Won
2
Everything posted by premiso
-
Why are you using eval in the first place? <?php $txResult = "trnApproved=1&trnId=10000021&messageId=1&messageText=%3CLI%3EInvalid+expiry+date%3Cbr%3E&trnOrderNumber=10000021&authCode=TEST&errorType=N&errorFields=&responseType=T&trnAmount=827%2E4&trnDate=9%2F9%2F2009+1%3A35%3A43+AM&avsProcessed=0&avsId=0&avsResult=0&avsAddrMatch=0&avsPostalMatch=0&avsMessage=Address+Verification+not+performed+for+this+transaction%2E&cardType=VI&trnType=P&paymentMethod=CC&ref1=&ref2=&ref3=&ref4=&ref5="; echo "Result:<BR>"; echo $txResult."<br>"; $special = array('/','','%','+'); $txResult = str_replace($special,'',$txResult); $items = explode('&',$txResult); $DBData = array(); foreach ($items as $var) { list($name, $val) = explode('=', $var); $DBData[$name] = $val; echo $var."<br>"; } echo "<br>"; echo "<br>"; echo "this should be Approval:".$trnApproved."<br>"; echo "this should be Transaction ID:".$trnId."<br>"; echo "<br /><Br /><pre>"; echo "Cols held\n"; print_r($DBData); echo "</pre>"; ?> That is one way to do it, it is not tested or checked, but "should" work. Basically it creates an associative array ($DBData) where the index is the name and the item held in the index is the value. You can use a foreach loop to iterate this array and put it into a DB/build the SQL statement for the insert.
-
<?php $test = array("this1valid", "this not valid", "thisvalid", "12345", "!@#notvalid", ".not valid"); foreach ($test as $tes) { if ((preg_match("~^[A-Za-z0-9]+$~si", $tes) > 0)) echo "$tes <b>was valid</b><Br />"; } die(); ?> preg_match. What you will want to look into is Regular Expressions for limiting items/checking fields for stuff you do not want. A great site for help with Regular Expressions is http://www.regular-expressions.info/repeat.html EDIT: Posting same method but with link to a site to help with the regular expressions.
-
Login scrips Members & How to see if they are logged in
premiso replied to gnetuk's topic in PHP Coding Help
CREATE TABLE users ( users_last_click_at DATETIME ); Note that after the datetime there was a comma. Next time post the error MySQL throws, it could help. Try the above and it should create the table just fine. -
You should be able to access the fields using Javascript on the applicantdetail.php. Since this is the PHP forum and what you want will most likely require the use of Javascript I would suggest creating a new topic in the Javascript section, since the original question here was solved.
-
Not sure if this could be the problem, but try using type="button" instead of submit. As submit is really for submitting a form, which could be causing a conflict. If not, I would suggest getting FireFox and using it's Javascript Debugging built in program to help out where you have gone wrong, or even try making it an anchor tag.
-
$var = xmlAPICallStringReturnFunctionHere(parameters here); Note that is not the actual code it is more like "psuedo" code, as I do not know what the api function is or what it takes. If you do, great, fill in the blanks. If not post some code for more help.
-
$file = "mypage.php"; list($file, $ext) = explode(".", $file); echo $file . " has the extension of " . $ext; I tend to prefer explode for something simple like this. Also look at list. Alternatively there is a pathinfo function in mysql php which breaks that out into an associative array so $array['extension'] would contain that, incase the file name may have multiple periods in it.
-
Need Help with Displaying records from Database
premiso replied to chu-boi's topic in PHP Coding Help
One suggestion...how about showing us the code you have tried and where it is failing and write out what you have tried to get it to work. Maybe then we will be able to help you. -
stristr would be one way to do it. $domain = $_SERVER['HTTP_REFERER']; if (stristr($domain, "mydomain.com") !== false) echo "mydomain.com is present."; But remember, checking the referrer is not a fail safe way, as an fyi as it can be spoofed easily.
-
[SOLVED] PHP passing single value rather than entire section
premiso replied to nd3_2000's topic in PHP Coding Help
The issue does not lie in how the data is coming out...well in a sense. If you want to have a select option you will need to make JobNumber be unique for each item or put it as an array in the html. As it is the page sees 10 JobNumbers, of course it will default to the last one on the page. echo "<INPUT TYPE=\"hidden\" NAME=\"JobNumber[]\" VALUE= \"" . $output['JobNo'] . "\" id=\"JobNumber\">"; The [] after JobNumber will turn it into an array. So you just have to access on the post page by: $_POST['JobNumber'][x] where x is the index you want to display. A checkbox might be better than an input as if checked/selected the array will only contain those jobnumbers. -
[SOLVED] file_exists: but filenames have spaces
premiso replied to geekpie's topic in PHP Coding Help
Have you tried this theory? $newfile = $path_info['filename'] . ' [Compatibility Mode].pdf'; The above line, compared to: while (!file_exists("abc [Compatibility Mode].pdf")){ Is the exact same, except that the abc etc is stored in a variable. Now take the original line: $newfile = '"'.$path_info['filename'] . ' [Compatibility Mode].pdf"'; That is not the same, as $newfile will contain "abc [compatibility Mode].pdf" isntead of just abc [compatibility mode].pdf Try it out and see, as I think you were too quick to shoot it down. Given the statement that the manually putting the name in the while loop works, the line change that I provided should work as well. -
Switch is not a loop, it is case driven expression. <?php $type = $_GET['type']; switch($type){ case weapon: $name = $_GET['name']; $query = "SELECT * FROM weapons"; $result = mysql_query($query); while($InfWeap = mysql_fetch_array($result)){ switch($name){ case $InfWeap['weapon_short_name']: echo "Full Name: " . $InfWeap['weapon_name'] . "<br>Short Name: " . $InfWeap['weapon_short_name']; break; default: echo "Default"; } } Should get it to work, pending I put the braces back in right etc.
-
[SOLVED] file_exists: but filenames have spaces
premiso replied to geekpie's topic in PHP Coding Help
$newfile = $path_info['filename'] . ' [Compatibility Mode].pdf'; It was checking for "abc [comp mode].pdf" isntead if just abc [comp mpde].pdf Replace that line and it should work. -
Ok let's try this one more time. error_reporting(E_ALL); ini_set('display_errors', TRUE); $path = 'C:\\Users\\Mike\\Desktop\\'; file_put_contents($path . 'txtfile.txt', pdf2txt($path . 'Athy Register.pdf')); if (file_exists($path . 'txtfile.txt')) { echo "File txtfile.txt has been created succesfully and contains <br><br><pre>"; echo file_get_contents($path . 'txtfile.txt'); }else { echo "File txtfile.txt was not created due to an issue."; } Replace that portion (the if statement was missing a ') and see if that corrects the issue.
-
[SOLVED] PHP passing single value rather than entire section
premiso replied to nd3_2000's topic in PHP Coding Help
echo "<INPUT TYPE=\"hidden\" NAME=\"JobNumber\" VALUE= \"{$output['JobNo']}\" id=\"JobNumber\">"; I believe it is causing havoc because of the array not being put in properly. The above should work as should this: echo "<INPUT TYPE=\"hidden\" NAME=\"JobNumber\" VALUE= \"" . $output['JobNo'] . "\" id=\"JobNumber\">"; Give that a try and see what comes of it. -
It depends on what you require. If you do not need anything but the raw data pulled out...then MySQL alone would be great. If you want to make it look like a report and manipulate the data and pretty it up you will need PHP with MySQL, as they do go hand in hand to help each other. But as said, if you just need it for numbers and small reports, MySQL will be fine, just the data would have to be pulled out using the command line or a script in MySQL which will only give you raw text in a table format vs having PHP pull it out and dressing it up a bit. As far as accuracy on math. It is only as accurate as you code it. You code it wrong it will be off, of course. That all depends on your knowledge and skills. Performance...really you cannot compare them as one is a Database and the other is a Markup/programming Language.
-
Sorry about that "\" is an escape character. $path = 'C:\\Users\\Mike\Desktop\\'; Should get you straight.
-
The text file will be created wherever that script was ran. You can define the path to place it on your desktop if that is easier for you like so: rror_reporting(E_ALL); ini_set('display_errors', TRUE); $path = 'C:\Users\Mike\Desktop\'; file_put_contents($path . 'txtfile.txt', pdf2txt($path . 'Athy Register.pdf')); if (file_exists($path . 'txtfile.txt')) { echo "File txtfile.txt has been created succesfully and contains <br><br><pre>"; echo file_get_contents($path . 'txtfile.txt'); }else { echo "File txtfile.txt was not created due to an issue."; } Which will create it on the desktop for you. But the file exists, or else php would not say it did
-
It depends on your server. For a shared host, a database session can be if you do not setup your session storing right. If you set it up correctly then they are about the same except that the file way will be much quicker. What security problems are you referring to?
-
I believe the content-type, content-disposition, content-transfer-encoding and the actual chunk (I think the chunk at least) should be apart of the headers. Not apart of the message. Move those to apart of $headers instead of $message. $message is expected to be text, hence why you actually see it. If all else fails check the mail function on the php site. Especially the user comments. I believe there will be examples of adding attachments.
-
Ok, lets re-arrange your code and put the call statements up top and remove the print_r <?php // Function : pdf2txt() // Arguments : $filename - Filename of the PDF you want to extract // Description : Reads a pdf file, extracts data streams, and manages // their translation to plain text - returning the plain // text at the end // Authors : Jonathan Beckett, 2005-05-02 // : Sven Schuberth, 2007-03-29 error_reporting(E_ALL); ini_set('display_errors', TRUE); file_put_contents('txtfile.txt', pdf2txt('C:\Users\Mike\Desktop\Athy Register.pdf')); if (file_exists('txtfile.txt')) { echo "File txtfile.txt has been created succesfully and contains <br><br><pre>"; echo file_get_contents('txtfile.txt'); }else { echo "File txtfile.txt was not created due to an issue."; } function pdf2txt($filename){ $data = getFileData($filename); $s=strpos($data,"%")+1; $version=substr($data,$s,strpos($data,"%",$s)-1); if(substr_count($version,"PDF-1.2")==0) return handleV3($data); else return handleV2($data); } // handles the verson 1.2 function handleV2($data){ // grab objects and then grab their contents (chunks) $a_obj = getDataArray($data,"obj","endobj"); $j = -1; foreach($a_obj as $obj){ $a_filter = getDataArray($obj,"<<",">>"); if ((is_array($a_filter)) && (count($a_filter) > 0)) { $j++; $a_chunks[$j]["filter"] = $a_filter[0]; $a_data = getDataArray($obj,"stream\r\n","endstream"); if ((is_array($a_data)) && (count($a_data) > 0)) { $a_chunks[$j]["data"] = substr($a_data[0], strlen("stream\r\n"), strlen($a_data[0])-strlen("stream\r\n")-strlen("endstream")); } } } // decode the chunks foreach($a_chunks as $chunk){ // look at each chunk and decide how to decode it - by looking at the contents of the filter $a_filter = split("/",$chunk["filter"]); if (isset($chunk['data'])) { // look at the filter to find out which encoding has been used if (substr($chunk["filter"],"FlateDecode")!==false){ $data =@ gzuncompress($chunk["data"]); if (trim($data)!=""){ $result_data .= ps2txt($data); } else { //$result_data .= "x"; } } } } if (isset($result_data)) { return $result_data; } else { return false; } } //handles versions >1.2 function handleV3($data){ // grab objects and then grab their contents (chunks) $a_obj = getDataArray($data,"obj","endobj"); $result_data=""; foreach($a_obj as $obj){ //check if it a string if(substr_count($obj,"/GS1")>0){ //the strings are between ( and ) preg_match_all("|\((.*?)\)|",$obj,$field,PREG_SET_ORDER); if(is_array($field)) foreach($field as $data) $result_data.=$data[1]; } } return $result_data; } function ps2txt($ps_data){ $result = ""; $a_data = getDataArray($ps_data,"[","]"); if (is_array($a_data)){ foreach ($a_data as $ps_text){ $a_text = getDataArray($ps_text,"(",")"); if (is_array($a_text)){ foreach ($a_text as $text){ $result .= substr($text,1,strlen($text)-2); } } } } else { // the data may just be in raw format (outside of [] tags) $a_text = getDataArray($ps_data,"(",")"); if (is_array($a_text)){ foreach ($a_text as $text){ $result .= substr($text,1,strlen($text)-2); } } } return $result; } function getFileData($filename){ $handle = fopen($filename,"rb"); $data = fread($handle, filesize($filename)); fclose($handle); return $data; } function getDataArray($data,$start_word,$end_word){ $start = 0; $end = 0; $a_result = array(); while ($start!==false && $end!==false){ $start = strpos($data,$start_word,$end); if ($start!==false){ $end = strpos($data,$end_word,$start); if ($end!==false){ // data is between start and end $a_result[] = substr($data,$start,$end-$start+strlen($end_word)); } } } return $a_result; } ?> Give that a try and see what comes of it.
-
Mike, You have your print_r after a return statement in the function. That will never happen. return $data; print_r ($data); Should be: print_r ($data); return $data; That will show data and allow you to check to make sure that everything is going through properly.
-
The main issue I see is that you are in a while loop...10 times. This will load 10 images which at even just 2.4MB's a peice you are out of memory. The code could be cleaned up a bit better, such as "clearing" the images after the loop runs each time (setting to null). But all in all you should just up your memory limit. I would Suggest a 32MB or 64MB limit for multiple image uploading. EDIT: AFter re-looking at the code I made a few comments: <?php function AddImages() { $i = 1; while($i <= 10) { $image_name = "image_" . $i; if (isset ($_FILES[$image_name])){ $imagename = $_FILES[$image_name]['name']; if($imagename == "") { $i++; }else { $source = $_FILES[$image_name]['tmp_name']; $target = "images/gallery/".$imagename; move_uploaded_file($source, $target); $imagepath = $imagename; $save = "images/gallery/" . $imagepath; //This is the new file $file = "images/gallery/" . $imagepath; //This is the original file list($width, $height) = getimagesize($file) ; $modwidth = 840; $diff = $width / $modwidth; $modheight = $height / $diff; $tn = imagecreatetruecolor($modwidth, $modheight) ; $imgwidth = $modwidth; $imgheight = $modheight; $image = imagecreatefromjpeg($file) ; imagecopyresampled($tn, $image, 0, 0, 0, 0, $modwidth, $modheight, $width, $height) ; // $save is not defined till later....why have this here. imagejpeg($tn, $save, 100) ; $save = "images/gallery/sml_" . $imagepath; //This is the new file $file = "images/gallery/" . $imagepath; //This is the original file list($width, $height) = getimagesize($file) ; $modwidth = 80; $diff = $width / $modwidth; $modheight = $height / $diff; $tn = imagecreatetruecolor($modwidth, $modheight) ; // Why does this seem to be happening twice ? $image = imagecreatefromjpeg($file) ; imagecopyresampled($tn, $image, 0, 0, 0, 0, $modwidth, $modheight, $width, $height) ; imagejpeg($tn, $save, 100) ; /*MYSQL INSERTION*/ $imgpath = $imagepath; $thumbpath = "sml_". $imagepath; $text_caption = "text_".$i; $caption = $_POST[$text_caption]; if(empty($caption)) { $caption = 'No info'; } mysql_query("INSERT INTO images (imgpath, thumbpath, caption, imgwidth, imgheight) VALUES ('$imgpath', '$thumbpath', '$caption', '$imgwidth', '$imgheight')") or die(mysql_error()); $i++; // clear up the resources $tn = null; $image = null; } } else { print "Error: No image<br />"; $i++; } } header("location: admin.php?p=upload&succes=Alle Billeder blev uploaded."); } Primarily it seems that you have duplicate code. I am not sure if this is correct or if it is indeed duplicate and you need to clean it up and remove the duplicates.
-
[SOLVED] Problem with displaying Username on 1st restricted page..
premiso replied to tobimichigan's topic in PHP Coding Help
Members Area: <?php session_start(); if (!$_SESSION["pfno"]) { //user not logged in, redirect to login page header("Location:Login.php"); } include("cn.php"); ?> Change that if statement to the isset. -
Please do not re-create posts that you already have a topic for. http://www.phpfreaks.com/forums/index.php/topic,262713.0.html As far as your issue elaborating on Wildteen's remarks. Somewhere in your code, whether in an include etc, the rsWorkshopRegistrants is being overwritten. Go through all your files searching for that and try and find a spot that may be overwriting the original resource. EDIT: As it goes, the code you have posted us does not show that there is or should be a problem, hence that it must lie else where in the code.