Jump to content

Really Really Stuck... Need Help...


ricerocket

Recommended Posts

Hi, I don't know anything about CSV files or how to use them or anything and I wanted to know how to make the script below read a CSV file then use the information in there (email/password) to create the account...

 

<!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=iso-8859-1">
<title>Add Cpanel Email Accounts</title>
</head>

<body>

<fieldset>
<legend>Add a Cpanel Email Account</legend>
<form name="add_cpemail">
<fieldset>
<legend>Username</legend>
<input type="text" name="username" class="form_text" />
</fieldset>
<fieldset>
<legend>Password</legend>
<input type="password" name="password1" class="form_text" />
</fieldset>
<fieldset>
<legend>Re-type your Password</legend>
<input type="password" name="password2" class="form_text" />
</fieldset>
<fieldset>
<input type="submit" name="send" class="form_button" value="Create Email Account" />
</fieldset>
</form>
</fieldset>

<script type="text/javascript">
<!--

// form validation
function init() {
var f = document.forms.add_cpemail;
var e = f.elements;
f.onsubmit = function() {
// check username
if (!e.username.value || e.username.value == '') {
alert('Enter a username.');
return false;
}
// check password
if (e.password1.value != e.password2.value) {
alert('Please verify that your password and password confirmation match.');
return false;
}
}
}

window.onload = init();

//-->
</script>

<?php

// required cpanel data
define( 'CPEMAIL_DOMAIN', 'example.com'); // Cpanel domain
define( 'CPEMAIL_SSL', 0); // 0 = no SSL, 1 = Uses SSL
define( 'CPEMAIL_PORT', 2082); // usually the port is 2082 withought SSL and 2083 with SSL
define( 'CPEMAIL_THEME', 'bluelagoon'); // x is the default theme, others include: bluelagoon, x2, xmail, xcontroller, monsoon
define( 'CPEMAIL_QUOTA', 10); // email quota in Megabytes

// sensitive cpanel info
define( 'CPEMAIL_USER', 'username'); // Cpanel Username
define( 'CPEMAIL_PASS', 'password'); // Cpanel Password

if (isset($_GET['send'])) {

$username = $_GET['username'];
$password = $_GET['password1'];

$url = 'http'.(CPEMAIL_SSL ? 's' : '').'://'.CPEMAIL_USER.':'.CPEMAIL_PASS.'@'.CPEMAIL_DOMAIN.':'.CPEMAIL_PORT.'/frontend/'.CPEMAIL_THEME.'/mail/doaddpop.html';
$url .= '?email='.$username.'&domain='.CPEMAIL_DOMAIN.'&password='.$password.'&quota='.CPEMAIL_QUOTA;

// make the http request to cpanel, this is where the email is created
// this is just like the browser making the request, only php does it for the user
$txt = http_request( $url );

// in a live situation, you would parse the returned html, and see if the email was successfully created.
// because this is dependent on the Cpanel theme, I didnt put it in. 
// A simple test example would be:
// if (strpos($txt, 'Successful') !== false) { echo 'Your account was created, please log in.'; } 
// the above checks for the occurance of Successful in the returned html, which occurs when an email is created (english)
// note: different Cpanel themes give different html output, and may be in English or other language
echo '<hr />';
echo $txt; // show the result of the http request

}

// makes an fopen request to the url and returns the content
function http_request($url) {
ini_set('user_agent','MSIE 4\.0b2;'); // set user agent as IE browser

$txt = '';
if ($fp = fopen($url, 'r')) {
while( !feof($fp) ) {
$txt .= fread( $fp, 2082 );
}
fclose($fp);
}
return $txt;

}

?>


</body>
</html>

 

Thanks.

Link to comment
https://forums.phpfreaks.com/topic/97155-really-really-stuck-need-help/
Share on other sites

wouldn't form need to be passed to another page? <form method="get" action="otherpage.php?">

 

Yes and No...it could be done that way or through one file as well.

 

Yes, it would be easier to have multiple files to pass the information...one file have the form and the other file run the php script and to parse the form information.

 

No, you could do it all through one file by using cases and the switch function to switch to different cases through operations.

 

the latter option would be more complicated to do.

 

Either way you do it jkewlo is correct in saying that it needs to have

method="get" action="otherpage.php"

in the form tag otherwise it won't actually do anything. If you decide to learn switching between cases the action will just be the filename of the same file running the script but if you do the separate files you will need to make the action value whatever you name the php file that runs the script.

The default method is GET and the default action is "same page" so

<form>
...
</form>

 

EG

<?php
if (isset($_GET['sub']))
{
    echo $_GET['mytext'] . '<hr/>';
}                                             
?>
<form>
<input type="text" name="mytext">
<input type="submit" name="sub" value="try it">
</form>

The default method is GET and the default action is "same page" so

<form>
...
</form>

 

EG

<?php
if (isset($_GET['sub']))
{
    echo $_GET['mytext'] . '<hr/>';
}                                             
?>
<form>
<input type="text" name="mytext">
<input type="submit" name="sub" value="try it">
</form>

 

oh snap my bad...I didn't even see "isset" in his code...I thought it was trying to run a multiple file form through one file.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.