|
fly904 wrote:
NDD National Prefix
Cheers! That's what I was looking for. Didn't know what it was called.
|
|
|
|
|
Hi,
I'm having major problems with erratic php behavior. I think it's something to do with the server, though I'm not sure. It is incomprehensible in a way that C++ or VB could never be: the same code will work and then not work even though no inputs or context have changed.
I need to get a handle on this. A step in the right direction would be to get more information out of the server. Is there an "explicit" or "strict" option in php?
I've searched for it here, and on the general Internet and haven't found it.
I could try to explain the behavior but no one would believe me anyway. It is pretty much as if there were a "ghost in the machine" making arbitrary decisions as to when the code will work.
Jeff
|
|
|
|
|
This is a pretty vague problem.
Could you not find any help here[^]?
If at first you don't succeed, you're not Chuck Norris.
|
|
|
|
|
Jeffrey Webster wrote:
erratic php behavior
PHP itself is generally not erratic and pretty straight forward in the way it parses code. You code either works or PHP tells you that it doesn't. You can however, increase decrease what error messages you receieve.
Add one of the following Code to each Page you test / include in a config file.
To display all errors except for notices:
<?php
ini_set('display_errors', 1);
error_reporting(E_ALL ^ E_NOTICE);
?>
To display all errors including notices:
<?php
ini_set('display_errors', 1);
error_reporting(E_ALL);
?>
(I think that's the right way round)
|
|
|
|
|
Hi,
Thanks for your reply and the code.
I'm sorry but I didn't quite understand this:
"Add one of the following Code to each Page you test / include in a config file."
Should I create a php file (say, error_display.php) with the cited code and then include it at the top of each php page? Or should I be editing the php config file directly?
Thanks for any clarification .
Jeff
|
|
|
|
|
Jeffrey Webster wrote: Or should I be editing the php config file directly?
Edit the 'error_reporting' line (or add it) to your php.ini file to look like the following:
error_reporting = E_ALL Then restart your web server.
I would suggest creating your own custom error handler. The following example simply logs the error into a file storing what file the error occurred, what line it happened, the message given and dumps the variables currently stored in the symbol table.
<?php
function errorHandler($type, $message, $file, $line, $symboltable)
{
error_log('ERROR in ' . $file . ' on line ' . $line . ' - ' . $message . ' [var dump] ' . print_r($symboltable, true) . '
', 3, 'errors.log');
if ($type == E_USER_ERROR)
{
die( $message );
}
echo 'An error has occurred, sorry for the inconvenience.';
return true;
}
error_reporting(E_ALL);
set_error_handler('errorHandler');
?>
More options of what you can do the error_log() function can do, such as email, write to the system logger etc., can be found in the documentation[^].
If at first you don't succeed, you're not Chuck Norris.
|
|
|
|
|
Jeffrey Webster wrote:
Should I create a php file (say, error_display.php) with the cited code and then include it at the top of each php page? Or should I be editing the php config file directly?
Either.
1)Create a php file (say, error_display.php) with the cited code and then include it at the top of each php page.
or
2) Use fly904's method. Custom error handler is better, but to start you should probably just get them showing up on the page you are working on.
|
|
|
|
|
|
I am trying to make a script that downloads a file from a link, e.g. it would download file.swf from www.example.com/file.swf and put it on my hard drive.
I can't seem to find any info on this. Ideas? Any php functions I can use? Or some kind of tutorial?
Thanks
Edit:
As an example of this functionality:
Say you have a forum that lets you upload an avatar. You can hit browse, but you can also specify a link to the image you want to use. If you specify a link, it will download the image, resize it, and upload it to the ftp.
modified on Wednesday, September 23, 2009 2:05 AM
|
|
|
|
|
I'll leave it to you to figure out GD for resizing the images, it's very simple. As will I leave it to you to come up with a naming scheme of the uploaded files.
The code's very simple and only needs Mat Kruse's Ajax Toolbox (AjaxRequest.js) to run. You could easily whip up the xmlhttprequest object and call yourself, though.
getFile.php
<?php
$url = $_GET["tgt"];
if ($url == "")
die("No target specified");
function stripFilePath($filePath)
{
return substr(strrchr($filePath, '/'), 1 );
}
function loadHttpFile($url)
{
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$data = curl_exec($ch);
curl_close($ch);
return $data;
}
function saveHttpData($filename, $data)
{
$fp = fopen($filename, "wb");
fwrite($fp, $data);
fclose($fp);
}
$newFilename = sprintf("uploads/%s", stripFilePath($url));
$displayedFilename = stripFilePath($newFilename);
$data = loadHttpFile($url);
saveHttpData($newFilename, $data);
printf ("<a href='%s'>%s</a>", $newFilename, $displayedFilename);
?>
downloadFile.html
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Untitled Document</title>
<script src="../test/AjaxRequest.js"> </script>
<script type="text/javascript">
function myGetAjaxResponse(target, url)
{
AjaxRequest.get(
{
'url':url,
'onSuccess':function(req){ target.innerHTML=req.responseText; }
}
);
}
function onGoBtn()
{
var url, target, src;
src = document.getElementById("urlInput").value;
target = document.getElementById("tgtDiv");
url = "getFile.php?tgt="+src;
myGetAjaxResponse(target, url);
}
</script>
</head>
<body>
<label>URL
<input name="urlInput" type="text" id="urlInput" value="http://pplware.sapo.pt/wp-content/uploads/2007/10/20-xampp-logo-trio.jpg" size="80">
</label>
<br>
<label>Download file & provide new link
<input type="button" name="goBtn" id="goBtn" value="GO!" onclick="onGoBtn();">
</label>
<br>
<div id="tgtDiv">Target Div(Link will go here)</div>
</body>
</html>
|
|
|
|
|
Wow.. this worked great!! Even uploaded it back to my ftp, which is what I was trying to figure out next
Ty very much
|
|
|
|
|
huh1234 wrote: I am trying to make a script that downloads a file from a link, e.g. it would download file.swf from www.example.com/file.swf and put it on my hard drive.
I can't seem to find any info on this. Ideas? Any php functions I can use? Or some kind of tutorial?
download.php
<?
if ( isset( $_GET[ 'file' ] ) )
{
if ( file_exists( $_GET[ 'file' ] ) )
{
header( 'Content-type: application/force-download' );
header( 'Content-Transfer-Encoding: Binary' );
header( 'Content-length: ' . filesize( $_GET[ 'file' ] ) );
header( 'Content-disposition: attachment; filename="' . basename( $_GET[ 'file' ] ) . '"' );
readfile( $_GET[ 'file' ]);
}
else
{
if ( isset( $_SERVER[ 'HTTP_REFERER' ] ) )
header( 'Location: ' . $_SERVER[ 'HTTP_REFERER' ] . '?res=nofilefound' );
else
die( 'No referer!' );
}
}
else
{
if ( isset( $_SERVER[ 'HTTP_REFERER' ] ) )
header( 'Location: ' . $_SERVER[ 'HTTP_REFERER' ] . '?res=nofilegiven' );
else
die( 'No referer!' );
}
?>
And then to call it:
<a href="download.php?file=filename.txt">filename.txt</a>
huh1234 wrote: If you specify a link, it will download the image, resize it, and upload it to the ftp.
You can do that on the fly. http://www.google.co.uk/search?q=php+resize+images[^]
If at first you don't succeed, you're not Chuck Norris.
|
|
|
|
|
Thumbnail function:
<?php
function create_thumbnail($image_path, $thumbnail_width, $thumbnail_height, $thumbnail_path="")
{
$imgSize = getimagesize($image_path);
$imgExtension = "";
switch ($imgSize[2])
{
case 1:
$imgExtension = '.gif';
break;
case 2:
$imgExtension = '.jpg';
break;
case 3:
$imgExtension = '.png';
break;
}
if ($thumbnail_path=="") $thumbnail_path = (basename($image_path, $imgExtension))."_thumb".$imgExtension ;
// Get new dimensions
list($width, $height) = getimagesize($image_path);
// Resample
$resampledImage = imagecreatetruecolor($thumbnail_width, $thumbnail_height);
if ( $imgExtension == ".jpg" )
{
$image = imagecreatefromjpeg($image_path);
}
else if ( $imgExtension == ".gif" )
{
$image = imagecreatefromgif($image_path);
}
else if ( $imgExtension == ".png" )
{
$image = imagecreatefrompng($image_path);
}
imagecopyresampled($resampledImage, $image, 0, 0, 0, 0, $thumbnail_width, $thumbnail_height, $width, $height);
if ( $imgExtension == ".jpg" )
{
imagejpeg($resampledImage, $thumbnail_path);
}
else if ( $imgExtension == ".gif" )
{
imagegif($resampledImage, $thumbnail_path);
}
else if ( $imgExtension == ".png" )
{
imagepng($resampledImage, $thumbnail_path);
}
}
?>
|
|
|
|
|
Cool.. Thanks for the replies. I am working on it right now. Will update results soon =)
|
|
|
|
|
I have installed apache for windows vista. I have configured apache to use Lister:8888 in my httpd.conf and my web service is running. I have both .pl and .cgi files in the ../cgi-bin folder of the apache web folder. I do not have any other webservers running. When I try to display a page (http://localhost:8888/cgi-bin/test.pl or http://localhost:8888/cgi-bin/webpage.cgi). I get the ie error: "localhost is not set up to establish a connection on port "8888" with this computer." Now, if I try http://localhost/cgi-bin/test.pl I get the error "localhost is not set up to establish a connection on port World Wide Web service (HTTP) with this computer. Can anyone help?
Thanks,
Steve Holdorf
|
|
|
|
|
I checked the event logs and have the follow error:
The Apache service named
reported the following error: >>>
httpd.exe: Could not reliably determine the server's fully qualified domain name, using 127.0.0.1 for ServerName
Hope this helps.
|
|
|
|
|
Have you solved this yet? are you using it as a development or live server (is it visible to the world or just you?)?
|
|
|
|
|
Hi all
Need help on frame breaker code.
i have a page with two frames in it.the pages are built in PHP.
the first page displays page from my site whereas the second frame displays page from the other site for which i do not have control on.
but for some sites that do have a frame breaker code in them, those pages open in the parent window rather than opening in the frame.
have tried the security TAG in Iframe but it works only in IE.
for mozilla its of no use.
tried a few things but to no effect.
tried from this link
http://coderrr.wordpress.com/2009/02/13/preventing-frame-busting-and-click-jacking-ui-redressing/[^]
is it even possibe to do so.
Pls help
Thanks in Advance.
Sandeep
|
|
|
|
|
It seems to me, that the way I'd approach it is to do a GET on the desired page, scan the page for any offending code and fix as required.
From the 2minute primer i've just had, it looks like a couple of prime strings to be commented out are "top.location= xxxxxxx" and "top.location.replace"
I guess I'd just try loading the page into a string, and inserting a pair of '/' characters at the start of any line that contains either of the two strings I mentioned. That way, you've killed the javascript before it ever had a chance.
|
|
|
|
|
hi enhzflep
thanks for the reply.
can u pls elaborate with the code so that i can understand it.
also if we try to get a page in a string and strip of the Javascript(frame breaker code) then what is the way to display the stripped content in a iframe.
please have a look at the following link
http://www.iframehtml.com/iframe-scripts.html[^]
it tells way to strip the JS from the page but how to display that page in a iframe then
Regards
Sandeep.
|
|
|
|
|
That's okay Sandeep. Thank-you for introducing me to the whole concept. It's been rather an interesting exercise.
I've had a little play around, and come up with some code that will kill the framebuster in a page that I've been playing with.
It's a two-file approach. There's the html file that makes the request, and the php file that retrieves the requested file
then strips the offending code from it.
In my simple example, I simply replace "top.location=self.location;" with "alert('Framebuster busted!');"
All you'll have to do is to find, download and compress AjaxRequest.js (EDIT: http://www.ajaxtoolbox.com/request/source.php)
[EDIT: No, you don't. I forgot I used a different method. Anyhow, it's still a good library]
Here's some code to play with:
1. getPage.php
<?php
$url = $_GET["tgt"];
if ($url == "")
die("goddamit");
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$data = curl_exec($ch);
curl_close($ch);
echo strip_javascript($data, 0);
function strip_javascript($filter, $allowed=0)
{
$filter = str_replace("top.location=self.location;", "alert('Framebuster busted!');", $filter);
return $filter;
}
?>
2. showInIFrame.html
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Untitled Document</title>
<script type="text/javascript">
function onGoBtn()
{
var url, ifrm, src;
url = document.getElementById("urlInput").value;
ifrm = document.getElementById("tgtFrame");
src = "getPage.php?tgt="+url+"&rand="+parseInt(Math.random()*100);
ifrm.src = src;
}
</script>
</head>
<body>
<label>URL
<input type="text" name="urlInput" id="urlInput" value="www.freedb.org">
</label>
<br>
<label>Load into IFrame
<input type="button" name="goBtn" id="goBtn" value="GO!" onclick="onGoBtn();">
</label>
<br>
<iframe id="tgtFrame">Target Frame</iframe>
</body>
</html>
modified on Wednesday, September 23, 2009 1:23 AM
|
|
|
|
|
Is there a Python debugger that isn't complete rubbish? I just tried PyScripter and it crashes. I understand Eclipse doesn't have breakpoints which makes no sense to me. I tried WinPdb and the installer crashes.
PS. Looks like Wing IDE works.
modified on Wednesday, September 16, 2009 5:50 PM
|
|
|
|
|
|
u could use the pdb..commandline debugger
|
|
|
|
|
how can i upload and save image on server,i want fullcode because my code work locally but not on server
|
|
|
|
|