• 0

?action=action urls problem


Question

Blog I am making: http://adamb10.com/ub

What I am trying to do: Get urls like index.php?action=login

Well as you can see from the link above you will see a login box. Thats not supposed to be there. Infact besides the url/title bar, nothing else should be there.

http://www.adamb10.elixant.com/ub/index.php?action=login

Besides the screw you part, it works fine.

Time for the code I have. Index.php:

<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=ISO-8859-1">
 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
      <html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
<head>
<style type="text/css">
body { 
      background-color: #f1f1f1; 
      font-family: Arial, sans-serif; 
      font-size: 13px; 
      color: black; 
 } 
  
 input, textarea { 
      font-size: 9pt; 
 } 
  
 a:link, a:visited, a:active { 
      color: #007751; 
      text-decoration: none; 
 } 
  
 a:hover { 
      color: #007751; 
      text-decoration: underline; 
 } 
  
  
 .titlebg { 
      background-color: #e7efde; 
      font-size: 13px; 
 } 
  
 .windowbg { 
      background-color: #c6dbaf; 
      font-size: 13px; 
 } 
  
 .windowbg2 { 
      background-color: #f1f1f1; 
      font-size: 13px; 
 } 
  
 .border { 
      background-color: #94bd63; 
 } 
  
 .smalltext { 
      font-size: 11px; 
 }
</style>
<title>My ****ing test blog</title>

<p align=center>

<table width="80%" cellspacing="1" cellpadding="4" border="0" class="border">

<td class="windowbg2">

<font size="3">

<b>My Blog Title</b>

</font>

</td>

<tr>

<td class="windowbg2">

<a href="index.php"><img src="images/home.gif" align=left border="0"></a>
<a href="index.php?action=login"><img src="images/login.gif" align=center border="0"></a>
<img src="images/logout.gif" align=center>
<img src="images/profile.gif" align=center>
<img src="images/admin.gif" align=center>
</td>

</tr>

</table>


<?
include('sources/cases.php');
?>
</body>

</html>

Login.php:

<html>
<head>
<style type="text/css">
body { 
      background-color: #f1f1f1; 
      font-family: Arial, sans-serif; 
      font-size: 13px; 
      color: black; 
 } 
  
 input, textarea { 
      font-size: 9pt; 
 } 
  
 a:link, a:visited, a:active { 
      color: #007751; 
      text-decoration: none; 
 } 
  
 a:hover { 
      color: #007751; 
      text-decoration: underline; 
 } 
  
  
 .titlebg { 
      background-color: #e7efde; 
      font-size: 13px; 
 } 
  
 .windowbg { 
      background-color: #c6dbaf; 
      font-size: 13px; 
 } 
  
 .windowbg2 { 
      background-color: #f1f1f1; 
      font-size: 13px; 
 } 
  
 .border { 
      background-color: #94bd63; 
 } 
  
 .smalltext { 
      font-size: 11px; 
 }
</style>
<title>My ****ing test blog</title>
<p align=center>
<br>
<br>
<br>
<table width="80%" cellspacing="1" cellpadding="4" border="0" class="border">
<td class="windowbg2">
<font size="3">
Please login with your details below.
<br>
<FORM METHOD="POST" ACTION="sources/loginprocess.php">
Username: <input type="text" name="username">
<br>
Password: <input type="password" name="pass">
<br>
<input type="SUBMIT" value="Submit"> 
</form>
</td>
</table>
</body>
</html>

cases.php:

<?
include 'login.php';

switch ($_REQUEST['action'])
{
	case 'login':
   print "Hello and screw you.<br>";
	break;
}
?>

I plan on adding more actions in the future. So how can I stop the login box from being printed on index.php and get rid of the screw you thing on ?action=login?

Thanx!

Link to comment
Share on other sites

2 answers to this question

Recommended Posts

  • 0

Well your coding style is certainly orignal, like the fact that you create a HEAD tag but dont acctually close it (not to mention the fact that you close the BODY tag but you dont create it).

Well lets start from the top shall we, all your choices depend on the overall effect that you want to achive. I don't really know what your planned design looks like but you have to make a decision between using a single [template] page to display your information, or several differently designed pages. Since you are learning PHP I would suggest you use the template version becuase it offers you much more chance to get some real "hands on" experience with all the different functions in the language.

Personally, I would not have a seperate page for a login form but simply create an area on the site [perhaps in a side bar] that would contain it. You can use your existing form but you will need to strip everything apart from the form itself, so you can do a simple:

<?php

if ( !session_is_registered("username") ) {
   include("login.php");
} else {
   echo "Welcome Back __INSERT MYSQL USERNAME RESULT HERE__";
}

?>

You were also asking about the best way to include files using GET attributes (?action=blah). Well this is a little cut-down script i've used before. You will obviously have to change the "news.php" to a defualt page, whatever that may be in your case. But this script will include content from a file that matches the action string so for example:

index.php?action=hello

would include "hello.php" from the root directory.

<?php

if ( isset($_GET['action']) ) {
   if ( file_exists($_GET['action'] . ".php") ) {
      include($_GET['action'] . ".php");
   } else {
      include("news.php");
   }
} else {
   include("news.php"); 
}

?>

I may be going into too much detail, and I appologise for that. But I am just trying to make sure you head off in the right direction and don't faff about learning something that is basically never used in the real world.

If you need any more help I will gladly assist, and I really hope I haven't lost you anywhere, ps. I am sorry if my grammer\spellings is bad, its just it is late and I really can't face reading it again. :)

Link to comment
Share on other sites

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.