Jump to content

How to use ID and Cases?


FilipKrstic

Recommended Posts

You first need to fix what premiso mentioned, but something like this?

 

$i = $_GET['id'];

switch ($i) {
    case 0:
        echo "i equals 0";
        break;
    case 1:
        echo "i equals 1";
        break;
    case 2:
        echo "i equals 2";
        break;
}

Link to comment
Share on other sites

Same with strings...  Look in the manual...

 

"http://www.mysite.com/page.php?id=1&alpha=downloads"

 

$i = $_GET['alpha'];

switch ($i) {
    case "downloads":
        echo "Yay!  downloads";
        break;
    case "uploads":
        echo "uploads";
        break;
}
?>

 

Link to comment
Share on other sites

Huh, guys many helpful informations.. Amazing...  ::)

 

I have one more question, and I can start with writing...

 

I have two sessions... Session $_SESSION[username] and $_SESSION[mcp]. At the start I have classic if...

 

session_start();
require_once("../config.php");

// Check his status.
if (!empty($_SESSION[mcp]) or ($_SESSION[username]))
{
// There is place where I need to put loggin function...
}
else // bad info
{
echo "Need to login first";
}

 

And I don`t how to make fuction logged? "if user logged as $_SESSION[username] print Welcome $_SESSION[username] or if logged as $_SESSION[mcp] print Welcome $_SESSION[mcp]" ???

 

P.S I`m php starter...

Link to comment
Share on other sites

session_start();
require_once("../config.php");

if(isset($_SESSION['mcp']) || isset($_SESSIONS['username' ) {
  echo "Welcome " . $_SESSIONS['username'] . "
";
  echo "What is mcp? " . $_SESSIONS['mcp'] . "
";
} else {
  echo "Need to login first"; 
}
?>

Link to comment
Share on other sites

When I try this peace of code, and when I login as $_SESSION[username], server shows me: "Need to login first", missing _$SESSION[bla] OR _$SESSION_[blabla]...

 

Maybe:

<?php
session_start();
require_once("../config.php");

// Check his status.
if (isset($_SESSION[mcp]) or isset($_SESSION[username]))
{
?>

?

What is ||?

Link to comment
Share on other sites

Here we are...

 

Session username is session for admin and mcp is session for moderator_control_panel. And I want make that the admin can come in mcp with his login (with his session). That is the reason why I put OR.

Informations about $_SESSIONS['username'] comes from mysql, table admins, and $_SESSIONS['mcp'] from mysql too, table mods...

 

Code for mcp page...

<?php
session_start();
require_once("../config.php");

// Check his status.
if (!empty($_SESSION[mcp]) or ($_SESSION[username]))
{
// MOD AREA
}
else // bad info
{
   echo "Need to login first";
}
?>

 

Login page...

<?php
session_start();
// Check if he wants to login:
if (!empty($_POST[mcp]))
{
require_once("../config.php");

// Check if he has the right info.
$query = mysql_query("SELECT * FROM mods
						WHERE username = '$_POST[mcp]'
						AND password = '$_POST[password]'")
or die ("<Wrong username or password");

$row = mysql_fetch_array($query)
or die ("Wrong username or password");

if (!empty($row[username])) // he got it.
{
	$_SESSION[mcp] = $row[username];
	echo "Success";
	exit();
}
else // bad info.
{
	echo "Please login";
	exit();
}
}

?>

 

Link to comment
Share on other sites

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.