Hello there,

I am too new to try to figure out what I did wrong on this script. The idea was to check if the user was logged in, if they were the script would print a welcome message displaying the first name of the user, if they were not logged in the script would print the login form. Any assistance is appreciated:

<?php
	//Start session
	session_start();

//Check whether the session variable SESS_MEMBER_ID is present or not
if(!isset($_SESSION['SESS_MEMBER_ID']) {
print "Welcome <?php echo $_SESSION['SESS_FIRST_NAME'];?>.<br>You are logged in.<br><br>To view your account page, <a href="member-index.php" onmouseover="window.status='';return true">click here</a>"
}
else
{
	 (trim($_SESSION['SESS_MEMBER_ID']) == '')) 
		print("<font size="2" face="Verdana, Arial, Helvetica, sans-serif">User Name:
                                    </font><font size="2" face="Verdana, Arial, Helvetica, sans-serif"></font><font size="1" face="Verdana, Arial, Helvetica, sans-serif"><br>
                                    <form id="loginForm" name="loginForm" method="post" action="login-exec.php">
                  <input name="login" type="text" class="textfield" id="login" /><br>
                  <font size="2" face="Verdana, Arial, Helvetica, sans-serif">Password:</font>
                  <input name="password" type="password" class="textfield" id="password" />
                  <input type="submit" name="Submit" value="Login" />
                              </font>");
		exit();
	}
?>

    if you want t owrite a " with print, place before it a \ sign.

    for example:

    print "Hello, mi name is \"Josh\", and i like \" sign very much...";

    You start 3 ( sign, but you did not close on of them.

    (trim($_SESSION['SESS_MEMBER_ID']) == ''))

    use that:

    if(trim($_SESSION['SESS_MEMBER_ID']) == ''))

    and use this formula:

    print 'Welcome '. $_SESSION['SESS_FIRST_NAME'].'<br>You are logged in.<br><br>To view your account page, <a href="member-index.php" onmouseover="window.status='';return true">click here</a>';

    and why you use exit(); ? forget is...

    in the first watch i could find only these mistakes.

    Denholm;10890243 wrote:

    Hello there,

    I am too new to try to figure out what I did wrong on this script. The idea was to check if the user was logged in, if they were the script would print a welcome message displaying the first name of the user, if they were not logged in the script would print the login form. Any assistance is appreciated:

    <?php
    	//Start session
    	session_start();
    
    //Check whether the session variable SESS_MEMBER_ID is present or not
    if(!isset($_SESSION['SESS_MEMBER_ID']) {
    print "Welcome <?php echo $_SESSION['SESS_FIRST_NAME'];?>.<br>You are logged in.<br><br>To view your account page, <a href="member-index.php" onmouseover="window.status='';return true">click here</a>"
    }
    else
    {
    	 (trim($_SESSION['SESS_MEMBER_ID']) == '')) 
    		print("<font size="2" face="Verdana, Arial, Helvetica, sans-serif">User Name:
                                        </font><font size="2" face="Verdana, Arial, Helvetica, sans-serif"></font><font size="1" face="Verdana, Arial, Helvetica, sans-serif"><br>
                                        <form id="loginForm" name="loginForm" method="post" action="login-exec.php">
                      <input name="login" type="text" class="textfield" id="login" /><br>
                      <font size="2" face="Verdana, Arial, Helvetica, sans-serif">Password:</font>
                      <input name="password" type="password" class="textfield" id="password" />
                      <input type="submit" name="Submit" value="Login" />
                                  </font>");
    		exit();
    	}
    ?>

      Am I also supposed to place backslashes in front of the quotation marks ( " ) in the print tags? Alright, if I'm understanding this correctly, this should be the final product:

      <?php
      	//Start session
      	session_start();
      
      //Check whether the session variable SESS_MEMBER_ID is present or not
      if(!isset($_SESSION['SESS_MEMBER_ID'])) {
      print 'Welcome'. $_SESSION['SESS_FIRST_NAME'].'<br>You are logged in.<br><br>To view your account page, <a href="member-index.php" onmouseover="window.status='';return true">click here</a>";
      }
      else
      {
      	 (trim($_SESSION['SESS_MEMBER_ID']) == '')) 
      		print '<font size="2" face="Verdana, Arial, Helvetica, sans-serif">User Name:
                                          </font><font size="2" face="Verdana, Arial, Helvetica, sans-serif"></font><font size="1" face="Verdana, Arial, Helvetica, sans-serif"><br>
                                          <form id="loginForm" name="loginForm" method="post" action="login-exec.php">
                        <input name="login" type="text" class="textfield" id="login" /><br>
                        <font size="2" face="Verdana, Arial, Helvetica, sans-serif">Password:</font>
                        <input name="password" type="password" class="textfield" id="password" />
                        <input type="submit" name="Submit" value="Login" />
                                    </font>';
      	}
      ?>

      I tried it again, yet nothing loads, only a white screen. Any other suggestions?

      EDIT: Oops. Just noticed I placed this in the wrong forum. Was trying to put it into Coding, not PHP upgrades.

        At the end of , use ' and not " ...

        print 'Welcome'. $_SESSION['SESS_FIRST_NAME'

        And in the line 12 you missed an if

        if(trim($_SESSION['SESS_MEMBER_ID']) == ''))   <---- And lets Count the )  in this line...

        left is 2, but in the right there is 3 🙂

        use a syntax check friendly php editor...

        <?php
            //Start session
            session_start();
        
        //Check whether the session variable SESS_MEMBER_ID is present or not
        if(!isset($_SESSION['SESS_MEMBER_ID'])) 
        {
        print 'Welcome'. $_SESSION['SESS_FIRST_NAME'].'<br>You are logged in.<br><br>To view your account page, <a href="member-index.php" onmouseover="window.status='';return true">click here</a>';
        }
        else
        {
         if(trim($_SESSION['SESS_MEMBER_ID']) == '')
            print '<font size="2" face="Verdana, Arial, Helvetica, sans-serif">User Name:
                                        </font><font size="2" face="Verdana, Arial, Helvetica, sans-serif"></font><font size="1" face="Verdana, Arial, Helvetica, sans-serif"><br>
                                        <form id="loginForm" name="loginForm" method="post" action="login-exec.php">
                      <input name="login" type="text" class="textfield" id="login" /><br>
                      <font size="2" face="Verdana, Arial, Helvetica, sans-serif">Password:</font>
                      <input name="password" type="password" class="textfield" id="password" />
                      <input type="submit" name="Submit" value="Login" />
                                  </font>';
        }
        ?> 
        

          Thanks for the tip, I'm getting a syntax editor now, for future use.

          The odd thing is, the script still doesn't work..? I even copied your edited version to see if it would work, it didn't.

          Is there perhaps a different method to achieve my original goal?

            lets write down the user's tables structure.

            and i easily give you a session check example, i write the whole rows data into session variables.

            hello

              Database name: rcwebsite
              Table: members
              Rows in Members:

              member_id (auto increment)
              firstname
              lastname
              login
              passwd

              Hopefully that's what you were looking for.

                Hi,

                i've create a sample, you can download from here,

                http://www.phpcode.hu/teszt/session_login/session_login.rar

                you can see in there the login.php, it goes to the login2.php, it check the username and password, if it maches it sets the user's info session values, and print in form.php

                if you don't understand something lets answer. may i create a video tutorial around this theme ?

                bye.

                Denholm;10890271 wrote:

                Database name: rcwebsite
                Table: members
                Rows in Members:

                member_id (auto increment)
                firstname
                lastname
                login
                passwd

                Hopefully that's what you were looking for.

                  Yes, you may create a video tutorial around this theme. Yet this still doesn't resolve my issue.

                  Let's get back to the original goal. I'm trying to make a script on a public (not private) page that checks to see if the user is logged in. If the user is logged in, it displays a message similar to, "Hello $_user, you are logged in." If not, it prints the login form.

                  I'm trying to have this script execute in the area marked below in screen-shot-1.jpg.

                  [ATTACH]3660[/ATTACH]

                  As you can see, it's a public page, not a designated login area. If the user is logged in the script will print a message as stated above, if not, it will print the login form as shown in the picture.

                  I tried using the script you made, yet upon opening the document in firefox through apache the page loads showing what is displayed in screen-shot-2.jpg.

                  [ATTACH]3661[/ATTACH]

                  Apparently a few errors in coding. Yet the pages won't execute as they are supposed to.

                    I think you have not the right to run php code...
                    Before you wants to do this lets check.

                    copy a .php file to the server, with this:

                    <?php
                    echo ("PHP test 123");
                    ?>

                    and if it write the whole code as a text, lets check another web hosting place.

                    Denholm;10890367 wrote:

                    Yes, you may create a video tutorial around this theme. Yet this still doesn't resolve my issue.

                    Let's get back to the original goal. I'm trying to make a script on a public (not private) page that checks to see if the user is logged in. If the user is logged in, it displays a message similar to, "Hello $_user, you are logged in." If not, it prints the login form.

                    I'm trying to have this script execute in the area marked below in screen-shot-1.jpg.

                    [ATTACH]3660[/ATTACH]

                    As you can see, it's a public page, not a designated login area. If the user is logged in the script will print a message as stated above, if not, it will print the login form as shown in the picture.

                    I tried using the script you made, yet upon opening the document in firefox through apache the page loads showing what is displayed in screen-shot-2.jpg.

                    [ATTACH]3661[/ATTACH]

                    Apparently a few errors in coding. Yet the pages won't execute as they are supposed to.

                      I'm executing the php scripts on my local Apache server, it's not on the web. The test was successful and returned the words, "PHP test 123."

                        Maybe the short php tag will be the problem.

                        I'm doing a tutorial in a few days. That might help.

                          Thank you for the assistance so far. I'll be looking for the tutorial. Can you PM me when it's finished?

                          Thanks.

                          EDIT: Yes, it was because of the short php tag. I simply inserted the php notes and it worked, partially.... Some code is still appearing because you coded it improperly. Here is an image of what I see:
                          [ATTACH]3662[/ATTACH]

                          It is because in the code you close the <form> tag with some php code, here is a good example of just that:

                          <td><input id="firstname" name="firstname" <?=$style_classfirstname?>type="text" size="25" value="<?=$_SESSION["contentfirstname"]?>" maxlength="255"></td></tr><tr><td width = "150"><div align="right"><label for="lastname">lastname</label></div></td>

                          You closed the <form> tag at this code:

                          <?=$style_classfirstname?>

                          Which means the rest is disregarded as code and displayed as text.

                            You should allow the short tags.

                            if i white something like that:

                            <?php
                            $url="aaa.jpg";
                            ?>

                            <a href="<?=$url?>"><img src="something.jpg"></a>

                            if will adds the $url's value into that link.

                            if you changethe code <?=$value?> into <?php echo $value; ?>

                            that will work file. Tomorrow i start that tutorial.

                            Denholm;10890406 wrote:

                            Thank you for the assistance so far. I'll be looking for the tutorial. Can you PM me when it's finished?

                            Thanks.

                            EDIT: Yes, it was because of the short php tag. I simply inserted the php notes and it worked, partially.... Some code is still appearing because you coded it improperly. Here is an image of what I see:
                            [ATTACH]3662[/ATTACH]

                            It is because in the code you close the <form> tag with some php code, here is a good example of just that:

                            <td><input id="firstname" name="firstname" <?=$style_classfirstname?>type="text" size="25" value="<?=$_SESSION["contentfirstname"]?>" maxlength="255"></td></tr><tr><td width = "150"><div align="right"><label for="lastname">lastname</label></div></td>

                            You closed the <form> tag at this code:

                            <?=$style_classfirstname?>

                            Which means the rest is disregarded as code and displayed as text.

                              Well, now it works, yet login2 won't print the message of a successful registration or a failed registration. Any ideas as to the issue here?

                                let's start in login.php and login2.php the
                                with log tag
                                <?php
                                session_start(); ?>

                                And create the connect.php nad

                                run the table create sql query.

                                CREATE TABLE IF NOT EXISTS members (
                                member_id int(6) NOT NULL auto_increment,
                                firstname varchar(255) NOT NULL default '',
                                lastname varchar(255) NOT NULL default '',
                                login varchar(255) NOT NULL default '',
                                passwd varchar(255) NOT NULL default '',
                                PRIMARY KEY (member_id),
                                UNIQUE KEY id (member_id)
                                ) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=2 ;

                                And after that, try it.

                                bye.

                                Denholm;10890424 wrote:

                                Well, now it works, yet login2 won't print the message of a successful registration or a failed registration. Any ideas as to the issue here?

                                  This is rather frustrating. I imported the included .sql file into my rcwebsite database. Afterward I tried to make an account again and it still didn't print the message of a successful registration.

                                  Any other ideas?

                                    Write a Reply...