|
how do you code a login form of an e-learning system.
|
|
|
|
|
Like you would for any other system. Help[^].
If at first you don't succeed, you're not Chuck Norris.
|
|
|
|
|
Hi,
How to change the index position of dropdown list,for example if i select 2nd index value of dropdown ,after showing the result again it moves to 0th index , i want it to be remain in 2nd index value... need help.
|
|
|
|
|
Before the page has been loaded, use the selected attribute.
<select id="selectbox">
<option>Not Selected</option>
<option>Also Not Selected</option>
<option selected="selected">Selected</option>
</select>
If you want it during run time; then use javascript.
document.getElementById('selectbox').selectedIndex = 2;
If at first you don't succeed, you're not Chuck Norris.
|
|
|
|
|
Thanks for your fast reply,I want the dropdown index should be changed during runtime,I dont want to assign the static value as 2,
For the next if i select 3, then it will still remain in 2, I want the index to be changing as per user input.
|
|
|
|
|
It was just an example. Obviously you would put it in a function.
function changeSelectedIndex(id, index)
{
document.getElementById(id).selectedIndex = index;
}
changeSelectedIndex('selectbox', n); Obviously, n can be any index (number) of your choice.
If at first you don't succeed, you're not Chuck Norris.
|
|
|
|
|
HI,
Make a bit clear,changeSelectedIndex('selectbox', n); the 'n' is user choice or it changes dynamically at runtime.I want the index should be changed dynamically at runtime.I dont want to edit in code.
|
|
|
|
|
Well I don't know how you're calling the index change so all I can do is put a variable there!
If at first you don't succeed, you're not Chuck Norris.
|
|
|
|
|
Not sure if this is possible but I thought I'd ask:
I'm using mobile phone verification that checks to see if a mobile number was turned on in the last week using a service from liquid11 - which I've tested and works brilliantly. The only problem is it requires the mobile number to be formatted with the country code prefix - e.g. "+44".
So.. how can you get country dialling code from a mobile phone number?
i.e: If a user enters 07123456789, and the phone is in the UK it would need to be converted into the format "+447123456789"
And I can't get the users to enter the prefix either (which would make life a lot easier), so it has to be some form of lookup.
Any ideas?
|
|
|
|
|
You could store all the prefixes (country codes) in a database as well as the numbers (NDD National Prefix) to be replaced. This would only be useful if the user selects the right country from another input. I would store both the initial and the replaced numbers, just in case the user decides to change thier country at a later date. Only the replaced number should be place in text, to make sure the user selects the right country.
It could be added on to an existing language table, such as those used for translations etc, without too much hassle.
Added:
The source I got my data from: http://www.kropla.com/dialcode.htm[^]
If at first you don't succeed, you're not Chuck Norris.
|
|
|
|
|
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
|
|
|
|
|