Jump to content

Recommended Posts

Hello,

 

Well, i need little help :) I made a small contacting us system, all is done, reading, writing, moderation. But for moderation I need help :) I mean I don't have any experiance with Cookie or Session. And I don't know, what I have to use :(

 

But I would try to explain. There is a file called moderation.php and when it hits the page, It uses an if() statement and when it's not true, it gives a Small Form with a box called Password. So please have a look on this code thanks ;)

 

<?php
$pass = $_POST["password"];
$form = "<form method=\"post\" action=\"moderation.php\">
<p align=\"center\"> Password <input name=\"password\" type=\"text\" size=\"5\"></p>
<p align=\"center\"> <input name=\"submit\" type=\"submit\" value=\"submit\">
</form>";


if($pass = my_password)
{

//does all moderation task.............

}
else
{
echo $form;
}
?>

 

Well, But What I need is when ever in moderation it require to valid the password, It automatically takes the cookie from my Browser memory and do the task, and if the cookie is not available, it will just show the $form and when the password is inserted, it will insert the cookie and continue script work.

 

Well, Why do i need this? Well. Before my moderation was only used to read the users query for contact, but now I have a new thing, Deleting the queries as well, And When I try to delete it asks for validating password, again and again and can't continue.

 

Thanks  alot dear, your help would be very helpful for me. Badly waiting for answer :)

 

FAISAL!

Link to comment
https://forums.phpfreaks.com/topic/105583-cookie-or-session-dont-know-exactly/
Share on other sites

heres a little untested example

 

hope it helps

 

<?php
session_start(); //need this at the start

$pass = $_POST["password"];
$form = "<form method=\"post\" action=\"moderation.php\">
<p align=\"center\"> Password <input name=\"password\" type=\"text\" size=\"5\"></p>
<p align=\"center\"> <input name=\"submit\" type=\"submit\" value=\"submit\">
</form>";

if(isset($_GET['logoff']))
{
$_SESSION['Access'] == ""; //remove the admin value
session_destroy(); //kill the session
}

if($pass = "my_password")
{
$_SESSION['Access'] == "Admin"; //set value for use laster
}

if(isset($_SESSION['Access']) && $_SESSION['Access'] == "Admin")
{
echo "Welcome Admin!<br>";
echo "<a href='?logoff'>Logoff</a>";
}else{
echo "Welcome Guest";
}

?>
<a href="page2.php">page2.php</a>

 

 

<?php
session_start(); //need this at the start
//$_SESSION['Access'] is still valid from the other page
if(isset($_SESSION['Access']) && $_SESSION['Access'] == "Admin")
{
echo "Welcome Admin!";
}else{
echo "Welcome guest";
}

?>

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.