...

View Full Version : Always start at index



zoobie
09-19-2003, 12:05 AM
With pages all over the internet, my users need to come into my site on the index and not the middle. My $_SESSION starts on the index...What would you guys recommend? Example? Thanks

Spookster
09-19-2003, 12:17 AM
If you mean that people should only come to your site through the front page then you can easily do that using sessions.

On the front page just add a value to your session indicating they have visited the front page



<?php
session_start();
$_SESSION['frontPage'] = "true";
?>


Then on every page just check to see if that session variable exists and if it doesn't then send them to the front page:



<?php
session_start();
if(!isset($_SESSION['frontPage']))
header("Location: index.php");
?>

zoobie
09-19-2003, 02:55 AM
Ok...Thanks
Few more q's:
Shouldn't that if(!isset($_SESSION['frontPage'])) have a semi-colon on the end of it?
Also, my real index is up a level. Should I use header("Location: ../index.php"); or the full URL header("Location: http://site.com"); ?
This is for pages found in search engines.
Thanks :cool:

Nightfire
09-19-2003, 03:01 AM
Shouldn't that if(!isset($_SESSION['frontPage'])) have a semi-colon on the end of it?
No :) Underneath the if statement is the condition if the session is set

Should I use header("Location: ../index.php"); or the full URL header("Location: http://site.com"); ?
I don't think there's any difference, apart from a few extra characters in the script

mordred
09-19-2003, 03:52 AM
Better use an absolute address in the header() command, IIRC this is demanded by the HTTP specs. So using http://www.site.tld would always work, while the relative URLs are at the mercy of the client. Most browsers do resolve these relative locations though, but I can't speak for the googlebot.

zoobie
09-19-2003, 11:28 AM
Gotcha...Thanks all. :D



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum