Always view intro with PHP

bigjoe4

New Member
Messages
907
Reaction score
0
Points
0
I am trying to make my website (http://idesigncircuit4u.exofire.net/) so that visitors must view the intro page before they view the other pages, so that if they try to view one of the other pages first they will be re-directed to the intro.

This is the code I tried to use:

Code:
On top of the main page

PHP Code:
<?php
session_start();
$_SESSION['main'] = 1;
?> 

On top of all the other pages

PHP Code:
<?php
session_start();
if (!isset($_SESSION['main'])) {
   header("http://www.sitename.com/index.php");
   exit();
}
?>

This does not work. Am I using PHP wrong or do I need to upgrade my PHP version, or is there some other way to do this? Thanks in advance.
 

hatbocs

New Member
Messages
62
Reaction score
0
Points
0
Doing a little more digging this may work:

On main page:
PHP:
<?php
session_start();
if (!isset($_SESSION['main'])) {
$_SESSION['main'] = 1;
}
?>

On the other pages (make sure this is the very first thing in the php file):
PHP:
<?php
session_start();
if (!isset($_SESSION['main'])) {
header('Location: http://idesigncircuit4u.exofire.net/');
exit;
}
?>

I don't know how well it works, but it's worth a shot, I suppose.
 
Last edited:

bigjoe4

New Member
Messages
907
Reaction score
0
Points
0
Thanks I will try it :) :) :)
Edit:
Nope I tried it, it does not work, I have requested an upgrade to PHP2 and it has heen accepted I just have to wait a couple of hous until it takes effect. maybe this will make it work.
 
Last edited:

hatbocs

New Member
Messages
62
Reaction score
0
Points
0
Oh, yes, it could be that the header() function isn't allowed in the basic version.
 

VPmase

New Member
Messages
914
Reaction score
1
Points
0
The javascript route.

PHP:
<?php
session_start();
if (!isset($_SESSION['main'])) {
echo "<script type=\"text/javascript\">window.location = \"YOUR SITE HERE!\";</script>";
}
?>
 
Last edited:

sunils

New Member
Messages
2,266
Reaction score
0
Points
0
Yes use the javascript.
The header function will not work sometimes saying it should be the first statement in the file.

so here is my version for other page tops.

PHP:
 <?php
session_start();
if (!isset($_SESSION['main'])) 
{
?>
   <script language="javascript" type="text/javascript">
         location= "http://idesigncircuit4u.exofire.net/";
   </script>
<?
}
?>
 

bigjoe4

New Member
Messages
907
Reaction score
0
Points
0
Yes use the javascript.
The header function will not work sometimes saying it should be the first statement in the file.

so here is my version for other page tops.

PHP:
 <?php
session_start();
if (!isset($_SESSION['main'])) 
{
?>
   <script language="javascript" type="text/javascript">
         location= "http://idesigncircuit4u.exofire.net/";
   </script>
<?
}
?>

OK so what code do I put on the main page? Thanks.
 
Last edited:

Synkc

Active Member
Messages
1,765
Reaction score
0
Points
36
That approach will only work if the end-user's browser is both compatible with JavaScript, and has it enabled.

The best way to go would be with the PHP header() function. I can't see how the suggested code in your first post could not work; do you mind posting the error message you get?
 
Last edited:

bigjoe4

New Member
Messages
907
Reaction score
0
Points
0
No error message, just nothing happened, but I will try again, perhaps I typed a spelling mistake or something.
Edit:
Nope, still nothing happens, there must be something I am doing wrong, I don't know much about PHP.
 
Last edited:

Synkc

Active Member
Messages
1,765
Reaction score
0
Points
36
Are you sure your adding the code correctly, and that the files have the extension ".php"? I just tested it on my local web server and it worked perfectly.


Edit:

Never mind that, I just noticed your problem.

Replace the header function with:

header("location:http://www.sitename.com/index.php");
 
Last edited:

bigjoe4

New Member
Messages
907
Reaction score
0
Points
0
Thanks, Synkc, it works now :). I have sent 50 credits + Rep as payment :) :) :)
 
Last edited:
Top