Jump to content

[SOLVED] smart redirection, ned help


ekante

Recommended Posts

So the thing is i need to create manager/pilot web based sistem, where users register as manager or pilot. The whole idea is that when thay register in DB is there status pilot or manager.

concept:

*)user log's in

*)function check the status

*)page redirects him to pilots or manager control panel, where he is doing all his nececery things, stuff =D

*)but when he attempts to go in ther control page liek manager is going in pilots page , function is not redirecting  but just opening managers control panel again. But pilots and manager pages are different from each other.

 

Thing is , i have no clue how to write the code for function like that , i need some hints doing this , some advice ,and some sample code to understand youre idea.

 

Best regardrs.

Link to comment
Share on other sites

Problem is that i dont know how to write the code, so i didnt even start to write, because i dont know where to start.

 

but i think like this:

 

function userStatus() {

$query = "SELECT * FROM user WHERE userid = '$userid' ";
$result = mysql_query($query) or die(mysql_error());
$row = mysql_fetch_array($result);

if ($row['status'] = 'user') {

//dont know how the redirect code works

}
else if ($row['status'] = 'manager') {

//same

}
else if ($row['status'] = 'pilot') {

//same
}
}

Link to comment
Share on other sites

change your single '=' to double '==' .. you do this when checking against a value .. kind of like saying, "is equal to" .. a single = is like saying, "equals".

 

for redirection .. i bet if you typed 'php redirection' in google you'd have your problem solved already .. look into the header() function .. it's what you're going to need .. but, before using header(), look into how to use it, otherwise, you're going to get an error message along the lines of "Headers already sent...", and you're going to be right back here.

 

a simple header redirect would look something like this :

header("Location: http://www.mysite.com");
exit;

where mysite.com is your site.

Link to comment
Share on other sites

i have problem with header(), he allway sends me to 1.php when i type index.php?id= {random from 1-3}

 

<?php
/*$query = "SELECT * FROM user WHERE userid = '$userid' ";
$result = mysql_query($query) or die(mysql_error());
$row = mysql_fetch_array($result);*/

if ($id = 1) {

header("Location: http://localhost/1.php");

}
else if ($id =  2) {

header("Location: http://localhost/2.php");

}
else if ($id = 3) {

header("Location: http://localhost/3.php");
}

?>
<?php 
echo "you stay here";
?>

 

how can i do redirection or just "send" to another page anotherway, i think this is very silly way to do that, or in case there isnt tell me where im wrong.

Link to comment
Share on other sites

You most likely want to use include instead of a redirect, as redirects would mean 2 page requests opposed to one.

so something like one of the two examples below and then having the a user/manager/pilot  .php file in the same directory as the file with this code is in.

<?php
function userStatus() 
{
  $query = "SELECT * FROM user WHERE userid = '$userid' ";
  $result = mysql_query($query) or die(mysql_error());
  $row = mysql_fetch_array($result);

  if ($row['status'] == 'user') {
    include( 'user.php' );
  }
  else if ($row['status'] == 'manager') {
    include( 'manager.php' );
  }
  else if ($row['status'] == 'pilot') {
    include( 'pilot.php' );
  }
}
?>

 

Alternatively use:

<?php
function userStatus() 
{
  $query = "SELECT * FROM user WHERE userid = '$userid' ";
  $result = mysql_query($query) or die(mysql_error());
  $row = mysql_fetch_array($result);
  
  switch( $row['status'] )
  {
    case 'user':
    case 'manager':
    case 'pilot':
      include( $row['status'].'.php' );
  }
}
?>

2nd example is easier to maintain, but might be harder to read to you.. go with whatever you feel comfortable with.

 

Link to comment
Share on other sites

Thanks guys here is simple code for (localhost/index.php?id=1 or 2 or 3):

 

<?php
/*$query = "SELECT * FROM user WHERE userid = '$userid' ";
$result = mysql_query($query) or die(mysql_error());
$row = mysql_fetch_array($result);*/
$_GET['id'];


  /*$query = "SELECT * FROM user WHERE userid = '$userid' ";
  $result = mysql_query($query) or die(mysql_error());
  $row = mysql_fetch_array($result);*/

  if ($id = 1) {
    include( '1.php' );
  }
  else if ($id = 2) {
    include( '2.php' );
  }
  else if ($id = 3) {
    include( '3.php' );
  }

?>

 

I got what i wanted thanks.

 

Best regards.

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.