Jump to content

Recommended Posts

QUESTION ONE:
I can do simple things like this:
session_start();

$username = $_SESSION['username'];

and then do say if($username){ and that basically means if they are logged in, i want to do if NOT LOGGED In. how would I do this?

QUESTION TWO:
I want to know how to make a form redirect someplace after it executes the query, I have this script:
[code=php:0]
if(isset($_POST['submit']) && !empty($_POST['password']) && !empty($_POST['cpassword']))
{


$password = $_POST['password'];
$cpassword = $_POST['cpassword'];

if($password!=$cpassword)
{
echo "Passwords do not match.";
}

$securepass = base64_encode($password);

$sql2 = "UPDATE admins SET password = '$securepass' WHERE username = '$username'";
$sqlr2 = mysql_query($sql2) or die(mysql_error());

}
?>
<form action="editpass.php" method="POST">
New Password:
<input type="password" name="password" />
<br />
New Password again:
<input type="password" name="cpassword" />
<Br />
<input type="submit" name="submit" value="Submit" />
</form>
[/code]

Can someone post back that script having it redirect to logout.php after the query is executed?

QUESTION THREE:
I have a news and download system, both use POST and are fairly simple, I need to have edit and delete functions for each one, they obviously have their own unique ID. I know it is probably fairly easy to do I have just never seen the code for it. so im assuming it would do something like this:

fetch array to fetch id for each post, usign a while statement to link to deletenews.php?id=$id uniquely, etc etc. although probably a bit different for edit, using update table set.

anyway if anyone could point me to a good tutorial for question three it would be much appreciated.

anyone taking the time to read this and able to answer at least 1 question, very much appreciated and rep will be given.

thanks

ONE:

[code=php:0]if(!$username)[/code]


TWO:

2 options: JavaScript way: [code=php:0]<body onLoad="me.location("logout.php");">[/code]

or PHP way:
[code=php:0]
header("Location: http://www.uscript.com/logout.php");
[/code]

THREE:

I never actually delete anything from my database unless I really, really need to. Fact is, sometimes we delete things and we really don't mean to, even after we press YES I REALLY MEAN TO button. I normally add a status field, and if the status is set to some number like 2, then I wont display it, but if it's set to 1 or something else, I will display it.

As for editing, you would use a SELECT statement to populate your normal addpost form with the data, then

[code=php:0]UPDATE posts SET title = 'some here' and body = 'some more here' WHERE postID = $id[/code]


Hope that helps.. :)
hi localhost,

2)  as keeB, has pointed out, you can use the above two methods. i just want to remind you if you already know about working with header, then this is of no use for you,.

Make sure that no code should be executed before the header command.It means no echo statements, no blank spaces or no html output should come before the header statement.


cheers
sai

[quote author=keeB link=topic=100274.msg395578#msg395578 date=1152683332]
2 options: JavaScript way: [code=php:0]<body onLoad="me.location("logout.php");">[/code]
[/quote]

Then you are breaking the back button. When/if people click on the back button, then they will immediately get forward again. The header way is to prefer, since the page don't finish loading, but go to the new location as soon as it meets the Location header.
please, someone modify this script so it immediately redirects to index.php if logged in successfully!

[code=php:0]
<?php
session_start();
include('../connect.php');
$username = $_SESSION['username'];


$ip = $_SERVER['REMOTE_ADDR'];
$date = date("M d, Y");
$hitadd= MYSQL_QUERY("INSERT INTO stats(date, ip)".
"VALUES ('$date', '$ip')");

$date = date("M d, Y");
$uniquea = mysql_query("SELECT DISTINCT ip FROM stats");
$uniqueb = mysql_num_rows($uniquea);
$tdayua = mysql_query("SELECT DISTINCT ip FROM stats WHERE date = '$date'");
$tdayub = mysql_num_rows($tdayua);
$hitsa = mysql_query("SELECT * from stats");
$hitsb = mysql_num_rows($hitsa);
$tdayhitsa = mysql_query("SELECT * from stats where date = '$date'");
$tdayhitsb = mysql_num_rows($tdayhitsa);

?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<link rel="stylesheet" type="text/css" href="../default.css" />

<title>uScript - Home</title></head>

<body>
<div class="header"><a href="index.php"><img src="../images/logo.png" alt="LOGO PLACEHOLDER" width="172" height="52" border="0" /></a></div>
<div class="sidebar">
<div class="subheading"><strong>Navigation</strong></div>
<div class="sidebarcontent">
<?php
if($username) { echo "
<p><a href=\"index.php\">Home</a></p>
<p><a href=\"news.php\">News</a></p>
<p><a href=\"downloads.php\">Downloads</a></p>
<p><a href=\"features.php\">Features</a></p>
<p><a href=\"changelog.php\">Changelog</a></p>
<p><A href=\"support.php\">Support</A></p>
<p><a href=\"forums/\">Forums</a></p>
<p><A href=\"staff.php\">Staff</A></p>
<p><a href=\"admin/\">ADMIN PANEL</a></p>
<p><a href=\"admin/logout.php\">Logout</a></p>";
} else {
echo "
<p><a href=\"index.php\">Home</a></p>
<p><a href=\"news.php\">News</a></p>
<p><a href=\"downloads.php\">Downloads</a></p>
<p><a href=\"features.php\">Features</a></p>
<p><a href=\"changelog.php\">Changelog</a></p>
<p><A href=\"support.php\">Support</A></p>
<p><a href=\"forums/\">Forums</a></p>
<p><A href=\"staff.php\">Staff</A></p>";
}
?>
</div>
        <div class="subheading" style="margin-top:2px;"><strong>Statistics</strong></div>
        <div class="sidebarcontent">
          <p>
  Hits:<?php echo " $hitsb  <br />

Hits Today: $tdayhitsb <br />
Unique Hits: $uniqueb<br />
Unique Today: $tdayub <br />
Articles: ";?><?php

$query = mysql_query("SELECT * FROM news") or die(mysql_error());
$numrows = mysql_num_rows($query);

echo "$numrows"; ?><br />
          </p>
  </div>

        <div class="subheading" style="margin-top:2px;"></div>
</div>
<div class="content" style="margin-bottom:8px;">
  <div class="newsheading">
    <p><strong>Administrative Login </strong></p>
      </div>

  <div class="newsarticle">
    <form action="login.php" method="POST">
          <div align="center">
            <p>
              <input type="text" name="username" value="Username" onFocus="this.value=''" />
              <br />
              <input type="password" name="password" value="Password" onFocus="this.value=''" />
              <br />
              <input type="submit" name="submit" value="Login" />
  <br />
  <?php


include('../connect.php');

if ($_POST['username']) {
$username=$_POST['username'];
$password=md5($_POST['password']);
if ($password==NULL) {
echo "<font face='verdana' size='2'>No password given.";
}else{
$query = mysql_query("SELECT username,password FROM admins WHERE username = '$username'") or die(mysql_error());
$data = mysql_fetch_array($query);
if($data['password'] != $password) {
echo "Incorrect login, try again.";
}else{
$query = mysql_query("SELECT username,password FROM admins WHERE username = '$username'") or die(mysql_error());
$row = mysql_fetch_array($query);
$_SESSION["username"] = $row['username'];
echo "thanks for loggin in. <a href=../index.php>home</a>";
}
}
}
?>
            </p>
            <p>&nbsp;              </p>
          </div>
    </form>
    </div>
</div>

<Font size="1"><center>
  <p>Copyright &copy;2006 <a href="http://uscript.org">uScript.org</a> - All Rights Reserved</p>
  <p>uScript is Free Software released under the GNU/GPL License. </p>
</center></Font>

[/code]
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.