PHP Forums Archive

two start pages for different access levels

Tags: mail, class, smtp, access levels

andree posted on 2008-01-17 10:14:57 #

Haii olaf,
thanks all for your classs.
i am beginer in php programming.
i am using your class, but i dont know how to redirect access user class.
example : if user level = 10 go to admin.php but if user level =1 go to member.php and member can update his account to. not to deny_access.php.
one question more, i am using smtp server for mail how i can setting it. how i can configurate if i using Mail.php(pear). cause my internet service provider cannot support it with mail() function.

thanks a lot for your answer and time.
best regard andree.

Comments / discussions

Olaf posted on 2008-01-17 11:15:01 #

Hi,

create a page for your admin level (based on the example page) and use this code:

$admin = new Access_user;

$admin->access_page($_SERVER['PHP_SELF'], "", DEFAULT_ADMIN_LEVEL); 

if ($admin->get_access_level() < DEFAULT_ADMIN_LEVEL) {
    header("Location: ".START_PAGE);
    exit;
}

this should do the job

andree posted on 2008-01-24 08:15:11 #

thanks Olaf, i will try it now.
i have one question more,
how we can check if the user has/already login or not?
example : if user want to download some files, he must login first.
how i can check it..? :)

Thanks a lot for your time.
best regard,
andree.

Olaf posted on 2008-01-24 08:20:45 #

check the file "example.php", the function

$page_protect->access_page();

will check if the login is valid, if not the visitor is redirected to the login page.

Olaf posted on 2008-01-24 08:28:50 #

there is another way using a session:

if (isset($_SESSION['logged_in'])) echo 'welcome!';

andree posted on 2008-01-25 08:19:49 #

Yes its works!
thanks a lot.

I still confuse using PHPMailer,
which configurate i must change in PHPMailer folder.
for your access_class, i change it in db_config right,
am i need to change anything else?
it seem can't send email.
so I try using PEAR and it works well, how do u think olaf, its save for security?
i cut it in acces_user_class.php bellow send_mail() function.

include("Mail.php");
/* mail setup recipients, subject etc */
$recipients = "andree@whatzup-online.com";
$headers["From"] = $_POST['from'];
$headers["To"] = "andree@whatzup-online.com";
$headers["Subject"] = $_POST['subject'];
$mailmsg = $_POST['message'];
/* SMTP server name, port, user/passwd */
$smtpinfo["host"] = "mail.telkom.net.id";
$smtpinfo["port"] = "25";
$smtpinfo["auth"] = true;
$smtpinfo["username"] = "whatzup@yahoo.net.id";
$smtpinfo["password"] = "xtr3m";
/* Create the mail object using the Mail::factory method */
$mail_object =& Mail::factory("smtp", $smtpinfo);
/* Ok send mail */
$mailsent = $mail_object->send($recipients, $headers, $mailmsg);

for all the time being, thanks.
andree

Olaf posted on 2008-01-25 08:41:00 #

Andree,

you need to check that your mail script safe against mail header injections.

what I don't understand, is it possible to use phpmailer on your server or not?

you know about the last update where it's possible to use phpmailer as mail script?

andree posted on 2008-01-25 09:40:45 #

okey,
how if my server cannot allow to using phpmailer?

i just change in this script right:
define("USE_PHP_MAILER", false); // true = use phpmailer
define("PHP_MAILER_SMTP", true); // true send by SMTP, false = senmail

sory, if i can explain it better co'z my poor english.
where is the last update i can find.?

Thanks.

Olaf posted on 2008-01-25 09:50:54 #

Hi,

with the pear script the mail is send via SMTP, the same way how it's possible with phpmailer.

Just download the latest AU class version and check the instructions here:

andree posted on 2008-01-25 10:02:42 #

okey olaf,
i already update the latest au class.
so i don't need configuration for PHPMailer,
i just extract them into classes folder, isn't it?

best regards, andree.

Olaf posted on 2008-01-25 10:10:08 #

yes right, you need only to change the path to your phpmailer class folder/file

andree posted on 2008-01-25 11:00:23 #

i try it and work fine,
the message says "Please check your e-mail and follow the instructions."
But i not receive email activation, the record has already insert to database, and there is no error warning.

i using your au class ver 1.98 now, before it i using ver 1.94
i think i will try with PEAR again instead PHPMailer.
or i will try it later.

one more question please,
i try to add 2 fields in table users, which file i must modified?
is just access_user_class.php or there is another ?

sory to bother u again,
thanks a lot,
andree

Olaf posted on 2008-01-25 11:10:24 #

one more question please,
i try to add 2 fields in table users, which file i must modified?
is just access_user_class.php or there is another ?

Please start a new thread (this would be the third subject for this thread)...

about the mail thing, check the method I have created for phpmailer, if you use the pear class the same way it should be fine...

andree posted on 2008-01-25 11:19:48 #

okey olaf.
thanks a lot for your time.
it's realy big help!,
i will sure to try phpmailer again latter,

please ask me if u need suport for your forum/vote or something.
i will pleasure to suport it.

best regard,
andree.

Olaf posted on 2008-01-25 11:29:52 #

something else; you can use phpmailer in debugging mode, this way you get more information about what's wrong, add this row to the send_mail method in AU:

$mail->SMTPDebug = true; below the row with the code $mail->IsSMTP();

sure you need to send the the mail in smtp mode with this options:

define("USE_PHP_MAILER", true); // true = use phpmailer
define("PHP_MAILER_SMTP", true); // true send by SMTP, false = sendmail

andree posted on 2008-01-25 11:44:12 #

ok, i will try it.
i read phpmailer installation now,
i don't need to configurate php.ini file for phpmailer installion, right?
or maybe my server mail host was busy.

thanks, andree.

Olaf posted on 2008-01-25 11:46:19 #

"ok, i will try it.
i read phpmailer installation now,
i don't need to configurate php.ini file for phpmailer installion, right?
or maybe my server mail host was busy.
thanks, andree."
andree

No, never changed something in my php.ini, all the mails are send on your web server. Just be sure that you use the right SMTP settings.

andree posted on 2008-01-25 12:02:00 #

Thanks olaf,

i already try using PEAR and it work well,
the activation mail can sent to my outlook mail,

but i will try using PHPMailer in debugging mode as your sugestions,
perhaps it will resolving this problem and error will be revealed.

best regard, andree.

andree posted on 2008-01-28 08:28:16 #

hi olaf,
i have try with debugging mode.

mail->SMTPDebug = true; add this in au class
define("USE_PHP_MAILER", true); // add this in dbconfig
define("PHP_MAILER_SMTP", true); // add this in dbconfig

it works !!
but if the connection to long/slow it will be blank white page.
it's seems the proses to heavy.

it's okey..?

andree posted on 2008-01-28 08:39:15 #

sometimes give this error ?

Warning: fsockopen() [function.fsockopen]: unable to connect to mail.nitu.net.id:25
(A connection attempt failed because the connected party did not properly respond after a period of time,
or established connection failed because connected host has failed to respond. )
in C:\Program Files\xampp\htdocs\classes\PHPMailer\class.smtp.php on line 122

any suggestion ?

thank, andree

Olaf posted on 2008-01-28 08:41:04 #

Hi Andree,

I think your mail server is too busy or has a slow connection, if possible have try a different one. This is not related to the code.

andree posted on 2008-01-28 08:51:56 #

Yes u are right olaf,
everything is work well now
thanks a lot for all u suggestion.

i start new tread now :)