Hi this is Scorpion
I have create 5 pages on PHP
and 1 login Page.
Now the issue is that if user didnt login to the Website, then he cannot view those pages and simply he/she must direct to login page if click to other categories of Page.
I have Created a session but it is not doing it so.
Any help will be appreciated with great concern

Regards
Scorpion

when the user logs in, put his username in the session. In all other pages, check if $_SESSION is set and not equal to null. If its null, then use header function to redirect to the login page.
Eg.

//after user logs in, 
$_SESSION['username']=$username;
// 
in other pages, 
if(! isset($_SESSION['username']) || $_SESSION['username']=="")) {
//redirect to login page
}

Cheers,
Naveen

Thanx a lot dear for such an great help
Will be back soon
Regards
Scorpion

Hi this is scorpion

if i want to create my user account
like
Name, loginname, email,password...
let suppose i enter these values to create account in my Signup Form
let suppose i click on button "Create Account"

if ('')
{
then it direct to Welcome user page and and it must be sign in automatically....
}

but
in my Present case what i am dong is that
i give the location but it is automatically directing to Sign in Page.
Infact i start seession in my welcome_user.php

well how to direct it to get login automatically when create an account
not to sign in.

Any help will be higly appreciated

Thanks and Regards
scorpion

On successful registration, add username to the session. In the next page, check if session is set, if yes, then redirect directly to the page which he gets after successful login. If session is not set, redirect him to login page.

if(isset($_POST))
{
$usr_email_chk_avail    =   $_POST;
$usr_nam_chk_avail      =   $_POST;
$usr_pass_chk_avail     =   $_POST;


$sql_chk        =   "select * from login_session where user_email='$usr_email_chk_avail' AND user_name='$usr_nam_chk_avail' AND user_password='$usr_pass_chk_avail'";


echo $sql_chk;
$result_chk     =   mysql_query($sql_chk);


$num_rows       =   mysql_num_rows($result_chk);


if ($num_rows <= 0)
{
echo "<script>alert('Congratulation This User Name: Available for You')</script>";
echo $sql_chk;
echo "<script>window.location='http://localhost/login_sess/welcome_user.php'</script>";
include 'create_user.php';


$_SESSION('u_name') = $usr_nam_chk_avail;
}

this is my code
but it is throwing error

Fatal error: Can't use function return value in write context in C:\xampp\htdocs\login_Sess\sign_up.php on line 100

Its $_SESSION=$usr_nam_chk_avail;

cant understand your Point....

its not
$_SESSION('u_name') = $usr_nam_chk_avail; But the one I posted above.

Oh My God its just a Bracket mistake
and becomes invisible for me.....
sometimes little mistakes becomes a biggest mistake

Thanks after all Naveen
Regards
Scorpion

:) You are welcome!

$username = $_POST['user'];
    $password = $_POST['pass'];

    $sql="Select memid,passw from member where memid='$username'";
    $result     = dbQuery($sql);
    //  $numProduct = dbNumRows($result);
    while ($row = dbFetchAssoc($result)) {  
        //extract($row);
        if($username == $row['memid'] && $password == $row['passw'] )
        {
            session_start();
            $_SESSION['adnuser']=$_POST['user'];
            if (isset($_SESSION['login_return_url'])) {
                header('Location: '. $_SESSION['login_return_url'].'DBGSESSID='.$_REQUEST[DBGSESSID].'&PHPSESSID='.$_REQUEST[PHPSESSID].'');
                exit;
            } else {
                header('Location: index.php?DBGSESSID='.$_REQUEST[DBGSESSID].'&PHPSESSID='.$_REQUEST[PHPSESSID].'');
                exit;
            }

        }

hi guys when user get login... how to get its id and store it to other table?

Can you explain in detail what exactly you mean by that ?

Yes.... I want the particular ID.... When a user get online i need to obtain its aurto generated ID of its Database and to store it in variable ... coz i am making a forum.... and have to use the ID for a Particular thread... like this user Starts this thread....
So hope u Understand?

Regards
Scorpion

$q="select * from user_table where username='$user' and password='$password'"; //when the user is logging in
$result=mysql_query($q);
if(mysql_num_rows($result) > 0) {
echo "Valid user";
while($row=mysql_fetch_array($result)){
$id=$row['id']; //is the autogenerated id
echo "Id is ". $id; //$id will have the id
}
} else {
echo "Invalid user";
exit;
}

Something like that ?

Men I Fix it before your Response
But After All Thanks A lot for your Response
Glad to see this

Regards
Scorpionz

:) Great ! congrats !

Thanks Buddy!!! :)

If your problem is fixed, why not mark this thread as solved ?

if
there any other issue raised regarding this scenario?
then
So it must not be marked...
After all thanks

Regards
Scorpion

hmm! okay !

commented: Naveen is a Great Guy ... With Great Knowledge +2
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.