Jump to content

How to use ID and Cases?


FilipKrstic

Recommended Posts

I need to make page, which is order by id, and she need to has a cases?

 

For example... http://www.mysite.com/page.php?id=1 and I have "switch ($_REQUEST[alpha]) { case downloads: break; }"

 

Link for this `ll be http://www.mysite.com/page.php?id=1?alpha=downloads but that can`t....

 

Can someone help? Thanks a lot...

Link to comment
https://forums.phpfreaks.com/topic/139621-how-to-use-id-and-cases/
Share on other sites

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;
}

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;
}
?>

 

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...

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"; 
}
?>

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 ||?

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();
}
}

?>

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.