Jump to content

blog project


lukasz

Recommended Posts

Hey lads,

 

I'm a bit stuck with something,

 

I've no problem to register and create a/c for new user, but I dont know how I will direct then new user to his new blog and how would I direct old user to his old blog with all the details stored already?

 

At the moment I have two mysql tables,one table to store username ,email and password and second one to store post(title,comment,authorname).

 

Do I need another table?

 

 

Any ideas?

 

Thanks,

 

 

Link to comment
Share on other sites

Can you explain more fully? I'm not sure what you're asking.

 

Hey Pawn ,

 

I'm creating blog in php and mysql , I have a bit done.

I  can create new users and store their username and password in database ,I have also template for posting msg's.Next thing which need to be done is each user need to be log in into their own blog with their post's , picture ans so on..

How will I direct them to their blog?

What code need to be involved that each time the user is log in  , will be log in to his own blog?

If is new user then probably I will need to use a template or something to let new user upload picture . add posts and so on?

Do you understand me now?

 

I'm very new to php and mysql!

p.s I'm really sorry sometimes is difficult for me to explain something fully ;0)

 

I appreciate your help,

Link to comment
Share on other sites

Maybe add a field to the users table (if you're using database that is...) that is for their blog id/name. then when they login, just do this:

header("location: index.php?blog=$blogid");

:-\ though, I don't think that is the best way to do this. I think you should post some of your code here, so it can be evaluated.

Link to comment
Share on other sites

Maybe add a field to the users table (if you're using database that is...) that is for their blog id/name. then when they login, just do this:

header("location: index.php?blog=$blogid");

:-\ though, I don't think that is the best way to do this. I think you should post some of your code here, so it can be evaluated.

 

Thanks for that ,

 

This is my login page..

 

<?php

session_start();

 

if (isset($_POST['txtusername']) && isset($_POST['txtpassword'])) {

// check if the user id and password combination is correct

if ($_POST['txtusername'] == 'admin' && $_POST['txtpassword'] == 'admin') {

// the user id and password match,

// set the session

$_SESSION['login'] = "Login";

// after login we move to the main page

header('Location: print.php');

exit;

} else {

 

include "connect.php";

 

mysql_select_db("post_db")

or die ("Could not select database because ".mysql_error());

 

$q = "SELECT * FROM $table1 WHERE txtusername='$txtusername' and txtpassword='$txtpassword'";

$result = mysql_query($q)or die (mysql_error());

$numrows=mysql_num_rows($result);

 

 

if($numrows==0){echo "Invalid User ..<a href='loginpage.html'>Please try again.</a>";}

 

else {

 

echo $_POST['txtusername'];

echo " You are logged in successfully!<br><a href='http://localhost/Project/firstprint.php'>Click Here.</a>";}

 

 

 

}

}

?>

 

Sorry any extra ideas?

Maybe yea I would add extra field to users table?but I'm not getting one thing here whats the 'blog=$blogid' is?

 

Is late late here I will back here i next couple hours please let me know if you have any suggestions here and whether you want to see any more stuff of my code?!Thanks.

 

Link to comment
Share on other sites

Maybe yea I would add extra field to users table?but I'm not getting one thing here whats the 'blog=$blogid' is?

 

it will tell the script which blog the user is using. you get the blogid from the database. SELECT * FROM wherever WHERE userid='userid' - then just pull the blog from the users row.

 

then you just create a script to recognize the blog=blogid using $_GET, where you determine what to show. the blog id will probably correspond to another field in a different table, maybe blogdata or something. that is recognition point.

 

i'm going to take a break for a while; hopefully someone else can think of a good idea before i get back. :D

Link to comment
Share on other sites

Maybe yea I would add extra field to users table?but I'm not getting one thing here whats the 'blog=$blogid' is?

 

it will tell the script which blog the user is using. you get the blogid from the database. SELECT * FROM wherever WHERE userid='userid' - then just pull the blog from the users row.

 

then you just create a script to recognize the blog=blogid using $_GET, where you determine what to show. the blog id will probably correspond to another field in a different table, maybe blogdata or something. that is recognition point.

 

i'm going to take a break for a while; hopefully someone else can think of a good idea before i get back. :D

 

'Then just pull the blog from the users row ' - you mean id?

'the blog id will probably correspond to another field in a different table..' why do I need another table for?to store other details?

Thanks,again I appreciate any suggestion!

Oh I see only darkness :)

 

Link to comment
Share on other sites

Maybe yea I would add extra field to users table?but I'm not getting one thing here whats the 'blog=$blogid' is?

 

it will tell the script which blog the user is using. you get the blogid from the database. SELECT * FROM wherever WHERE userid='userid' - then just pull the blog from the users row.

 

then you just create a script to recognize the blog=blogid using $_GET, where you determine what to show. the blog id will probably correspond to another field in a different table, maybe blogdata or something. that is recognition point.

 

i'm going to take a break for a while; hopefully someone else can think of a good idea before i get back. :D

 

'Then just pull the blog from the users row ' - you mean id?

'the blog id will probably correspond to another field in a different table..' why do I need another table for?to store other details?

Thanks,again I appreciate any suggestion!

Oh I see only darkness :)

 

include "connect.php";

 

mysql_select_db("post_db")

or die ("Could not select database because ".mysql_error());

 

$data = mysql_query("SELECT * FROM textpost ORDER BY date desc limit 10")

or die(mysql_error());

echo "<h3>"."Your recent blog post's"."<br/>"."</h3>";

echo "<table align='right'>";

echo "<tr>";

echo "<td>";

echo "Login Page <a href='loginpage.html'>Click Here.</a>";

echo "</td>";

echo "<tr>"."<td> <br> </td>"."</tr>";

echo "<td>";

echo " Add New Post Here <a href='http://localhost/Project/add_post.php'>Click Here.</a>";

echo "</td>";

echo "</tr>";

echo "</table>";

echo "<table border='0' >";

 

while($info = mysql_fetch_array( $data ))

{

echo "<tr>"."<td><b>Title:</b></td> <td>".$info['title'] . "</td>"."</tr>";

echo "<tr>"."<td><b>Comment:</b></td> <td>".$info['comment'] . " </td>"."</tr>";

echo "<tr>"."<td><b>Authorname:</b></td> <td>".$info['authorname'] . " </td>"."</tr>";

echo "<tr>"."<td><b>Date:</b></td> <td>".$info['date'] . " </td>"."</tr>";

echo "<tr>"."<td> <br> </td>"."</tr>";

}

echo "</table>";

 

 

?>

 

 

This is my general code to print post's , but I stil cant get it how to print post only for particular bloger which is logged in using username and password , please help ;-)

Link to comment
Share on other sites

Okay, that looks pretty good. (didn't really evaluate it, but in essence, good).

 

Now, since you already have a table for posts "textposts" - Add a field to that. Call it "owner" or something.

 

Everytime a user creates a post, add their blog ID to the "owner" field of the post. This way, each post will be marked by that user (*they 'own' it now ).

 

Then, just change your code slightly to recognize your blogs, based on the User's ID.

 

An example of the URL would be: mysite.com/index.php?blog=1 (The blog=1 represents the ID of the user who 'owns' the blog).

 

The code for this would be simple:

 


$owner = $_GET['blog'];

include "connect.php"; 

mysql_select_db("post_db")
or die ("Could not select database because ".mysql_error());

$data = mysql_query("SELECT * FROM textpost WHERE blogID = '" . $owner . "' ORDER BY date desc limit 10") 
or die(mysql_error()); 
echo "<h3>"."Your recent blog post's"."<br/>"."</h3>";
echo "<table align='right'>";
echo "<tr>";
echo "<td>";
echo "Login Page <a href='loginpage.html'>Click Here.</a>";
echo "</td>";
echo "<tr>"."<td> <br> </td>"."</tr>";
echo "<td>";
echo " Add New Post Here <a href='http://localhost/Project/add_post.php'>Click Here.</a>";
echo "</td>";
echo "</tr>";
echo "</table>";
echo "<table border='0' >"; 

while($info = mysql_fetch_array( $data )) 
{ 
echo "<tr>"."<td><b>Title:</b></td> <td>".$info['title'] . "</td>"."</tr>"; 
echo "<tr>"."<td><b>Comment:</b></td> <td>".$info['comment'] . " </td>"."</tr>";
echo "<tr>"."<td><b>Authorname:</b></td> <td>".$info['authorname'] . " </td>"."</tr>";
echo "<tr>"."<td><b>Date:</b></td> <td>".$info['date'] . " </td>"."</tr>";
echo "<tr>"."<td> <br> </td>"."</tr>";
} 
echo "</table>"; 


?> 

 

Now it will only display posts owned by this user; everything else will be the same. :)

 

How are you storing sessions/logs, btw? If you are using cookies/session, instead of using the index.php?blog=1 - you could just store a session/cookie with their user ID (if you don't have one already), and then have the site recognize it that way. Just by changing the one line of code I made - IE: $owner = $_COOKIE['userID'];

 

Also, be sure to check for possible security errors with your scripts. :P Don't want anyone hacking it.

Link to comment
Share on other sites

Okay, that looks pretty good. (didn't really evaluate it, but in essence, good).

 

Now, since you already have a table for posts "textposts" - Add a field to that. Call it "owner" or something.

 

Everytime a user creates a post, add their blog ID to the "owner" field of the post. This way, each post will be marked by that user (*they 'own' it now ).

 

Then, just change your code slightly to recognize your blogs, based on the User's ID.

 

An example of the URL would be: mysite.com/index.php?blog=1 (The blog=1 represents the ID of the user who 'owns' the blog).

 

The code for this would be simple:

 


$owner = $_GET['blog'];

include "connect.php"; 

mysql_select_db("post_db")
or die ("Could not select database because ".mysql_error());

$data = mysql_query("SELECT * FROM textpost WHERE blogID = '" . $owner . "' ORDER BY date desc limit 10") 
or die(mysql_error()); 
echo "<h3>"."Your recent blog post's"."<br/>"."</h3>";
echo "<table align='right'>";
echo "<tr>";
echo "<td>";
echo "Login Page <a href='loginpage.html'>Click Here.</a>";
echo "</td>";
echo "<tr>"."<td> <br> </td>"."</tr>";
echo "<td>";
echo " Add New Post Here <a href='http://localhost/Project/add_post.php'>Click Here.</a>";
echo "</td>";
echo "</tr>";
echo "</table>";
echo "<table border='0' >"; 

while($info = mysql_fetch_array( $data )) 
{ 
echo "<tr>"."<td><b>Title:</b></td> <td>".$info['title'] . "</td>"."</tr>"; 
echo "<tr>"."<td><b>Comment:</b></td> <td>".$info['comment'] . " </td>"."</tr>";
echo "<tr>"."<td><b>Authorname:</b></td> <td>".$info['authorname'] . " </td>"."</tr>";
echo "<tr>"."<td><b>Date:</b></td> <td>".$info['date'] . " </td>"."</tr>";
echo "<tr>"."<td> <br> </td>"."</tr>";
} 
echo "</table>"; 


?> 

 

Now it will only display posts owned by this user; everything else will be the same. :)

 

How are you storing sessions/logs, btw? If you are using cookies/session, instead of using the index.php?blog=1 - you could just store a session/cookie with their user ID (if you don't have one already), and then have the site recognize it that way. Just by changing the one line of code I made - IE: $owner = $_COOKIE['userID'];

 

Also, be sure to check for possible security errors with your scripts. :P Don't want anyone hacking it.

 

Thanks for the suggestions I will have look on this now and I'll get back to you  ;)

Link to comment
Share on other sites

Okay, that looks pretty good. (didn't really evaluate it, but in essence, good).

 

Now, since you already have a table for posts "textposts" - Add a field to that. Call it "owner" or something.

 

Everytime a user creates a post, add their blog ID to the "owner" field of the post. This way, each post will be marked by that user (*they 'own' it now ).

 

Then, just change your code slightly to recognize your blogs, based on the User's ID.

 

An example of the URL would be: mysite.com/index.php?blog=1 (The blog=1 represents the ID of the user who 'owns' the blog).

 

The code for this would be simple:

 


$owner = $_GET['blog'];

include "connect.php"; 

mysql_select_db("post_db")
or die ("Could not select database because ".mysql_error());

$data = mysql_query("SELECT * FROM textpost WHERE blogID = '" . $owner . "' ORDER BY date desc limit 10") 
or die(mysql_error()); 
echo "<h3>"."Your recent blog post's"."<br/>"."</h3>";
echo "<table align='right'>";
echo "<tr>";
echo "<td>";
echo "Login Page <a href='loginpage.html'>Click Here.</a>";
echo "</td>";
echo "<tr>"."<td> <br> </td>"."</tr>";
echo "<td>";
echo " Add New Post Here <a href='http://localhost/Project/add_post.php'>Click Here.</a>";
echo "</td>";
echo "</tr>";
echo "</table>";
echo "<table border='0' >"; 

while($info = mysql_fetch_array( $data )) 
{ 
echo "<tr>"."<td><b>Title:</b></td> <td>".$info['title'] . "</td>"."</tr>"; 
echo "<tr>"."<td><b>Comment:</b></td> <td>".$info['comment'] . " </td>"."</tr>";
echo "<tr>"."<td><b>Authorname:</b></td> <td>".$info['authorname'] . " </td>"."</tr>";
echo "<tr>"."<td><b>Date:</b></td> <td>".$info['date'] . " </td>"."</tr>";
echo "<tr>"."<td> <br> </td>"."</tr>";
} 
echo "</table>"; 


?> 

 

Now it will only display posts owned by this user; everything else will be the same. :)

 

How are you storing sessions/logs, btw? If you are using cookies/session, instead of using the index.php?blog=1 - you could just store a session/cookie with their user ID (if you don't have one already), and then have the site recognize it that way. Just by changing the one line of code I made - IE: $owner = $_COOKIE['userID'];

 

Also, be sure to check for possible security errors with your scripts. :P Don't want anyone hacking it.

 

Thanks for the suggestions I will have look on this now and I'll get back to you  ;)

I'm getting error now: Unknown column 'blogID' in 'where clause'

Link to comment
Share on other sites

My mistake. I should have wrote owner in the WHERE clause, not blogID. :P

 

Also, be sure that you have actually created the owner field, before testing.

 

Fixed:

 

$owner = $_GET['blog'];

include "connect.php"; 

mysql_select_db("post_db")
or die ("Could not select database because ".mysql_error());

$data = mysql_query("SELECT * FROM textpost WHERE owner = '" . $owner . "' ORDER BY date desc limit 10") 
or die(mysql_error()); 
echo "<h3>"."Your recent blog post's"."<br/>"."</h3>";
echo "<table align='right'>";
echo "<tr>";
echo "<td>";
echo "Login Page <a href='loginpage.html'>Click Here.</a>";
echo "</td>";
echo "<tr>"."<td> <br> </td>"."</tr>";
echo "<td>";
echo " Add New Post Here <a href='http://localhost/Project/add_post.php'>Click Here.</a>";
echo "</td>";
echo "</tr>";
echo "</table>";
echo "<table border='0' >"; 

while($info = mysql_fetch_array( $data )) 
{ 
echo "<tr>"."<td><b>Title:</b></td> <td>".$info['title'] . "</td>"."</tr>"; 
echo "<tr>"."<td><b>Comment:</b></td> <td>".$info['comment'] . " </td>"."</tr>";
echo "<tr>"."<td><b>Authorname:</b></td> <td>".$info['authorname'] . " </td>"."</tr>";
echo "<tr>"."<td><b>Date:</b></td> <td>".$info['date'] . " </td>"."</tr>";
echo "<tr>"."<td> <br> </td>"."</tr>";
} 
echo "</table>"; 


?> 

Link to comment
Share on other sites

My mistake. I should have wrote owner in the WHERE clause, not blogID. :P

 

Also, be sure that you have actually created the owner field, before testing.

 

Fixed:

 

$owner = $_GET['blog'];

include "connect.php"; 

mysql_select_db("post_db")
or die ("Could not select database because ".mysql_error());

$data = mysql_query("SELECT * FROM textpost WHERE owner = '" . $owner . "' ORDER BY date desc limit 10") 
or die(mysql_error()); 
echo "<h3>"."Your recent blog post's"."<br/>"."</h3>";
echo "<table align='right'>";
echo "<tr>";
echo "<td>";
echo "Login Page <a href='loginpage.html'>Click Here.</a>";
echo "</td>";
echo "<tr>"."<td> <br> </td>"."</tr>";
echo "<td>";
echo " Add New Post Here <a href='http://localhost/Project/add_post.php'>Click Here.</a>";
echo "</td>";
echo "</tr>";
echo "</table>";
echo "<table border='0' >"; 

while($info = mysql_fetch_array( $data )) 
{ 
echo "<tr>"."<td><b>Title:</b></td> <td>".$info['title'] . "</td>"."</tr>"; 
echo "<tr>"."<td><b>Comment:</b></td> <td>".$info['comment'] . " </td>"."</tr>";
echo "<tr>"."<td><b>Authorname:</b></td> <td>".$info['authorname'] . " </td>"."</tr>";
echo "<tr>"."<td><b>Date:</b></td> <td>".$info['date'] . " </td>"."</tr>";
echo "<tr>"."<td> <br> </td>"."</tr>";
} 
echo "</table>"; 


?> 

I'm getting eror now :Could not insert data because Incorrect integer value: '' for column 'owner' at row 1.

 

My mysql table textpost include: id, title comment , authorname , date and owner! Should I set up owner as a primiary key now?because cannot be auto increment?

Link to comment
Share on other sites

Just set it to primary or index.

 

Don't make it autoincrement. I didn't say that, did I? For the posts that already exist, you will have to manually put the user ID's into the owner field (or write a script that does it for you).

 

For all new posts though, you just need to remember that you have to record the user id in the 'owner' field every time they're submitted.

I'm getting eror now :Could not insert data because Incorrect integer value: '' for column 'owner' at row 1.

 

Are you getting that error on the same script? We're not submitting any data right now. You're just trying to view it on this script.

Link to comment
Share on other sites

Just set it to primary or index.

 

Don't make it autoincrement. I didn't say that, did I? For the posts that already exist, you will have to manually put the user ID's into the owner field (or write a script that does it for you).

 

For all new posts though, you just need to remember that you have to record the user id in the 'owner' field every time they're submitted.

I'm getting eror now :Could not insert data because Incorrect integer value: '' for column 'owner' at row 1.

 

Are you getting that error on the same script? We're not submitting any data right now. You're just trying to view it on this script.

 

I'm getting error on different script.This is script which inserting new post.

..

I'm sorry I'm very tired and annoyed ;-) I working all day a then after work trying to get this working, Thanks for your help ,

 

1.How can I make this automatically?--> 'you will have to manually put the user ID's into the owner field (or write a script that does it for you).

 

2.How to record user id in the 'owner'? field every time I submit any new post.

 

This is my other script to add post:

<html>

<body>

      <br>

 

      <h3>Add Post</h3>

 

 

      <form method="post" action="insert.php">

 

      Title: <input name="title" size="20" maxlength="100">

 

      <br>

 

      Comment: <input name="comment" size="20" maxlength="100">

 

      <br>

 

  Authorname: <input name="authorname" size="20" maxlength="100">

 

  <br>

 

 

  <input name="date" type="hidden" value=NOW()>

 

  <input name="owner" type="hidden">

 

      <input type="submit" name="submit" value="Add Post">

 

      </form>

 

</body>

</html>

 

to insert post:

 

<?PHP

 

include "connect.php";

 

mysql_select_db("post_db")

or die ("Could not select database because ".mysql_error());

// insert the data

$insert=mysql_query("INSERT INTO $table values (NULL,'".$_POST['title']."','".$_POST['comment']."','".$_POST['authorname']."',now(),'".$_POST['owner']."')")

or die("Could not insert data because ".mysql_error());

// print a success message

echo "Your post has been added to adatabase! ";

header('Location: firstprint.php');

 

 

?>

 

This is probably very simple but I cannot get this into my head!!!!

 

Link to comment
Share on other sites

How do you store your user authentication? Do you have a cookie/session already that has the user's ID, or no?

 

If you don't have one already, how is it setup?

 

Typically, I'll set a cookie to have the user ID in it, then I just query the cookie up for something like this.

 

If don't though, you'll need to get whatever data from your user's field that is stored in your sessions/cookies. IE: if you're storing their usrename in a cookie. Then just create a query before the insert query to get the user's ID.

 

IE:

 

$results = array();
$sql = "SELECT * FROM users WHERE id = '".$_COOKIE['userid']."'";
$query = mysql_query($sql, $dblink) or die  ('Error: ' . mysql_error() );
while ( $row = mysql_fetch_array($query, MYSQL_ASSOC)) array_push($results, $row);

if ( count($results) == 1 )
$owner = $results[0][id];
else
die ("Error: Either that username doesn't exist, or there were multiple people using the same username");

 

Could be a lot simple though. I need to know how your authentication is setup. IE: stored values of sessions/cookies

Link to comment
Share on other sites

How do you store your user authentication? Do you have a cookie/session already that has the user's ID, or no?

 

If you don't have one already, how is it setup?

 

Typically, I'll set a cookie to have the user ID in it, then I just query the cookie up for something like this.

 

If don't though, you'll need to get whatever data from your user's field that is stored in your sessions/cookies. IE: if you're storing their usrename in a cookie. Then just create a query before the insert query to get the user's ID.

 

IE:

 

$results = array();
$sql = "SELECT * FROM users WHERE id = '".$_COOKIE['userid']."'";
$query = mysql_query($sql, $dblink) or die  ('Error: ' . mysql_error() );
while ( $row = mysql_fetch_array($query, MYSQL_ASSOC)) array_push($results, $row);

if ( count($results) == 1 )
$owner = $results[0][id];
else
die ("Error: Either that username doesn't exist, or there were multiple people using the same username");

 

Could be a lot simple though. I need to know how your authentication is setup. IE: stored values of sessions/cookies

 

I'm not using any sessions or cookies , It's my first project so I wanted to leave it for now as I didnt want to complicate anthing , I've table in mysql where username's and password's are stored , if new user I've registration form.

 

login.php:

 

<?php

session_start();

 

if (isset($_POST['txtusername']) && isset($_POST['txtpassword'])) {

// check if the user id and password combination is correct

if ($_POST['txtusername'] == 'admin' && $_POST['txtpassword'] == 'admin') {

// the user id and password match,

// set the session

$_SESSION['login'] = "Login";

// after login we move to the main page

header('Location: print.php');

exit;

} else {

 

include "connect.php";

 

mysql_select_db("post_db")

or die ("Could not select database because ".mysql_error());

 

$q = "SELECT * FROM $table1 WHERE txtusername='$txtusername' and txtpassword='$txtpassword'";

$result = mysql_query($q)or die (mysql_error());

$numrows=mysql_num_rows($result);

 

 

if($numrows==0){echo "Invalid User ..<a href='loginpage.html'>Please try again.</a>";}

 

  else {

 

echo $_POST['txtusername'];

//header('location: firstprint.php?blog=1');

//exit;

echo "  You are logged in successfully!<br><a href='http://localhost/Project/firstprint.php?blog=2'>Click Here.</a>";}

Link to comment
Share on other sites

How do you store your user authentication? Do you have a cookie/session already that has the user's ID, or no?

 

If you don't have one already, how is it setup?

 

Typically, I'll set a cookie to have the user ID in it, then I just query the cookie up for something like this.

 

If don't though, you'll need to get whatever data from your user's field that is stored in your sessions/cookies. IE: if you're storing their usrename in a cookie. Then just create a query before the insert query to get the user's ID.

 

IE:

 

$results = array();
$sql = "SELECT * FROM users WHERE id = '".$_COOKIE['userid']."'";
$query = mysql_query($sql, $dblink) or die  ('Error: ' . mysql_error() );
while ( $row = mysql_fetch_array($query, MYSQL_ASSOC)) array_push($results, $row);

if ( count($results) == 1 )
$owner = $results[0][id];
else
die ("Error: Either that username doesn't exist, or there were multiple people using the same username");

 

Could be a lot simple though. I need to know how your authentication is setup. IE: stored values of sessions/cookies

 

I'm not using any sessions or cookies , It's my first project so I wanted to leave it for now as I didnt want to complicate anthing  , I've table in mysql where username's and password's are stored , if new user I've registration form.

 

login.php:

 

<?php

session_start();

 

if (isset($_POST['txtusername']) && isset($_POST['txtpassword'])) {

// check if the user id and password combination is correct

if ($_POST['txtusername'] == 'admin' && $_POST['txtpassword'] == 'admin') {

// the user id and password match,

// set the session

$_SESSION['login'] = "Login";

// after login we move to the main page

header('Location: print.php');

exit;

} else {

 

include "connect.php";

 

mysql_select_db("post_db")

or die ("Could not select database because ".mysql_error());

 

$q = "SELECT * FROM $table1 WHERE txtusername='$txtusername' and txtpassword='$txtpassword'";

$result = mysql_query($q)or die (mysql_error());

$numrows=mysql_num_rows($result);

 

 

if($numrows==0){echo "Invalid User ..<a href='loginpage.html'>Please try again.</a>";}

 

  else {

 

echo $_POST['txtusername'];

//header('location: firstprint.php?blog=1');

//exit;

echo "  You are logged in successfully!<br><a href='http://localhost/Project/firstprint.php?blog=2'>Click Here.</a>";}

 

Hey, as long as I know I do not have to use any cookies or session , I just wanted to achieve this as simple as possible and then later on play aroung with the code, Is any simple way to achieve my aim?

Thank you very much.. :)

 

Link to comment
Share on other sites

You'll need an authentication cookie of some sort for this to work properly. Otherwise, there's no way to distinguish the users. :P

 

Without a way of distinguishing the users, this can't be done. I can briefly describe how to create and destroy cookies:

 


/* creating a cookie - set's $_COOKIE['username'] for 1 hour. The value will be the user's username, but in the example below is just "Peron's Username Here" */

setcookie ("username", "Person's Username Here", time() + 3600, "/", "yoursite.com", 1);

/* destroying a cookie - simply set the time to be less than the time allowed */

setcookie ("username", "Person's Username Here", time() - 3600, "/", "yoursite.com", 1);

 

See here for more info: http://us2.php.net/setcookie

 

I recommend you do some reading. It is a pain at first, but there's really not that much, and you'll learn a lot.

 

Also, see sessions: http://us2.php.net/manual/en/ref.session.php

 

Sessions you should learn to, as if used right, they can make your site more secure.

Link to comment
Share on other sites

Hey, as long as I know I do not have to use any cookies or session , I just wanted to achieve this as simple as possible and then later on play aroung with the code, Is any simple way to achieve my aim?

Thank you very much.. :)

 

A Simple Script usually means a horrible UI

so ya need some complexity in order to make it easier for the end user.

cookies and sessions arent hard.

but if ya looking at a simple script, a member blog area isnt recommended

cuz that means user authentication, which means if ya want to know its the same user navigating from page to page

u will either use a cookie or a session, or u can have em log in every page they navigate (like i said simple script usually means horrible ui)

 

so either make it into a personal blog, or try yer hand at user authentication.

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.