Session variables don't get passed to the third page after session start - session-variables

after starting a new session in my login.php i rediredct to home.php and load session variables successfully.But when i try to open menu.php from home.php and use session variables , those same variables are unndefined now. I echoed the session id after both page changes and its exactly the same. So can anyone please tell me why am i losing these variables?
login.php:
session_start();
$_SESSION["user"]=$puser;
$_SESSION["loggedin"]=true;
echo "<script>window.open('../home.php','_self')</script>";
?>
home.php
require("php/objects.php");
session_start();
if(isset($_SESSION["loggedin"]) && $_SESSION["loggedin"]==true)
{
$user=$_SESSION["user"];
$_SESSION["loggedin"]=true;
echo session_id();
echo $_SESSION["loggedin"];
}
else
{
echo "Login Error";
echo "<script>window.open('default.html','_self')</script>";
exit();
}``
?>
menu.php
require("objects.php");
session_start();
echo session_id();
echo $_SESSION["loggedin"];
/*if(isset($_SESSION["loggedin"]) && $_SESSION["loggedin"]==true)
{
$user=$_SESSION["user"];
$utype=isset($user->salary)?"staff":"client";
}
else
{
echo "Login Error";
echo "<script>window.open('../default.html','_self')</script>";
exit();
}*/``
?>
when i click a link in home.php with href=menu.php i get an error that index loggedin is undefined

I don't know what is in your objects.php, calling session should probably come before that.
session_start();
require("objects.php");
echo session_id();
echo $_SESSION["loggedin"];

Related

how to post login array error within the originating page

Hi how do you post the login error message within the originating page where the user was attempting to login ?
Below I was able to stay on the current page if user login successfully but for login error it will obviously just go to the logonprocess page and display the error message.
Sorry that I remove a lot of validation below as the codes can really be very long.
Index.php
<?php
//set the session cookie parameter
ini_set("session.save_path", "sessionData");
session_start();
?>
<?php
if (!isset($_SESSION['uName'])) { ?>
<form method="post" action="logonProcess.php">
<div>Username <input type="text" name="userName" placeholder="Username"></div>
<div>Password <input type="password" name="pwd" placeholder="Password"></div>
<div><input type="submit" value="Logon"></div>
</form>
<?php } else { }?>
<?php
if (isset($_SESSION['uName'])) {
$username = $_SESSION['uName'];
echo "<p>Welcome $username</p>\n";
?>
Logout</br></br>
LogonProcess.php
$loginerror = array();
if (empty($username)) {
$loginerror[] = "You have not entered all of the required fields";
}
elseif (strlen($passWD) < 8) {
$loginerror[] = "You have not entered all of the required fields";
}
if (!empty($loginerror))
for ($a=0;$a<count($loginerror);$a++)
{
echo "$loginerror[$a] <br />\n";
}
else
if (mysqli_stmt_fetch($stmt))
{
if (password_verify($passWD, $passWDHash))
{
$_SESSION['uName'] = $username;
echo "<p>Login successful</p>";
header('Location: ' . $_SERVER['HTTP_REFERER']);
}
else
{
echo "<p>Please try to login again</p>";
}
why dont you put ur login error in $_SESSION["login_error"] and check in ur origin page if the session exits show the error then destroy the session after it.

how to send an HTML content via php mail()

I am trying to send an HTML e-mail using this code but all i am getting is FALSE from the mail() function.
The error_log is empty.
Can someone tell me why mail() is not working?
$message = '<html><body>';
$message .= '<table rules="all" style="border-color: #666;" cellpadding="10">';
$message .= "<tr style='background: #eee;'><td><strong>Name:</strong> </td><td>SDFSDF</td></tr>";
$message .= "<tr><td><strong>Email:</strong> </td><td>VXCVSDF</td></tr>";
$message .= "</table>";
$message .= "</body></html>";
$to = 'my_mail#gmail.com';
$subject = 'Website Change Reqest';
$headers = "From: USER NAME"."\r\n";
$headers .= "Reply-To: USER EMAIL"."\r\n";
$headers .= "MIME-Version: 1.0"."\r\n";
$headers .= "Content-Type: text/html; charset=ISO-8859-1"."\r\n";
if (mail($to, $subject, $message, $headers)) {
echo 'Your message has been sent.';
} else {
echo 'There was a problem sending the email.';
}
It's hard to debug PHP mail() function.
After checking your script, I can confirm that your code is working fine. It's something with your server or/and PHP configuration.
Start with this little snippet to see what is happening:
error_reporting(E_ALL);
ini_set('display_errors', -1);
echo '<br>I am : ' . `whoami`.'<br>';
$result = mail('myaddress#mydomain.com','This is the test','This is a test.');
echo '<hr>Result was: ' . ( $result === FALSE ? 'FALSE' : 'TRUE') . ' ('. $result. ')';
echo '<hr>';
echo phpinfo();
After output, check your sendmail_path, in most case sendmail_path uses sendmail MTA:
/usr/sbin/sendmail -t -i
Edit your php.ini file, set the following and don't forget to restart httpd server:
sendmail_path = /usr/sbin/sendmail -t -i
Check log files at /var/log/maillog, it could really help you to solve the problem.
If you still have a problem, just take a good look at PHPMailer, SwiftMailer, PEAR's Mail or Zend Framework's Zend_Mail an excellent, comprehensive, modern PHP mailing library. It will be easy to debug your problem after all.
You can using phpmailer for this way!
https://code.google.com/a/apache-extras.org/p/phpmailer/
Hope this help!

Flash Message in YII Framework

After I send the request, I will announce the result to the user via SET FLASH. What is the way to show a message when the user sends a request?
For example when sending a message form : Display -> form is being send and then a flash message is displayed
Check the wiki on the Yii framework website:
http://www.yiiframework.com/wiki/21/how-to-work-with-flash-messages/
In your controller you can put:
Yii::app()->user->setFlash('success', "Form posted!");
In your view you can echo the flash message by:
<?php echo Yii::app()->user->getFlash('success'); ?>
Optionally you can check if a flash message exists by using the hasFlash method, so the code in your view would look like this:
<?php if(Yii::app()->user->hasFlash('success')):?>
<?php echo Yii::app()->user->getFlash('success'); ?>
<?php endif; ?>
Add setFlash in your controller. Something like this:
if($comment->save())
{
Yii::app()->user->setFlash('commentSubmitted','Thank you for your comment.');
$this->refresh();
}
And in your views, display flash message something like this:
<?php if(Yii::app()->user->hasFlash('commentSubmitted')): ?>
<div class="flash-success">
<?php echo Yii::app()->user->getFlash('commentSubmitted'); ?>
</div>
<?php endif; ?>
In your controller you can put:
if(conditions)
Yii::app()->user->setFlash('success', "Success text");
else
Yii::app()->user->setFlash('error', "Error text");
In your view you can echo the flash message by:
<?php
if(Yii::app()->user->hasFlash('success'))
Yii::app()->user->setFlash('success', '<strong>Well done!</strong> '.Yii::app()->user->getFlash('success').'.');
else
Yii::app()->user->setFlash('error', '<strong>Error!</strong> '.Yii::app()->user->getFlash('error').'.');
$this->widget('bootstrap.widgets.TbAlert', array(
'block'=>true, // display a larger alert block?
'fade'=>true, // use transitions?
'closeText'=>'×', // close link text - if set to false, no close link is displayed
'alerts'=>array( // configurations per alert type
'success'=>array('block'=>true, 'fade'=>true, 'closeText'=>'×'), // success, info, warning, error or danger
),
)); ?>

Disable notice yii

How disable notice , i try in idex.php But Notice is echo , how i can disable this .
<?
define("YII_ENBLE_ERROR_HANDLER",false)
define("YII_ENBLE_EXCEPTION_HANDLER",false)
?>
in php.ini
<?display_errors = off ?>
Update public/index.php
<?php
define('YII_ENABLE_ERROR_HANDLER', false);
define('YII_ENABLE_EXCEPTION_HANDLER', false);
// Turn off all error reporting
// error_reporting(0);
// Report all errors except E_NOTICE
// This is the default value set in php.ini
error_reporting(E_ALL ^ E_NOTICE);

Joomla User login check

First I am not a joomla developer. My friend has a web site created with joomla 1.5. In webroot there are some joomla files. I created a directory in webroot "mydirectory" and i have an index file in this directory. I try to access joomla's user info in this page i grab the user object but it doesn't work.
//i included joomla core files
$user =& JFactory::getUser();
if ($user->get('guest')) {
echo 'guest';
} else {
echo 'not guest';
}
when I log in to my account, it says 'guest' again.
Also, I can't find anything in Joomla's session class.
$session =& JFactory::getSession();
Thanks
You should do this:
$user =& JFactory::getUser();
if (!$user->guest) {
echo 'You are logged in as:<br />';
echo 'User name: ' . $user->username . '<br />';
echo 'Real name: ' . $user->name . '<br />';
echo 'User ID : ' . $user->id . '<br />';
}
This is from here: http://docs.joomla.org/JFactory/getUser
Try print_r($user) to see what items you are getting back.
Try to check for $user->id
See if you are missing including any file e.g. framework.php