View Full Version : PHP question
Hyper X 12-21-2007, 01:10 AM Hey guys i am wanting to create a script for my web site where when users login but i wanted the page the login script takes you to display different things depending on what user logged in.
for example users see a different pages to admins i was wondering if the was possible or whether 2 login scripts would have to be made.
also i wanted to make an account panel page for my web hosting site that allowed users to login and see information about their hosting accounts. The software would be CPanel.
thanks in advance guys.
Also if it helps i am using MySQL 5.0, IIS7 and PHP5.
Hyper X 12-21-2007, 01:41 AM And also for another web site i am doing selling Hardware i have a form to enter data in a MySQL DB but i dont know how to Get that data from DB to my Products page. i would have put this at the buttom of my post but i just remember and VBulletin wont let me edit my post twice for some reason.
Hey guys i am wanting to create a script for my web site where when users login but i wanted the page the login script takes you to display different things depending on what user logged in.
for example users see a different pages to admins i was wondering if the was possible or whether 2 login scripts would have to be made.
Sounds like you need to plan some things out, or at the very least provide more information. You could go about this numerous ways depending on the data you want to display, and how unique that data is on a per user level.
If you just want static pages to display based on the user you can easily construct a script that will redirect.
If you have dynamic data you would probably want to house this data in a db and use queries designed around the user.
You also need to keep in mind how valuable the data you're displaying is and what type of security is needed.
Hyper X 12-21-2007, 04:49 AM Well the Data would be their CPanel info such as bandwidth usage ect..
Their Plan that they have with me
and i know what to do for Admin page after the login but i was wondering if the login script could redirect based on which user logged in.
i am currently storing data in a MySQL Database on my own servers and am currently in the process of building my home site.
So it would be fair unique per user.
I am Still a bit new to PHP and havent been able to find an answer.
I hope this is a little more information.
Thanks for the Reply
Hyper X 12-21-2007, 11:18 AM Besides my little PHP issue i am still having does anyone know of an ASP script that can check the status of a windows service and also has the ability to stop/start/restart it.
Help is Appreciated
servergoods 12-21-2007, 12:28 PM just check the user login as admin or user, then use if and else to redirect, simple and easy
Hyper X 12-21-2007, 06:39 PM Thanks for the replies i really appreciate i now have a solution for that.
Now i am only looking for 2 more things.
1. Is there a script either ASP or CGI/Perl that can check the status of a windows service and be able to start, restart or stop it from a web interface?
2. Is there a way to make a script for my account panel section that displays their CPanel bandwidth usage and other such info?
I have spent about a day searching and havent found any online.
Thanks for the replies i really appreciate i now have a solution for that.
Now i am only looking for 2 more things.
1. Is there a script either ASP or CGI/Perl that can check the status of a windows service and be able to start, restart or stop it from a web interface?
Here is a perl script I found on google, http://techtasks.com/code/viewbookcode/585. You'll probably need to adapt it to your needs but the core functionality is certainly there.
# This code stops and starts (effectively restarts) a service.
# ---------------------------------------------------------------
# Adapted from VBScript code contained in the book:
# "Windows Server Cookbook" by Robbie Allen
# ISBN: 0-596-00633-0
# ---------------------------------------------------------------
use Win32::OLE;
$Win32::OLE::Warn = 3;
# ------ SCRIPT CONFIGURATION ------
$strComputer = '<ServerName>';# e.g. fs-rtp01 (use . for local server)
$strSvcName = '<ServiceName>';# e.g. dnscache
# ------ END CONFIGURATION ---------
$objWMI = Win32::OLE->GetObject('winmgmts:\\\\' . $strComputer . '\\root\\cimv2');
$objService = $objWMI->Get('Win32_Service.Name=\'' . $strSvcName . '\'');
$intRC = $objService->StopService;
sleep 5;
# Give the service 5 seconds to stop
if ($intRC > 0) {
print 'Error stopping service: ' . $intRC, "\n";
}
else {
print "Successfully stopped service\n";
}
$intRC = $objService->StartService;
if ($intRC > 0) {
print 'Error starting service: ' . $intRC, "\n";
}
else {
print "Successfully started service\n";
}
2. Is there a way to make a script for my account panel section that displays their CPanel bandwidth usage and other such info?
WHM? Main >> Account Information >> View Bandwidth Usage
Hyper X 12-21-2007, 10:53 PM WHM? Main >> Account Information >> View Bandwidth Usage
But is there a way to make that information show up when my customers login to their accounts on my main website?.
cause i am making an area where they can see their bandwidth and disk usage and purchase an upgrade from that area. amongst been able to do other account related things.
and thanks for that Perl script its really appreciated.
futhey 12-21-2007, 11:46 PM If you want your users to have dynamic pages when they login to your website, based on what type of user they are, the easiest method is to add a simple, tinyint row in your mysql DB called "type" or something like that.
Then, when you do your mysql_query for the login, you'll just need to do a mysql_fetch_row to get the user 'type'.
Then, you would make a 'case' for different user types and the .php page it redirected to.
For the best integration, you would need to integrate this with your registration script, so that if a customer signed up for x type of account, it inserted the information into your database accordingly.
Hope this helps. If I have misunderstood your question, please explain so.
Thanks,
James
futhey 12-21-2007, 11:50 PM One more thing I forgot: Most cPanel setups include Webalizer stats, in your /home/username/tmp/webalizer directory. You could include them in a .php file or copy the files to another directory and show them as stats. Then this could be put on a daily cronjob, and you'd have stats from your custom control panel.
Although Webalizer Stats are not the most advanced and you may change your mind about using them, it is the quickest solution.
Hope this helps,
James
But is there a way to make that information show up when my customers login to their accounts on my main website?.
cause i am making an area where they can see their bandwidth and disk usage and purchase an upgrade from that area. amongst been able to do other account related things.
and thanks for that Perl script its really appreciated.
I believe customers have access to bandmin, you should probably look to interface with bandmin or vnstat and integrate it into cpanel
Hyper X 12-22-2007, 05:22 AM Here is a perl script I found on google, http://techtasks.com/code/viewbookcode/585. You'll probably need to adapt it to your needs but the core functionality is certainly there.
# This code stops and starts (effectively restarts) a service.
# ---------------------------------------------------------------
# Adapted from VBScript code contained in the book:
# "Windows Server Cookbook" by Robbie Allen
# ISBN: 0-596-00633-0
# ---------------------------------------------------------------
use Win32::OLE;
$Win32::OLE::Warn = 3;
# ------ SCRIPT CONFIGURATION ------
$strComputer = '<ServerName>';# e.g. fs-rtp01 (use . for local server)
$strSvcName = '<ServiceName>';# e.g. dnscache
# ------ END CONFIGURATION ---------
$objWMI = Win32::OLE->GetObject('winmgmts:\\\\' . $strComputer . '\\root\\cimv2');
$objService = $objWMI->Get('Win32_Service.Name=\'' . $strSvcName . '\'');
$intRC = $objService->StopService;
sleep 5;
# Give the service 5 seconds to stop
if ($intRC > 0) {
print 'Error stopping service: ' . $intRC, "\n";
}
else {
print "Successfully stopped service\n";
}
$intRC = $objService->StartService;
if ($intRC > 0) {
print 'Error starting service: ' . $intRC, "\n";
}
else {
print "Successfully started service\n";
}
WHM? Main >> Account Information >> View Bandwidth Usage
I am having a problem when i run this script in IIS7 i recieve an error like this.
HTTP Error 502.2 - Bad Gateway
The specified CGI application misbehaved by not returning a complete set of HTTP headers. The headers it did return are "".
futhey 12-22-2007, 05:29 AM The service probably shut down before it was able to execute fully. Isn't that the usual cause of the 502.2 error?
On a second note, have you configured this script? I believe the <servername> part is meant to be replaced as part of the configuration of the script (Other Users, Correct me if I'm wrong)
Hyper X 12-22-2007, 06:19 AM This is my Configuration
# This code stops and starts (effectively restarts) a service.
# ---------------------------------------------------------------
# Adapted from VBScript code contained in the book:
# "Windows Server Cookbook" by Robbie Allen
# ISBN: 0-596-00633-0
# ---------------------------------------------------------------
use Win32::OLE;
$Win32::OLE::Warn = 3;
# ------ SCRIPT CONFIGURATION ------
$strComputer = '<localhost>';# e.g. fs-rtp01 (use . for local server)
$strSvcName = '<inetsrv>';# e.g. dnscache
# ------ END CONFIGURATION ---------
$objWMI = Win32::OLE->GetObject('winmgmts:\\\\' . $strComputer . '\\root\\cimv2');
$objService = $objWMI->Get('Win32_Service.Name=\'' . $strSvcName . '\'');
$intRC = $objService->StopService;
sleep 5;
# Give the service 5 seconds to stop
if ($intRC > 0) {
print 'Error stopping service: ' . $intRC, "\n";
}
else {
print "Successfully stopped service\n";
}
$intRC = $objService->StartService;
if ($intRC > 0) {
print 'Error starting service: ' . $intRC, "\n";
}
else {
print "Successfully started service\n";
}
the service name might be wrong. But i dont know what other name would be for IIS.
can this script be use as a stand alone page which is executed by pressing a form button.
i am currently running it standalone.
This is my Configuration
# This code stops and starts (effectively restarts) a service.
# ---------------------------------------------------------------
# Adapted from VBScript code contained in the book:
# "Windows Server Cookbook" by Robbie Allen
# ISBN: 0-596-00633-0
# ---------------------------------------------------------------
use Win32::OLE;
$Win32::OLE::Warn = 3;
# ------ SCRIPT CONFIGURATION ------
$strComputer = '<localhost>';# e.g. fs-rtp01 (use . for local server)
$strSvcName = '<inetsrv>';# e.g. dnscache
# ------ END CONFIGURATION ---------
$objWMI = Win32::OLE->GetObject('winmgmts:\\\\' . $strComputer . '\\root\\cimv2');
$objService = $objWMI->Get('Win32_Service.Name=\'' . $strSvcName . '\'');
$intRC = $objService->StopService;
sleep 5;
# Give the service 5 seconds to stop
if ($intRC > 0) {
print 'Error stopping service: ' . $intRC, "\n";
}
else {
print "Successfully stopped service\n";
}
$intRC = $objService->StartService;
if ($intRC > 0) {
print 'Error starting service: ' . $intRC, "\n";
}
else {
print "Successfully started service\n";
}
the service name might be wrong. But i dont know what other name would be for IIS.
can this script be use as a stand alone page which is executed by pressing a form button.
i am currently running it standalone.
This script in its current state is likely to be used on a command line such as "C:\Perl script_name.pl" opposed to calling on it from a browser. Your 502 error is caused because this script isn't sending any headers.
According to IIS error codes, 502.2 is "Error in CGI application."
now you could add the following information to the script to get it to send headers:
print "Content-type: text/html\n\n";
or even better:
use CGI qw(:standard);
header;
|