Web Hosting Talk







View Full Version : PHP Support Needed. Fast! (Simple?)


CircuitHost
11-12-2005, 07:51 PM
PHP Support Needed. Fast! (Simple?)

-- Is it possible to have two of the following tags on the same page?


header('Location: ../page.php')


Example;
IF not logged in I use header to send back to the login page.
IF page = 123 then I redirect to abc.

All in the same file.

Is that possible or is there another way to redirect or NOT show the content?

Tree NC
11-12-2005, 07:59 PM
Using a meta redirect has the same effect. Although not W3C complaint, it does work.

<?
if (!empty($_SESSION['sessionVariable']))
{?>
<meta http-equiv="refresh" content="0; url=../page.php">
<?}
else
{
?>
<meta http-equiv="refresh" content="0; url=../login.php">
<? } ?>

MonteCarloHosting
11-12-2005, 08:06 PM
You could also do it as simple as this:


<?php
if(!empty($_SESSION['sessionvar']))
{
//user is logged in...
header("Location: /path/to/logged/in/file");
}
else
{
header("Location: /some/other/page.php");
}
?>


Regards,
Christian

CircuitHost
11-12-2005, 08:34 PM
I was really looking for a possible way to not display the content, or use the header to redirect while the other header was still in the file.

But thank you for your help.

Any more help will be appriciated too!

localhost127
11-12-2005, 09:23 PM
I dont seem to understand what you are trying to do...

You want to move them to a different page if they're not logged in, but if they are logged in then display the content on the current page?

Can you explain it a little better?

Mr.X
11-12-2005, 09:37 PM
I was really looking for a possible way to not display the content, or use the header to redirect while the other header was still in the file.

But thank you for your help.

Any more help will be appriciated too!

As far as i see the information givin here is correct , but still unsure what you mean by "to not display the content" .

Tree NC
11-12-2005, 10:01 PM
I'm not sure what you're aking for either :S

CircuitHost
11-13-2005, 01:07 AM
Is it possible;

If the page = home, make it so it will not display the content?

localhost127
11-13-2005, 01:34 AM
You mean if the page is home but they are NOT logged in?

Sounds like something that could be easily fixed with an if/else statement

Burhan
11-13-2005, 02:42 AM
Please always pass the full URL to Location: -- not just the relative URL. It may work, but it is not the correct way to use that header.

Tree NC
11-13-2005, 06:43 PM
You would need to make a header and footer file, and then have a code like this:

<?php
switch ($page) {
case "":
case "index":
include "header.php";
include "home.php";
include "footer.php";
break;
default:
include "header.php";
include $page;
include "footer.php";
break;
}
?>

If I understand what you want, that is...

CircuitHost
11-13-2005, 09:54 PM
Board Closed.

Thank you all for your help! :)