The list of all PHP and Mysql posts

The first page of a forum

Index page (first page) in a forum just contains a bunch of links that redirect the user to different forum topics but if we want just registered users can see the posts in the topics so we should add some php for this purpose.(http://webprogram4beginners.blogspot.com/2011/02/redirect-user-to-login-page-sessions.html)

These are the pure codes (without format) that I have written for the first page of a forum.(put them in a file and rename it to "index.php")
You can see a sample of these codes online here :
http://story-world.99k.org/
http://vahid9224two.zxq.net/index.php


code:
<?php
session_start();
if(isset($_SESSION["auth_usr"])){
 echo "<p><a href=\"logout.php\">log out</a></p>";
}else{
 echo "<p><a href=\"login.php\">log in</a></p>";
 $_SESSION["d"] = "index.php";
}
?>
<br>
place of menu bar
<br>
<br>
// some explanation about my website.
Our website is place to find codes and sources of Flash Mx , PHP , MYSQL and website templates
to help you develope your skills.
Here, You can upload your interesting works and codes to help other friends development and show your
abilities to the others.
Please read our policy and copywrite rules about the things that you can upload.
<br>
<br>

// some links to different topics on the forum.
<a href="main_flash.php">FLASH MX and FLA FILES</a>
<br>
<a href="main_web.php">PHP , MYSQL CODES and WEBSITE DESIGN MATERIALS</a>
<br>
<a href="about.php">ABOUT US and CONTACT</a>
<br>
<a href="search.php">Search</a>
<br>


When this page is loaded if user hasn't login yet , the link of  "log in" would be shown , otherwise , the link of "log out" would appear and the index page address is saved in a session in order to be used if the user click on login link.(to redirect the user to the index page once again after login) :

$_SESSION["d"] = "index.php";

There is a point about echo order here :

echo "<p><a href=\"logout.php\">log out</a></p>";

We want to show this HTML codes by echo order :

<p><a href="logout.php">log out</a></p>

But   "   is a special character for echo and to echo it you should use  \"  instead.

If you changed this codes with Frontpage to make it beautiful , don't forget to uploud the hidden files (that are created by Frontpage) to the server unless many of the objects such as menu bar would not be shown by the server.

No comments:

Post a Comment