ricerocket Posted March 20, 2008 Share Posted March 20, 2008 I'm having trouble with a script of mine and I was wandering if someone could take a quick look and tell me if they see anything. The error I'm getting is: Fatal error: Cannot redeclare http_request() in /home/user/public_html/tb/process.php on line 34 And the script is below: <!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.'"a='.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> Link to comment https://forums.phpfreaks.com/topic/97028-having-problem-with-a-script-cannot-redeclare-http_request/ Share on other sites More sharing options...
Jeremysr Posted March 20, 2008 Share Posted March 20, 2008 http_request() is a built-in PHP function, you aren't allowed to make a function with the same name. Link to comment https://forums.phpfreaks.com/topic/97028-having-problem-with-a-script-cannot-redeclare-http_request/#findComment-496535 Share on other sites More sharing options...
ricerocket Posted March 20, 2008 Author Share Posted March 20, 2008 hmm. I see. It's just strange because about 3 months ago I was using it and it was working and everything and now a friend wanted to know if I still had it but I didn't so I went back to the site I got it from and it was teh exact same script and everything but now it won't work on my site and keeps giving the same error. What would you suggest is wrong? Or how I can fix? Link to comment https://forums.phpfreaks.com/topic/97028-having-problem-with-a-script-cannot-redeclare-http_request/#findComment-496539 Share on other sites More sharing options...
Jeremysr Posted March 20, 2008 Share Posted March 20, 2008 It's a PHP extension, so it might not come with some installations of PHP, or it might not come with older versions of PHP. To fix it just choose a different function name for you function. Link to comment https://forums.phpfreaks.com/topic/97028-having-problem-with-a-script-cannot-redeclare-http_request/#findComment-496540 Share on other sites More sharing options...
ricerocket Posted March 20, 2008 Author Share Posted March 20, 2008 But my server is the same and my PHP version is the same and everything is the same as it was a couple months ago when I had the script. And I don't know how to change it because I need it to make an http request, and I don't know of any other ways to do that beside http_request($url); Link to comment https://forums.phpfreaks.com/topic/97028-having-problem-with-a-script-cannot-redeclare-http_request/#findComment-496541 Share on other sites More sharing options...
Jeremysr Posted March 20, 2008 Share Posted March 20, 2008 Just change function http_request($url) { to function my_http_request($url) { and change $txt = http_request( $url ); to $txt = my_http_request( $url ); Link to comment https://forums.phpfreaks.com/topic/97028-having-problem-with-a-script-cannot-redeclare-http_request/#findComment-496543 Share on other sites More sharing options...
ricerocket Posted March 20, 2008 Author Share Posted March 20, 2008 cool thanks it works now. =) Link to comment https://forums.phpfreaks.com/topic/97028-having-problem-with-a-script-cannot-redeclare-http_request/#findComment-496546 Share on other sites More sharing options...
ricerocket Posted March 20, 2008 Author Share Posted March 20, 2008 Shoot! Now I have another question... ??? How can I make this script take a cvs file of emails and passwords and then create accounts with that information? Is there any simple say to request a cvs file? Link to comment https://forums.phpfreaks.com/topic/97028-having-problem-with-a-script-cannot-redeclare-http_request/#findComment-496548 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.