Need Help inMultiple action - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

Need Help inMultiple action

KsamysksundarKsamysksundar Posts: 22Member
I trying to create a login from using php.
What i am doing is
If the username and passwords are invalid i am reloading the page with error message. If username and password are correct I have to send them to a new page.

The code model like
<?
if($submitted==false)//Submitted is hidden field
{
echo "<form action=samefilename>";//Self posting
//Display Header images and menus....
In the middle of the page if(strlen($Errmsg)>0) echo $Errmsg;//hidden field




}
else{
Check User name and password;
if it is wrong {
$Errmsg="Invalid password";
include("samefile"); //It is working properly problem is
in below part
}
else{
//i want to call or load another file with that name
like include("samefile.php?uname=".$txtusername);
But it is showing error
" Unable to open samefile.php?uname=heaven";
I am doing with that using java script

window.location="samfile.php?uname".$txtusername
anyhow i am calling but when i am clicking back button of browser it is again checking username password again reloading the file with username.

So before entering i deleted $txtusername='' like , but it is still there it is giving headache for me.

Please any one help me in brief manner. I am newbie for php

The main question is i want to load one php file with argument like
filename?uname=programmer
Not in <a href
Not in <form action
Where ever i want

thanks for U


Comments

  • Mr. EgoMr. Ego Posts: 38Member
    : I trying to create a login from using php.
    : What i am doing is
    : If the username and passwords are invalid i am reloading the page with error message. If username and password are correct I have to send them to a new page.
    :
    : The code model like
    : <?
    : if($submitted==false)//Submitted is hidden field
    : {
    : echo "<form action=samefilename>";//Self posting
    : //Display Header images and menus....
    : In the middle of the page if(strlen($Errmsg)>0) echo $Errmsg;//hidden field
    :
    :
    :
    :
    : }
    : else{
    : Check User name and password;
    : if it is wrong {
    : $Errmsg="Invalid password";
    : include("samefile"); //It is working properly problem is
    : in below part
    : }
    : else{
    : //i want to call or load another file with that name
    : like include("samefile.php?uname=".$txtusername);
    : But it is showing error
    : " Unable to open samefile.php?uname=heaven";
    : I am doing with that using java script
    :
    : window.location="samfile.php?uname".$txtusername
    : anyhow i am calling but when i am clicking back button of browser it is again checking username password again reloading the file with username.
    :
    : So before entering i deleted $txtusername='' like , but it is still there it is giving headache for me.
    :
    : Please any one help me in brief manner. I am newbie for php
    :
    : The main question is i want to load one php file with argument like
    : filename?uname=programmer
    : Not in <a href
    : Not in <form action
    : Where ever i want
    :
    : thanks for U
    :
    :
    :

    Hello,
    for logging to a site is very good (and maybe the only one right) solution - SESSIONS. There can be several variables registered in one session - session variables. When browser accesses these pages he sends an session id to server (don't know exactly how, but it doesn't matter). Session variables are located on the server, and sessions are identified by its ids. It is ood idea to look into PHP manual for sessions. You can access session variable via $SESSION["variable_name"] (maybe it is $_SESSION I'm not sure now). When the variable doesn't exist and you want to write into it, new session variable is created. You need to place [b]session_start();[/b] on start of your script. Read the php manual for more details.
    About the file you want to include, it's quite easy: you wrote [italic]include("samefile.php?uname=".$txtusername);[/italic], but it looks fo file with name [b]"[/b]samefile.php?uname=$txtusername[b]"[/b]. You should write [italic]include ($txtusername)[/italic] or sth similar.
    Maybe one thing: You use JavaScript, but i think it is better to send the new address in data header with function [italic]header("Location: http://www.myaddress.com/myfile?parameter=value");[/italic]. You [b]HAVE TO use this function BEFORE any HTML data are sended to browser[/b].
    And the second thing: It isn't good dea to store information about logging in in hidden array. User can edit HTML sourcecode of sended page and there set the variable to [b]true[/b]. (Very easy, isn't?) This information should be in session variable, too.
    And the third and maybe last thing: Have you heard about using $_POST and $_GET arrays for getting informations from forms and parameters? IT IS VERY GOOD IDEA to use it. In our script (and on your server), there is a global variable for each field of form of parameter created. But you don't know where the variable came from. This can be dangerous, because somebody can try luck and write address [italic]www.youserver.com/yourpage.php?submitted=true[/italic]. What happens? A variable [italic]$submitted[/italic] will be created, so he can walk trough login page without password. It's terrible and very very dangerous, isn't it?
    When I learned PHP I have done some project with these capabilities, I had a few nightmares from this. So don't worry and for more informations read the PHP documentation on http://www.php.net .
    Have fun


  • KsamysksundarKsamysksundar Posts: 22Member
    : : I trying to create a login from using php.
    : : What i am doing is
    : : If the username and passwords are invalid i am reloading the page with error message. If username and password are correct I have to send them to a new page.
    : :
    : : The code model like
    : : <?
    : : if($submitted==false)//Submitted is hidden field
    : : {
    : : echo "<form action=samefilename>";//Self posting
    : : //Display Header images and menus....
    : : In the middle of the page if(strlen($Errmsg)>0) echo $Errmsg;//hidden field
    : :
    : :
    : :
    : :
    : : }
    : : else{
    : : Check User name and password;
    : : if it is wrong {
    : : $Errmsg="Invalid password";
    : : include("samefile"); //It is working properly problem is
    : : in below part
    : : }
    : : else{
    : : //i want to call or load another file with that name
    : : like include("samefile.php?uname=".$txtusername);
    : : But it is showing error
    : : " Unable to open samefile.php?uname=heaven";
    : : I am doing with that using java script
    : :
    : : window.location="samfile.php?uname".$txtusername
    : : anyhow i am calling but when i am clicking back button of browser it is again checking username password again reloading the file with username.
    : :
    : : So before entering i deleted $txtusername='' like , but it is still there it is giving headache for me.
    : :
    : : Please any one help me in brief manner. I am newbie for php
    : :
    : : The main question is i want to load one php file with argument like
    : : filename?uname=programmer
    : : Not in <a href
    : : Not in <form action
    : : Where ever i want
    : :
    : : thanks for U
    : :
    : :
    : :
    :
    : Hello,
    : for logging to a site is very good (and maybe the only one right) solution - SESSIONS. There can be several variables registered in one session - session variables. When browser accesses these pages he sends an session id to server (don't know exactly how, but it doesn't matter). Session variables are located on the server, and sessions are identified by its ids. It is ood idea to look into PHP manual for sessions. You can access session variable via $SESSION["variable_name"] (maybe it is $_SESSION I'm not sure now). When the variable doesn't exist and you want to write into it, new session variable is created. You need to place [b]session_start();[/b] on start of your script. Read the php manual for more details.
    : About the file you want to include, it's quite easy: you wrote [italic]include("samefile.php?uname=".$txtusername);[/italic], but it looks fo file with name [b]"[/b]samefile.php?uname=$txtusername[b]"[/b]. You should write [italic]include ($txtusername)[/italic] or sth similar.
    : Maybe one thing: You use JavaScript, but i think it is better to send the new address in data header with function [italic]header("Location: http://www.myaddress.com/myfile?parameter=value");[/italic]. You [b]HAVE TO use this function BEFORE any HTML data are sended to browser[/b].
    : And the second thing: It isn't good dea to store information about logging in in hidden array. User can edit HTML sourcecode of sended page and there set the variable to [b]true[/b]. (Very easy, isn't?) This information should be in session variable, too.
    : And the third and maybe last thing: Have you heard about using $_POST and $_GET arrays for getting informations from forms and parameters? IT IS VERY GOOD IDEA to use it. In our script (and on your server), there is a global variable for each field of form of parameter created. But you don't know where the variable came from. This can be dangerous, because somebody can try luck and write address [italic]www.youserver.com/yourpage.php?submitted=true[/italic]. What happens? A variable [italic]$submitted[/italic] will be created, so he can walk trough login page without password. It's terrible and very very dangerous, isn't it?
    : When I learned PHP I have done some project with these capabilities, I had a few nightmares from this. So don't worry and for more informations read the PHP documentation on http://www.php.net .
    : Have fun
    :
    :
    :

    ThankU Mr Ego
    Thanks for your proper guidence. header function is working properly
    This is what i need.
    Please tell me the original function of header(). My friend told me that some other argument is also there. will you? plz
    I am doing like this .
    if the entered password and username is correct i am creating session (using mysql) i am passing session id with username. There in the new form i am checking the session id is there are not . If it is there is he admin or others ..like that i am doing operaion
    Is there anyway to break up this?

    And one more help How to destroy session if the user close browser directly without logging out how to check with time. I read in book but i am not getting

    And one more help Dont take me a headache. How to use _post _get methods when i am using i didnt receive anything from that

    Thanks for U........

  • Mr. EgoMr. Ego Posts: 38Member
    : : : I trying to create a login from using php.
    : : : What i am doing is
    : : : If the username and passwords are invalid i am reloading the page with error message. If username and password are correct I have to send them to a new page.
    : : :
    : : : The code model like
    : : : <?
    : : : if($submitted==false)//Submitted is hidden field
    : : : {
    : : : echo "<form action=samefilename>";//Self posting
    : : : //Display Header images and menus....
    : : : In the middle of the page if(strlen($Errmsg)>0) echo $Errmsg;//hidden field
    : : :
    : : :
    : : :
    : : :
    : : : }
    : : : else{
    : : : Check User name and password;
    : : : if it is wrong {
    : : : $Errmsg="Invalid password";
    : : : include("samefile"); //It is working properly problem is
    : : : in below part
    : : : }
    : : : else{
    : : : //i want to call or load another file with that name
    : : : like include("samefile.php?uname=".$txtusername);
    : : : But it is showing error
    : : : " Unable to open samefile.php?uname=heaven";
    : : : I am doing with that using java script
    : : :
    : : : window.location="samfile.php?uname".$txtusername
    : : : anyhow i am calling but when i am clicking back button of browser it is again checking username password again reloading the file with username.
    : : :
    : : : So before entering i deleted $txtusername='' like , but it is still there it is giving headache for me.
    : : :
    : : : Please any one help me in brief manner. I am newbie for php
    : : :
    : : : The main question is i want to load one php file with argument like
    : : : filename?uname=programmer
    : : : Not in <a href
    : : : Not in <form action
    : : : Where ever i want
    : : :
    : : : thanks for U
    : : :
    : : :
    : : :
    : :
    : : Hello,
    : : for logging to a site is very good (and maybe the only one right) solution - SESSIONS. There can be several variables registered in one session - session variables. When browser accesses these pages he sends an session id to server (don't know exactly how, but it doesn't matter). Session variables are located on the server, and sessions are identified by its ids. It is ood idea to look into PHP manual for sessions. You can access session variable via $SESSION["variable_name"] (maybe it is $_SESSION I'm not sure now). When the variable doesn't exist and you want to write into it, new session variable is created. You need to place [b]session_start();[/b] on start of your script. Read the php manual for more details.
    : : About the file you want to include, it's quite easy: you wrote [italic]include("samefile.php?uname=".$txtusername);[/italic], but it looks fo file with name [b]"[/b]samefile.php?uname=$txtusername[b]"[/b]. You should write [italic]include ($txtusername)[/italic] or sth similar.
    : : Maybe one thing: You use JavaScript, but i think it is better to send the new address in data header with function [italic]header("Location: http://www.myaddress.com/myfile?parameter=value");[/italic]. You [b]HAVE TO use this function BEFORE any HTML data are sended to browser[/b].
    : : And the second thing: It isn't good dea to store information about logging in in hidden array. User can edit HTML sourcecode of sended page and there set the variable to [b]true[/b]. (Very easy, isn't?) This information should be in session variable, too.
    : : And the third and maybe last thing: Have you heard about using $_POST and $_GET arrays for getting informations from forms and parameters? IT IS VERY GOOD IDEA to use it. In our script (and on your server), there is a global variable for each field of form of parameter created. But you don't know where the variable came from. This can be dangerous, because somebody can try luck and write address [italic]www.youserver.com/yourpage.php?submitted=true[/italic]. What happens? A variable [italic]$submitted[/italic] will be created, so he can walk trough login page without password. It's terrible and very very dangerous, isn't it?
    : : When I learned PHP I have done some project with these capabilities, I had a few nightmares from this. So don't worry and for more informations read the PHP documentation on http://www.php.net .
    : : Have fun
    : :
    : :
    : :
    :
    : ThankU Mr Ego
    : Thanks for your proper guidence. header function is working properly
    : This is what i need.
    : Please tell me the original function of header(). My friend told me that some other argument is also there. will you? plz
    : I am doing like this .
    : if the entered password and username is correct i am creating session (using mysql) i am passing session id with username. There in the new form i am checking the session id is there are not . If it is there is he admin or others ..like that i am doing operaion
    : Is there anyway to break up this?
    :
    : And one more help How to destroy session if the user close browser directly without logging out how to check with time. I read in book but i am not getting
    :
    : And one more help Dont take me a headache. How to use _post _get methods when i am using i didnt receive anything from that
    :
    : Thanks for U........
    :
    About [italic]header[/italic] function: in string that is passed to this function are data headers, I think it may be content type or anything else. For more parameters try to look for some documentation - it may be about CGI scrpits (PHP scripts belong among them too) or somtehing else.
    You don't need to opreate with MySQL to work with sessions, that aren't "true sessions". Sessions are handled by PHP itself, it isn't difficult to use them. In your script call [italic]session_start()[/italic] at first. Then you can verify password and username. Suppose you have fields [b]username[/b] and [b]password[/b] at your page and [b]login[/b] function in your script which returns true when informations are correct and false otherwise. If these informations are correct, you should save them to session variables when checking password, e.g.
    [code]
    if(!($SESSION["name"]&&$SESSION["password"]))
    {
    //not logged
    if(login($_POST["name"],$_POST['password'])
    {
    $SESSION["name"]=$_POST["name"];
    $SESSION["password"]=$_POST["password"];
    //logged in, do something useful...
    }
    }
    else //already logged in any previous execution of this script
    {
    if(!login($SESSION["name"]&&$SESSION["password"]))
    {
    //informations in session variables are wrong, this should never happen, but it may e.g. if somebody changes logged person's username in database(but that didn't active user, strange)
    //so show login screen
    }
    //logged in, do somethign useful
    }
    [/code]. You should check these variables to know if is this person logged. They exist when they were created in previous executions of script (that handles PHP itself, you don't need to care about it). When $SESSION["name"] doesn't exist this means nobody has been logged and script displays login page. But when they exist, you should check values stored in them (but they are at 99,9% correct beacause incorrect informations you don't store into session variables, it can be incorrect only with logical error in script or deus ex machina). See PHP manual how to terminate session. There is some stuff with [b]session_close() function[/b].
    Session id validity is determined by setting your PHP module on your server for all scripts (find [italic][b]php.ini[/b][/italic] file)or you can redefine it in your script (see PHP manual (again :), very useful document)). When you set expiration time to 0, session id will be deleted (oh I remembered just now, session id's are carried by cookies) when browser is closed.
    $_POST and $_GET arrays.. A bit complicated. Maybe you may have old version of PHP (I'm not sure now, but I think this is contained in PHP 4) or the second and more probable cause, you have in [italic][b]php.ini[/b][/italic] [italic]register_globals=On[/italic], turn it to [italic]Off[/italic].
    I hope you and sessions become friends, this friendship is very improtant for PHP programer :)
    Bye


Sign In or Register to comment.