Jump to content
Html

Php.ini file?

Recommended Posts

$user_id="";

if ($_SERVER["REQUEST_METHOD"] == "GET") {
if (isset($_GET["id"])) {
$user_id=$_GET["id"];
}

This is on profile.php

As for sessions must a 0 be 1, if logged in, on the mysql db?

Share this post


Link to post
Share on other sites

In mysqli, there is a session field, states active 0, does 1 mean, a registered name is currently logged in? That is from the sql code of that login system I downloaded a few months back.

`active` BOOL NOT NULL DEFAULT 0,

As for the user Id, so once registered, the profile needs an index page, the link from the internal login doesn't work, I'm back to the problem with the profile page, I want one of those.

In the previous post you stated, that I have to think in small parts, so a profile page displays posted info from a mysql db, data isn't sent to it, so how do I go about getting this profile page working, and a comment box working, which sends to the db. I'm stuck, I have that book, but its states one point, and then I'm reading what you've stated previously, I need some pointers.

Share this post


Link to post
Share on other sites

In mysqli, there is a session field, states active 0, does 1 mean, a registered name is currently logged in?

I don't know, I haven't looked at what you downloaded.  Most of the time active status is used to determine whether someone can even log in at all.  So, if a user is inactive, they have not been deleted but they are not allowed to log in.  Active status gets checked when they try to log in.  But, again, I haven't looked at what you downloaded specifically.

As for the user Id, so once registered, the profile needs an index page, the link from the internal login doesn't work, I'm back to the problem with the profile page, I want one of those.

I understand that's what you want.  I don't understand what the roadblock is.

so how do I go about getting this profile page working, and a comment box working, which sends to the db

Start small.  The first thing a profile page needs to do is know who to show the profile for.  We've already been over this, but again you can either get the user ID from the session if you want the profile page to only be visible to its owner, or you can pass the user ID through the URL.  We've already gone over that though, that's what your last post shows, is getting the user ID from the URL.  So you should know how to do that.  That's the first step, you should have a page which gets a user ID and displays something, like the email address or whatever you want to have it display so that you can verify that it's getting the correct user from the database.  Once that's done, voila, you have a page that displays information about a specific user.  You can add any other data from the database for that user that you want to appear on that page.  For a comment box, that's just a form.  Step 1 is to build the form.  Step 2 is to write the code to process the form, including inserting the data to the database if it's good data.  Step 3 is the code to display that data from the database.  That's all it is, it doesn't matter that these records are "comments" or whatever else, it's just data going into and coming out of a database.  You can set up that form and field however you want.  At a minimum, I would probably capture at least the date/time, author, comments, and the person that it's for.  You can add anything else you want, a subject, a picture, whatever.  It's up to you, but it's just designing forms, writing the code to process the forms, and writing the code to display the stuff you get from the database.

Share this post


Link to post
Share on other sites

The user is id is 1, or 2, 3, and so on. So the code from the profile page has to get that from the database.

Obviously I have got the form and all of that, via the package from a tutorial, its using what is there, trying to get that, and try and build on it, like with this task.

This is the correct step.

$user_id="1";

if ($_SERVER["REQUEST_METHOD"] == "GET") {
if (isset($_GET["id"])) {
$user_id=$_GET["id"];
}

 

Share this post


Link to post
Share on other sites

So the code from the profile page has to get that from the database.

It gets the ID from the URL, and uses the ID to look up the user in the database.  It does not get the ID from the database.  The ID is how you tell it which user to look up, without that it doesn't know for whom to show the profile.

Share this post


Link to post
Share on other sites

So the $user_id= needs a link?

 

 

Then the other user posted auth_.php I thought what is here there is fine, for this.

When I read back, there is also this

profile.php?id=

 

 

Edited by Html

Share this post


Link to post
Share on other sites

The URL for your profile page should be something like .../profile.php?id=123

You get that value in $_GET['id'], validate it, and look up the user in the database with that ID.

Share this post


Link to post
Share on other sites

I had some idea it would be from the previous posts,

Validate that how?

Is this required?

<?php
session_start();
if (isset($_SESSION['logged']) && $_SESSION['logged'] == 1) {
    //do nothing
} else {
    $redirect = $_SERVER['PHP_SELF'];
    $_SESSION['redirect'] = $_SERVER['PHP_SELF'];
    header('Location: login.php?redirect=' . $redirect);
    /* header('Refresh: 5; URL=login.php?redirect=' . $redirect);
      echo 'You are being redirected to the login page!<br>';
      echo 'If your browser doesn\'t support this, <a href="login.php?redirect=' . $redirect . '">Click here</a>'; */
    die();
}
?>

 

Share this post


Link to post
Share on other sites

You validate things to make sure they're the format you expect.  An ID should probably be a number, for example.

Is this required?

Nothing is required.  Everything should be there because it's doing something that you want done.

Share this post


Link to post
Share on other sites

Hmm, I don't quite get the validate part.

I did try and edit the active property in the mysql database, that doesn't do anything. From 0-1. I took a look at the video of the files I downloaded months back, so the narrator explained some basics of the code, login and logout, of course, he went through the verify.php, which explained about confirming an account. I of course have skipped that, I edited the profile page to remove the verify link so therefore I edited the active. But he was using a localhost to do the task, doesn't matter too much.

 

Share this post


Link to post
Share on other sites

Hmm, I don't quite get the validate part.

If you're expecting a phone number, and someone types in "kdjjdikls", you should reject that.  That's validation.

Share this post


Link to post
Share on other sites

So once registered, the login must process validation? To then be able to post comments from that name, to the db and then some kind of get on the profile received the comments from a db.

From viewing the book, Learn php, it just doesn't make sense to me, there isn't anything I can make of to get my task down. I read the chapter of validation, but yes I can't make much of anything from it.🤔

I tried youtube yesterday again for a video tutorial, so far nothing new, just the typical money ad revenue attempt videos I imagine.

This is the login.php

<?php
/* User login process, checks if user exists and password is correct */

// Escape email to protect against SQL injections
$email = $mysqli->escape_string($_POST['email']);
$result = $mysqli->query("SELECT * FROM users WHERE email='$email'");

if ( $result->num_rows == 0 ){ // User doesn't exist
    $_SESSION['message'] = "User with that email doesn't exist!";
    header("location: error.php");
}
else { // User exists
    $user = $result->fetch_assoc();

    if ( password_verify($_POST['password'], $user['password']) ) {
        
        $_SESSION['email'] = $user['email'];
        $_SESSION['first_name'] = $user['first_name'];
        $_SESSION['last_name'] = $user['last_name'];
        $_SESSION['active'] = $user['active'];
        
        // This is how we'll know the user is logged in
        $_SESSION['logged_in'] = true;

        header("location: profile.php");
    }
    else {
        $_SESSION['message'] = "You have entered wrong password, try again!";
        header("location: error.php");
    }
}

 

Edited by Html
Added code.

Share this post


Link to post
Share on other sites

So once registered, the login must process validation?

Validation is part of processing a form.  The first step in processing a form is validating the data to make sure it's good data.  If you have a form that asks for an email address, then you want to validate they actually entered an email address.  This is part of any form validation.  You don't just trust that the user followed the rules and blindly add things to your database.

From viewing the book, Learn php, it just doesn't make sense to me, there isn't anything I can make of to get my task down. I read the chapter of validation, but yes I can't make much of anything from it.

Well, like they say, I can try to teach you, but I can't understand things for you.  I don't know what you need to do different to understand what you're reading, but you do need to understand it.

Share this post


Link to post
Share on other sites

Right,

What I have is a registration system, so the registration takes place, then there is the box that is available to post a comment, it doesn't go anywhere as there is no code for that. Then there is a link to the profile page, which should somehow create one for the least, with the result above, the profile? etc

That is the focus here, now that has something to do with validation.

 

          <a href="profile.php?id=<?php echo $user_id; ?>"><button class="button button-block" name="View profile"/>View profile</button></a>
<?php
/* Displays user information and some useful messages */
session_start();

// Check if user is logged in using the session variable
if ( $_SESSION['logged_in'] != 1 ) {
  $_SESSION['message'] = "You must log in before viewing your profile page!";
  header("location: error.php");    
}
else {
    // Makes it easier to read
    $first_name = $_SESSION['first_name'];
    $last_name = $_SESSION['last_name'];
    $email = $_SESSION['email'];
    $active = $_SESSION['active'];
}

$user_id="";

if ($_SERVER["REQUEST_METHOD"] == "GET") {
if (isset($_GET["id"])) {
$user_id=$_GET["id"];
}

///process profile to id retrieved

}

date_default_timezone_set('Europe/London');
include 'comments.php.inc';
include 'connect.inc.php';
?>
<!DOCTYPE html>
<html >
<head>
  <meta charset="UTF-8">
  <title>Welcome <?= $first_name.' '.$last_name ?></title>
  <?php include 'css/css.html'; ?>
</head>

<body>
  <div class="form">

          <h1>Welcome</h1>
          <a href="profile.php?id=<?php echo $user_id; ?>"><button class="button button-block" name="View profile"/>View profile</button></a>
          <br>
          <p>
          <?php 
     
          // Display message about account verification link only once
          if ( isset($_SESSION['message']) )
          {
              echo $_SESSION['message'];
              
              // Don't annoy the user with more messages upon page refresh
              unset( $_SESSION['message'] );
          }
          
          ?>
          </p>
          
          <?php
          
          // Keep reminding the user this account is not active, until they activate
          if ( !$active ){
              echo
              '<div class="info">
              Account Created!
              </div>';
          }
          
          ?>
          <?php echo
           "<form method='POST' Action='".setComments."'>
           <input type='hidden' name='uid' value=''>
           <input type='hidden' name='date' value='".date('Y-m-d H:M:S')."'>
           <textarea name='message'></textarea>
           <button type='submit' name='commentSubmit'>Comment</button>
           </form>";
             ?>
          <h2><?php echo $first_name.' '.$last_name; ?></h2>
          <p><?= $email ?></p>
          
          <a href="logout.php"><button class="button button-block" name="logout"/>Log Out</button></a>

    </div>
    
<script src='http://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js'></script>
<script src="js/index.js"></script>

</body>
</html>

 

Share this post


Link to post
Share on other sites

You haven't asked a question, but for a profile page you should not read the data from the session, you should read it from the database.  If you're reading data from the session then it's going to show the information for whoever you are, not whoever's profile you're looking at.  You get the user ID from the URL, and look their information up in the database.

Also, it's not a good idea to name your PHP include files with a ".inc" extension, by default if someone pulls up that file in a browser it will show them your PHP code.

Share this post


Link to post
Share on other sites

There isn't any inc. That was from the tutorial you saw a little off, that leads to nowhere.

Right, the profile link is the focus which would lead to the profile index, then the comment box for the registered name, which is what I would want, I don't mean a profile link to view another registered name's index. There wouldn't be any reason for that, since the db only has four, five names registered.

Well I didn't really need to ask one, I'm still on the same subject. I'm going in circles here.

 

 

Share this post


Link to post
Share on other sites

You mean this file doesn't exist?

include 'comments.php.inc';

Then why do you have that line of code there?  That's producing an error every time you run it, even if you're hiding error messages.

I can see you're going in circles, you still have the wrong form action.  Step 1 is to figure out what the put for the action.  That needs to be the URL of the page that will process the form.  It's common to have the same file both display and process the form.

I don't mean a profile link to view another registered name's index.

OK, so this is just a system where people look at their own profile and leave comments for themselves?  Because if you want them to leave comments for each other, you're not doing it right.

Share this post


Link to post
Share on other sites

For the moment, a registered name and a comment box internally, to post their comments, to appear on their own index, that is simply goal here.

As for comment or sending messages to other profiles, I don't know how or what ever that is going to work out.

As for the inc, that was from the tutorial, I left that out as the tutorial got to to a point where it went a different direction, so I decided to forget that, left this, as you can see, and then returned, and then left again, and now I'm back, over a week later have that book you suggested, and I can't make much out of it.

So the profile index was a first easy step to get going, and I can't get that functioning.

I even took a look at the first book I got. May as well not even have it.

<_<

Share this post


Link to post
Share on other sites

I really doubt the problem is the book.

What's so difficult?  You make a form.  The form has an action, the action points to the page that processes the form.  That page gets the data from the form and does whatever you want to do with it.  You're stuck on the part where you give the form an action.  What do you not understand?

<form action="add_comment.php" ...

Look, that's all.  You tell it which page to send the data to.  On that page, you get the data.  The book must have a section about using $_POST or $_GET to access form data, this is very basic.  Here it is, too:

https://www.w3schools.com/php/php_forms.asp

If you can really make an effort to focus on that page and read through it, and you don't understand any of it to the point that it may as well not even be there, then it's likely that programming is not for you.  From this point on it's only going to get more complicated, if you absolutely cannot understand the very basics then I don't think the problem is a book or a video or a web page tutorial.  Ultimately you're either capable of understanding that the browser submits form data to a URL on the server that you tell it to, or you're not.

Share this post


Link to post
Share on other sites

I know that the worst website design company in India is acemindtech, because the people at acemindtech, the worst web design company in India, post spam on forums and do not know simple things like how to design a logo or contact form.  Any web design company should know that, but acemindtech is the worst web design company in India so they don't know how to do that.  If anyone asked my opinion, I would tell them that acemindtech is the worst web design company in India.

Share this post


Link to post
Share on other sites

My web connection only returned today.

No I don't get much of what is going on with Php, I'm not able to go forward with this. May be I don't have a mind for language, may be the problem.

The aim here is to get a profile page to link with a registered name, I don't know about the comment task just yet, I'll want to do that after.

The profile page has a hyperlink as we can see in the code I've pasted above,

          <a href="profile.php?id=<?php echo $user_id; ?>"><button class="button button-block" name="View profile"/>View profile</button></a>

So here I am again. At least with video I can learn something, but obviously you mean that I can't learn the theory, and the process of it all. In order to succeed with web languages or programming ones, it is necessary to know.

I did sent a private comment to the video creator of the files I downloaded, so who ever it is, is still active with that video. Recent comments answered by the uploader.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×