how to post login array error within the originating page - authentication

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.

Related

How to use Apis to view lines in Xtream code 2.9.2?

How to view Lines from Xtream Code CMS?
I am using some APIs but not able view lines it always shows me 'Access Denied'.
How to allow API access? I have Xtream code 2.9.2 version.
I know To use APIs, we have to import our IP address into the whitelist from General Settings -> API Settings. It was an option in Xtream code 2.3.x but in later versions, they have changed things. And by default, they have disabled the access of APIs. There is no such type of option in the current version of Xtream code we have.
Any solution? How to allow API access in xtream code 2.9.2?
<?php
$panel_url = 'https://cms.xtream-codes.com/xxxx/'; //i am giving my cms xtream code panel link here
$username = "xxxx"; //i am giving my xtream code cms username here
$password = "xxxx"; //i am giving my xtream code cms password here
##############################################################################
$post_data = array( 'username' => $username, 'password' => $password );
$opts = array( 'http' => array(
'method' => 'POST',
'header' => 'Content-type: application/x-www-form-urlencoded',
'content' => http_build_query( $post_data ) ) );
$context = stream_context_create( $opts );
$api_result = json_decode( file_get_contents( $panel_url . "api.php?action=user&sub=info", false, $context ), true );
echo implode( ',', $api_result);
?>
Access denied
Pretty sure the $panel_url refers to the URL to your main server rather than your cms panel
My solution for checking active subscription info using xtream-codes V2 API
create an Index.php page for your form
<form class="form-inline" action="submit.php" method="post">
<div class="form-group">
<input type="text" class="form-control" id="username" placeholder="Enter Lines Username" name="username">
<input type="text" class="form-control" id="password" placeholder="Enter Lines Password" name="password">
<button type="submit" id="submit" class="btn btn-primary" name="submit">GET STREAM IDS</button>
</form>
Create submit.php and point your form action to it
<?php
$surname = $_POST['surname'];
$username = $_POST['username'];
$password = $_POST['password'];
$exp_date = date("d-m-Y",$json['user_info']["exp_date"]);
$json = json_decode(file_get_contents("http://<-YOUR DNS ->:<-YOUR PORT ->/panel_api.php?username=$username&password=$password"), true);
?>
<?php echo $json['user_info']["username"];?></a>
<?php echo $json['user_info']["password"];?></a>
<?php echo $json['user_info']["status"];?></a>
<?php echo $exp_date;?></a>
and create a line download button like this
DOWNLOAD PLAYLIST
The below code will generate a table of active channels and their TS numbers dependant to the entered line subscription packages
<table>
<thead>
<tr>
<th width="50%"><center>STREAM NAME</center></th>
<th width="50%"><center>STREAM TS NUMBER</center></th>
</tr>
</thead>
<tbody>
<tr>
<?php
$username = $_POST['username'];
$password = $_POST['password'];
$json = json_decode(file_get_contents("http://<-YOUR DNS ->:<-YOUR PORT ->/player_api.php?username=$username&password=$password&action=get_live_streams"), true);
for ($x = 0; $x < count($json); $x++)
{ ?>
<td><center><strong><?php echo $json[$x]['name'];?></strong></center></td>
<td><center><strong><?php echo $json[$x]['stream_id'];?></strong></center></td>
</tr>
<?php } ?>
these may not be the best methods but they work and I actually use myself

Cro user session gets forgotten

I'm trying to learn out Cro (and Perl6 simultaneously) ;)
My study app is based on the documentation of Cro. I added some authentication which does work, but the user session gets forgotten immediately.
You can check out the code at https://gitlab.com/ecocode/beaverapp
go to the login pasge and login with "user" and "pwd". You get rerouted to / (which indicates the login succeeded), but the message there is "Current user: -". So the session gets lost.
The relevant part of Routes.pm6 :
class UserSession does Cro::HTTP::Auth {
has $.username is rw;
method logged-in() {
defined $!username;
}
}
my $routes = route {
subset LoggedIn of UserSession where *.logged-in;
get -> UserSession $s {
content 'text/html', "Current user: {$s.logged-in ?? $s.username !! '-'}";
}
get -> LoggedIn $user, 'users-only' {
content 'text/html', "Secret page just for *YOU*, $user.username()";
}
get -> 'login' {
content 'text/html', q:to/HTML/;
<form method="POST" action="/login">
<div>
Username: <input type="text" name="username" />
</div>
<div>
Password: <input type="password" name="password" />
</div>
<input type="submit" value="Log In" />
</form>
HTML
}
post -> UserSession $user, 'login' {
request-body -> (:$username, :$password, *%) {
if valid-user-pass($username, $password) {
$user.username = $username;
redirect '/', :see-other;
}
else {
content 'text/html', "Bad username/password";
}
}
}
sub valid-user-pass($username, $password) {
# Call a database or similar here
return $username eq 'user' && $password eq 'pwd';
}
}
sub routes(Beaverapp $beaverapp) is export {
route {
# Apply middleware, then delegate to the routes.
before Cro::HTTP::Session::InMemory[UserSession].new;
delegate <*> => $routes;
}
}
I think the problem is due to the middleware session management not working. How should I correct this? Or maybe the problem is due to something else?
The behavior you saw was indeed caused by a bug in cookie-treatment inside of HTTP/2 stack.
As for now, the bug is fixed and the code in OP post works.
After discussion on cro irc channel, this problem only appears when using https 2. So the code above is correct.

Upload mp3 file not working in codeigniter

I am trying to upload mp3 file into folder using codeigniter V3.1.8 but i get error when i trying to upload any .mp3 file. I got "The filetype you are attempting to upload is not allowed." error.
Here is my controller, view code.
CommonController.php
public function uploadSong( $ref_id ) {
$status = $url = "";
$data['user_info'] = $this->data;
if ($status != "error") {
$config['upload_path'] = './assets/songs/';
$url = 'assets/songs/';
}
$config['allowed_types'] = 'mp3';
$config['max_size'] = 99999;
//$config['encrypt_name'] = TRUE;
//chmod('assets/', 0777);
$this->load->library('upload', $config);
if (!$this->upload->do_upload('file_name')) {
$status = 'error';
$msg = $this->upload->display_errors('', '');
echo $msg;
} else {
// Go ahead
}
}
upload.php
<?php echo form_open_multipart(base_url() . 'upload-song/'.$song[0]['id']);?>
<div class="form-group">
<label>Select Song</label>
<input type="file" name="file_name" size="20" required="true" />
</div>
<input type="submit" class="btn btn-primary" name="submit" id="submit" value="Upload" />
<?php echo form_close(); ?>
config/mimes.php
'mp3' => array('audio/mpeg', 'audio/mpg', 'audio/mpeg3', 'audio/mp3'),
Same process do with images upload and its working fine but am not getting what's going wrong with mp3 upload. Any idea whats going wrong with my code ?
Thanks in Advance.
You just need to replace in config/mimes.php from,
'mp3' => array('audio/mpeg', 'audio/mpg', 'audio/mpeg3', 'audio/mp3'),
to,
'mp3' => array('video/mp3', 'application/octet-stream', 'audio/mpeg', 'audio/mpg', 'audio/mpeg3', 'audio/mp3'),
Now it's working fine.

asp.net MVC form POST working in Localhost but not working after publishing

HomeController.cs:
public ActionResult Index()
{
return View();
}
[HttpPost]
public ActionResult Index(LoginInfo login)
{
if (Request.Form["Submit"] != null)
{
string Username = login.Username;
string Password = login.Password;
ViewBag.Massage = "";
if (Username == "Admin" && Password == "123")
{
ViewBag.Massage = "Login Successfull";
return RedirectToAction("MSISDN","UnSub");
}
else
{
ViewBag.Massage = "Please Enter Valid Login Information";
}
}
return View();
}
Views/Home/Index.cshtml
<form name="myForm" action="/Home/Index" method="post">
<div align="center">
<div style="color:red">#ViewBag.Massage</div>
<br>
<label for="Username">Username:</label>
<input type="text" name="Username" id="Username">
<label for="Password">Password:</label>
<input type="password" name="Password" id="Password">
<br>
<input type="submit" name="Submit"value="Submit">
</div>
</form>
This code is works perfectly in my localhost. But when I publishe my project to IIS Server it is not working. It is returning -
Server Error: 404 File or Directory Not Found.
May be it conflicts with my physical path and requested path. How to resolve this problem?? :(
The action's url in the form tag may be wrong :
If the url for display and post the data is the same, you can remove action="/Home/Index"
If you want to specify the url, please use action="#Url.Action("Index")"
It will automatically resolve the Url.
My Code is working properly after using an tilde (~) sign before action.
For example:
action="~/Home/Index"
After using this sign my code works properly. It reduce the conflicts between virtual path and physical path.

Invalid Request YII when delete model via POST

I want delete my model via post , but I always get Invalid Request
this is my view
<?php
echo CHtml::link(CHtml::encode('Delete image'), array('gambar/delete', 'id' => $data->id), array(
'submit' => array('data/delete', 'id' => $data->id),
'class' => 'delete', 'confirm' => 'This will remove the image. Are you sure?'
)
);
?>
and this is my action in GambarController
public function actionDelete() {
if (Yii::app()->request->isPostRequest) {
// we only allow deletion via POST request
$this->loadModel()->delete();
if (!isset($_GET['ajax']))
$this->redirect(array('index'));
}
else
throw new CHttpException(400, 'Invalid request. Please do not repeat this request again.');
}
But I always get Invalid Request, I have read some forums, but I cannot get it. Anyone can help me ?
In most cases you can not use link (<a>) to POST. Instead, use the <form> like this
<form action="<?php echo $this->createUrl('/gambar/delete/'.$model->id);?>" method="post">
<button
type="submit"
name="id"
value="<?php echo $model->id?>"
onclick="if (!confirm('Are you sure to delete this image?')) return false;">
<i class="icon-white icon-trash"></i> Delete
</button>
</form>
You are using CHtml::link, this will generate an html <a> tag. When you click on a <a>, your browser send HTTP GET request(not POST request) to the server. So if(Yii::app()->request->isPostRequest) is always false and therefore you see Invalid request error. You should remove this condition from the action. Also, $this->loadModel()->delete() is invalid, because loadModel get an id as parameter. So $this->loadModel($_GET['id'])->delete() is correct.
Use the below code
$this->loadModel(primarykey, 'TableName')->delete();
Should work!