Jump to content

need an advice on how to continue !


lofaifa

Recommended Posts

for example :

 

when i open a session .. should i always write pages for user like this :

 

<?php

session_start();

if(isset($_SESSION["user_name"]) && isset($_SESSION["user_password"])){

  echo  "<html>";

      echo "<head>";

      echo "<title>Profile Page </title>";

      echo "</head>";

 

      echo "<body>";

      echo "Welcome ".$_SESSION['user_name'] . " !<br/><br/>" ;

      echo "<br />";

  echo '<a href="add_info.php">Add New informations</a><br/><br/>';

  echo '<a href="edit_profile.php">Edit you Profile</a><br/><br/>';

      echo '<a href="logout.php">Logout</a>'; 

else {

      echo "you didnt login yet !!.<br/><br/>";

  echo '<a href="main.php">Go Back </a>';

      echo "</body>";

  echo "</html>";

?>

 

---------------------------------

 

<?php require_once("includes/connection.php");?>

<?php require_once("includes/functions.php");?>

<? session_start();

if(isset($_SESSION["user_name"]) AND isset($_SESSION["user_password"])){

echo '<html>';

echo '<head>';

echo '<title>Editting Page</title>';

echo '</head>';

echo '<body>';

echo '<form action="edit_pro.php" method="post">';

echo '<p>';

echo 'Edit Name : <input type="text" name="new_name" value="" id="new_name" />';

echo '<br/><br/>';

echo 'Edit Password: <input type="password" name="new_password" value="" id="new_password"/>';

echo '</p>';

echo '<input value="Change Now" type="submit" />';

echo '<a href="welcome.php"> Or Go back </a>';

echo '</form>';

echo '</body>';

echo '</html>';

}

?>

 

---------------------------------------

 

<?php require_once("includes/functions.php");?>

<?php session_start();

if(isset($_SESSION["user_name"]) AND isset($_SESSION["user_password"])){

echo '<html>';

echo '<head>';

echo '<title>Set INFO</title>';

echo '</head>';

echo '<body>';

echo 'Here u can post more info :<br/><br/>';

echo '<form action="add_pro.php" method="post">';

echo 'Your Name : <input type="text" name="user_rname" value="" id="user_rname" /><br/><br/>';

echo 'country :  <input type="text" name="user_country" value="" id="user_country" /><br/><br/>';

echo 'Name of Your blog :  <input type="text" name="user_blog" value="" id="user_blog" /><br/><br/>';

echo '<input value="Add info" type="submit" /><br/><br/> ';

echo '<a href="welcome.php">To go Back </a><br/><br/>';

echo '</form>';

echo '</body>';

echo '</html>';

}

?>

 

 

I'm kind of new to sessions myself but why session['password'] ?

You just need the users password at the time of login

 

You show that they have a profile and they are editing something, do they have an id#, is user_name unique?

 

I'm writing from memory, this is basically how I would do it.

 

if  (id_profile == $_SESSION['id_profile']) {

allow edit

} else {

kick them to the curb

}

 

you can get id_profile with a $_GET for the above or

 

have a profile.php page and have

 

if ($_SESSION['id_profile'])  {

$query = "SELECT this, that FROM table WHERE id_profile = $_SESSION['id_profile']";

 

Display all the their stuff here

 

} else {

redirect or something

}

but i have another question .. soo this is the general way how websites with users registred works ??

and is there any better way to write an HTML page under a php tag without a lot of echo s !?

 

Yes and

 



<?php if (isset($_SESSION["user_name"]) { ?>
<html>
<head>
<title>Set INFO</title>
</head>
<body>
Here u can post more info :<br/><br/>
<form action="add_pro.php" method="post">
Your Name : <input type="text" name="user_rname" value="" id="user_rname" /><br/><br/>
country :  <input type="text" name="user_country" value="" id="user_country" /><br/><br/>
'Name of Your blog :  <input type="text" name="user_blog" value="" id="user_blog" /><br/><br/>
<input value="Add info" type="submit" /><br/><br/>
<a href="welcome.php">To go Back </a><br/><br/>
</form>
</body>
</html>
<?php } else {
redirect or what ever
} ?>

 

or

<?php if (isset($_SESSION["user_name"]) {
echo '<html>
<head>
<title>Set INFO</title>
</head>
<body>
Here u can post more info :<br/><br/>
<form action="add_pro.php" method="post">
Your Name : <input type="text" name="user_rname" value="" id="user_rname" /><br/><br/>
country :  <input type="text" name="user_country" value="" id="user_country" /><br/><br/>
Name of Your blog :  <input type="text" name="user_blog" value="" id="user_blog" /><br/><br/>
<input value="Add info" type="submit" /><br/><br/>
<a href="welcome.php">To go Back </a><br/><br/>
</form>
</body>
</html>';

} else {
redirect or what ever
} ?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.