johnnybenimble
New Members-
Posts
9 -
Joined
-
Last visited
Never
Profile Information
-
Gender
Not Telling
johnnybenimble's Achievements
Newbie (1/5)
0
Reputation
-
Thank you very much. This was obviously my mistake. I got a HTTP 400 error with this, but at least it's an error to actually go on.
-
Apologies, it was further up in the code, I just wanted to post a snippet. $companyName = $_POST['COMPNAME']; $mainContact = $_POST['MAINCONTACT']; $telephone1 = $_POST['TELEPHONE']; $email = $_POST['EMAIL']; $contact2 = $_POST['SECONDCONTACT']; $telephone2 = $_POST['TELEPHONE2']; $email2 = $_POST['EMAIL2']; $package = $_POST['PACKAGE']; The reason for the dollar symbols - the creator of the web service is looking for these. I have tested the output with die("Test: ".$fields_string); and it shows the correct output that I require so I'm thinking it's not a problem with the code?
-
Hi guys, I was wondering if you could help me. I have this code which should send a call to a RESTful web service (which creates a new user in a database). My code is executing without any errors (that I can see) however the user doesn't get created. $url = 'http://127.0.0.1:85/AccountCreator.ashx'; $curl_post_data = array( '$companyName' =>$companyName, '$mainContact' =>$mainContact, '$telephone1' =>$telephone1, '$email' => $email, '$contact2' => $contact2, '$telephone2' => $telephone2, '$email2' => $email2, '$package' => $package ); foreach($curl_post_data as $key=>$value) {$fields_string.=$key. '=' .$value.'&'; } rtrim($fields_string, '&'); //die("Test: ".$fields_string); $ch = curl_init(); curl_setopt ($ch, CURLOPT, $url); curl_setopt ($ch, CURLOPT_POST, true); curl_setopt ($ch, CURLOPT_POSTFIELDS, $fields_string); $result = curl_exec($ch); curl_close($ch); I'm fairly new to PHP also, so I just can't see where I'm doing wrong. I have access to the server also - is there anything I can check on that which would indicate if the web service is being called or not? I've also read this in http://php.net/manual/en/function.curl-setopt.php... I don't think my PHP document is set to multipart/form-data - Would this affect it? I have also tried it like this with the port number, $url = 'http://127.0.0.1/AccountCreator.ashx'; $curl_post_data = array( '$companyName' =>$companyName, '$mainContact' =>$mainContact, '$telephone1' =>$telephone1, '$email' => $email, '$contact2' => $contact2, '$telephone2' => $telephone2, '$email2' => $email2, '$package' => $package ); foreach($curl_post_data as $key=>$value) {$fields_string.=$key. '=' .$value.'&'; } rtrim($fields_string, '&'); //die("Test: ".$fields_string); $ch = curl_init(); curl_setopt ($ch, CURLOPT, $url); curl_setopt ($ch, CURLOPT_PORT , 85); curl_setopt ($ch, CURLOPT_POST, true); curl_setopt ($ch, CURLOPT_POSTFIELDS, $fields_string); $result = curl_exec($ch); curl_close($ch);
-
I've just got word from our payment partners, the error was a HTTP 500 error.
-
Hi, I am trying to post to a REST service using PHP cURL but I'm after running into a bit of difficulty (this being that I've never used cURL before!!). I've put together this code: $url = 'http://127.0.0.1:00/AccountCreator.ashx'; /*Where :00 represents the port number */$curl_post_data = array( 'companyName' =>urlencode($companyName), 'mainContact' =>urlencode($mainContact), 'telephone1' =>urlencode($telephone1), 'email' => urlencode($email), 'contact2' => urlencode($contact2), 'telephone2' => urlencode($telephone2) 'email2' => urlencode($email2); 'package' => urlencode($package) );foreach($curl_post_data as $key=>$value) {$fields_string .=$key. '=' .$value.'&';}rtrim($fields_string, '&');$ch = curl_init();curl_setopt ($ch, CURLOPT, $url);curl_setopt ($ch, CURLOPT_POST, count($curl_post_data));curl_setopt ($ch, CURLOPT_POSTFIELDS, $fields_string);$result = curl_exec($ch);curl_close($ch); I've tried this however it doesn't run. As I am integrating with payment partners, it just says: I have emailed them to find out the exact error, but in the mean time I was wondering could someone take a look at my code to eliminate this as a problem, if possible. Thanks.
-
Hmm I have tried this function drawHorizontalLine($canvas) { // Create a 1000 x 10 image $canvas = imagecreatetruecolor(1000, 10); // Allocate colors $red = imagecolorallocate($canvas, 255, 0, 0); ImageFilledRectangle($canvas, 0, 0, 1000, 10, $red); // Output and free from memory header('Content-Type: image/jpeg'); imagejpeg($canvas); imagedestroy($canvas); } And then further down in my script I have called drawHorizontalLine($canvas); But I get the 500- Internal Server Error. Is the function okay? I'm thinking it's just the way I'm calling it.
-
Apologies. I played around with it an awful lot so I was getting a few different errors. Sometimes it was an internal server error 500... Then sometimes it was a mega long text error..but I know this was after I created the drawHorizontalLine function I wasn't including the correct parameters. The code above for that actually draws the red line..would it be possible to include all that into a function e.g. function drawHorizontalLine...and then call it later on in the script?
-
As in I get a server error and nothing at all displays. I know it's probably just as simple as creating a function, and calling the function somewhere in the script, I'm just not sure where.
-
Hi guys, new to the forum, also newish to PHP so will surely see you guys often johnnybenimble
-
Hi everyone, Newish to PHP and I'm sure this is a simple thing but I was hoping someone could help me out. I have a php file that draws a graph for me (it takes in the coordinates from a text file). What I want to do is insert a red line at the top of the graph (not from start to finish, but starting at a certain point in the graph and finishing at another point). This php code achieves the line I would like to insert into the graph: <?php $canvas = imagecreatetruecolor(1000, 10); // Allocate colors $red = imagecolorallocate($canvas, 255, 0, 0); ImageFilledRectangle($canvas, 0, 0, 1000, 10, $red); // Output and free from memory header('Content-Type: image/jpeg'); imagejpeg($canvas); imagedestroy($canvas); ?> I need to insert this into this php script: <?php $width = 1000; //width and height of the resulting image $height = 230; $drawLastLine = false; //draw 9th line or not $testMode = false; //render only 10 images //returns directory with cached images by name of text file function getCacheDirectory($fname) { $mod = filemtime($fname); $dirname = "cache/" . $fname . "." . $mod . "/"; return $dirname; } //checks if specified txt file is cached function isCached($fname) { $dirname = getCacheDirectory($fname); return file_exists($dirname); } //calculated y-coordinates of base-lines for all 9 lines, returns an array function initStart($height, $number = 9) { $d = $number + 1; $t = $height / $d; $res = array(); $c = 0; for ($i = 0; $i < $number; $i++) { $c += $t; $res[$i] = $c; } return $res; } //draws vertical grey line with specified coordinate function drawVerticalLine($img, $x) { $grey = imagecolorallocate($img, 80, 80, 80); $h = imagesy($img); imagesetthickness($img, 3); imageline($img, $x, 0, $x, $h, $grey); imagesetthickness($img, 0.1); } //cuts unfilled part of image in the right, making its width equal to $realW function cutRight($img, $realW) { $h = imagesy($img); $new = imagecreatetruecolor($realW, $h); imagecopy($new, $img, 0, 0, 0, 0, $realW, $h); return $new; } //makes up an array of required colors function allocateColors($img) { $result = array(); $result['blue'] = imagecolorallocate($img, 0, 0, 255); $result['red'] = imagecolorallocate($img, 255, 0, 0); $result['black'] = imagecolorallocate($img, 0, 0, 0); $result['white'] = imagecolorallocate($img, 255, 255, 241); return $result; } //main function which generates all the images function generateImages($fname) { set_time_limit(0); //there's no time limit, because it's long process global $width, $height, $start, $testMode, $drawLastLine; $lines = 9; $start = initStart($height, $drawLastLine ? $lines : $lines - 1); //colors of line from top bo bottom $lineCol = array('blue', 'blue', 'red', 'red', 'blue', 'blue', 'black', 'red', 'red'); $fp = fopen($fname, "r"); //we open our file with data $header = fgets($fp); $curX = 0; $sumX = 0; $imgNum = 1; $colors = false; $const = 1.0; //that's the constant which can be used to multiply by y-coordinates, i.e. making our graphs scalable by y-coordinate $prevY = array(); for ($i = 0; $i < $lines; $i++) { $prevY[$i] = 0; } $dir = getCacheDirectory($fname); mkdir($dir); $img = false; // $maximumImages = 10; //if we are testing, we will do just 10 images, else we will work until the file ends while ((!$testMode || ($testMode && $imgNum < $maximumImages)) && $line = fgets($fp)) { //if it's time to make up a new image if ($sumX % $width == 0) { //we save old one to file if ($img) { imagegif($img, $dir . $imgNum . ".gif"); $imgNum++; } //and create a new one, along with allocating colors and so on $img = imagecreatetruecolor($width, $height); $colors = allocateColors($img); imagefill($img, 0, 0, $colors['white']); $curX = 0; } $data = explode(",", $line); $time = array_shift($data); $linesCount = $drawLastLine ? $lines : $lines - 1; //we loop through our lines for ($i = 0; $i < $linesCount; $i++) { $ly = $data[$i] * $const; //it's the new Y coordinate, and we counts from baseline with y = 0 $realTo = $start[$i] + $ly; //now we count the baseline too $realFrom = $start[$i] + $prevY[$i]; //that's the previous step's y-coordinate $prevY[$i] = $ly; //we remember current coordinate to draw line on next step $x1 = $curX - 1; $y1 = $realFrom; $x2 = $curX; $y2 = $realTo; //we draw line finally with needed color imageline($img, $x1, $y1, $x2, $y2, $colors[$lineCol[$i]]); } //if the time looks like 235.000000, we need to draw vertical line if (round($time) == $time) { drawVerticalLine($img, $curX); } //we increase both curX (which is used for drawing) and overall x (it indicates how much lines we've processed) $curX++; $sumX++; } // if we didn't save all lines to .gifs, we need to save leftovers if ($curX > 0) { $img = cutRight($img, $curX); imagegif($img, $dir . $imgNum . ".gif"); $imgNum++; } //saving numbers of pictures rendered file_put_contents($dir . "info.txt", ($imgNum - 1)); } $fname = $_GET['file']; //there should be no slashes in filename and it should end with .txt if (strpos($fname, "/") !== false || strpos($fname, "\\") !== false || strpos($fname, ".txt") === false) { echo "Security error!"; die; } //it should exist if (!file_exists($fname)) { echo "No such file!"; die; } //if there are no images cached for our file, we need to generate them if (!isCached($fname)) { generateImages($fname); } $page = 1; $dirname = getCacheDirectory($fname); $maxPages = file_get_contents($dirname . "info.txt"); //$maxPages = 10; $uniqid = uniqid(); $img = $dirname . $page . ".gif?" . uniqid(); include("templates/show2.php.inc"); I'm just lost as to how I achive this line in the longer php script. I've tried creating my own function, and then calling it further down but this just breaks it. Any help is appreciated!!