Jump to content

if statement within an if statement?!? **SOLVED**


Recommended Posts

Hello,
Does anybody know if this piece of code will work as I don't want to change the actual page until I am more sure.

[code]<?php
#get variables
$st_id = $_GET['st_id'];
$mo_id = $_GET['mo_id'];

#create cookies and relocate
if( ( $st_id !=null ) and ( $mo_id !=null ) )
{
               if ( $st_id = '%'"."'%' )
{
header ( "Location:satff.php" );
}
else
setcookie("st_id",$st_id);
setcookie("mo_id", $mo_id);
header ( "Location:details.php" );
}
else
{ header ( "Location:http://resource/view.php?inpopup=true" );
exit();
}
?>[/code]

I want it to firstly check to see if there are values in both $st_id and $mo_id, if not relocate to:-
Location:http://resource/view.php?inpopup=true&id=2916

If there is. then check to see if $st_id is any value with an . in it, if it has a fullstop in it then locate to staff_login, if it doesnt then set some cookies and locate to the personal pages.

The idea is that users are sent from the main login page, standard users have unique numerical login number coupled with part of their surname e.g. 12345678SUR, whereas a staff member has a different format e.g. 1234.SUR. I want it to check if its a staff login or a normal user and locate them to specific pages.

So can I use % as a wildcard?
Is the code correct?

Many Thanks

It's an sql thing. It may have worked. lol.
One problem I forgot to mention is that the fullstop can change position within the staff number eg. could be 1234.sur and another could be 12345.sur, which is why I was looking for a wildcard solution.

but cheers I'll check out strpos
Ok I have this.
Am I on the right track?

[code]<?php

#get variables
$st_id = $_GET['st_id'];
$mo_id = $_GET['mo_id'];
$findme  = '.';
$pos = strpos($st_id, $findme);

#create cookies and relocate
if( ( $st_id !=null ) and ( $mo_id !=null ) )
{
if ($pos === false)
{
  setcookie("st_id",$st_id);
setcookie("mo_id", $mo_id);
header ( "Location:pages/personal_details.php" );
}
else
{
  header ( "Location:staff/satff_login.php" );
}
else
{
header ( "Location:http://resource/view.php?inpopup=true&id=2916" );
exit();
}

?>[/code]

Cheers
problem... you have two else statements...

[code]
if(( $st_id !=null ) and ($mo_id !=null)){
if($pos === false){
  setcookie("st_id",$st_id);
  setcookie("mo_id", $mo_id);
  header("Location:pages/personal_details.php");
}else{ #this should be an elseif()
  header("Location:staff/satff_login.php");
}else{ #this is the second
  header("Location:http://resource/view.php?inpopup=true&id=2916");
  exit();
}
}# you also forgot this...
[/code]
Cheers Taith,
I've now got this but it still doesn't work properly, if its a standard user logging in then it works and sends them to the correct page, but if its a staff member eg a login with a fullstop in the name then it doesnt work??
I'm not really familiar with the elseif statement.
Is this on the right lines?

[code]#get variables
$st_id = $_GET['st_id'];
$mo_id = $_GET['mo_id'];
$findme  = '.';
$pos = strpos($st_id, $findme);

#create cookies and relocate
if(( $st_id !=null ) and ($mo_id !=null))
{
if($pos === false)
{
  setcookie("st_id",$st_id);
  setcookie("mo_id", $mo_id);
  header("Location:personal.php");
}
  elseif($pos === true)
{
  header("Location:staff.php");
}
else
{  header("Location:http://resource/view.php?inpopup=true");
  exit(); }
}[/code]

Cheers
Hello all,

I have managed to get it to work in a way that I think is a little strange.

I changed
elseif($pos === true)
for
elseif($pos == true) and it works

but if I change
if($pos === false)
to
if($pos == false) it stops working again?

whats the real difference between == and ===

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