Jump to content

Recommended Posts

I have something which I find quite interesting. Till now I have yet to find any answers or anything which is close or even resembles what I really need.

 

This is basically what I have...

 

Page 1 --> Page 2 --> Page 3 --> Page 4

 

My problem is how do I make it in such a way that someone needs to actually go to Page 1 before going to Page 2, 3 or 4? Is there a way to actually do this? I would appericiate it if someone could help tell me what I could do to get this going.

 

Thank you very much.

Link to comment
https://forums.phpfreaks.com/topic/119656-php-page-security-help/
Share on other sites

An example:

<?php
session_start();

// set our variables, if they are not set we'll set a defaul value.
$_SESSION['pageN'] = isset($_SESSION['pageN']) ? $_SESSION['pageN'] : 1;
$page              = isset($_GET['page'])      ? $_GET['page']      : 1;

// check to see if the pageN session matches the requested page
if($_SESSION['pageN'] == $page)
{
    $_SESSION['pageN']++;

    echo '<h1>Page' . $page . '</h1>';
}
// page does not match, redirect user
else
{
    unset($_SESSION['pageN']);
    header('Location: test.php');
}

?>
<a href="?page=1">Page 1</a><br />
<a href="?page=2">Page 2</a><br />
<a href="?page=3">Page 3</a><br />
<a href="?page=4">Page 4</a><br />

Try going to 2, 3 or 4 first and you'll go back to 1.

As much as I would say "yes" to it, I seem to be having some problem with Sessions.

 

Warning: session_start() [function.session-start]: Cannot send session cookie - headers already sent by....

 

Not sure what's wrong at all.

 

In my entire page, I have nothing else other than a few JavaScripts and a Form in HTML. Not even sure what's wrong at all.

 

Can someone help? :(

session_start must be called before any output, eg

 

<?php session_start(); ?>
.... your html ...
<?php

// rest of your PHP

?>
.. more html

 

It cannot be

.... your html ...
<?php
session_start();

// rest of your PHP

?>
.. more html

As much as I would say "yes" to it, I seem to be having some problem with Sessions.

 

Warning: session_start() [function.session-start]: Cannot send session cookie - headers already sent by....

 

Not sure what's wrong at all.

 

In my entire page, I have nothing else other than a few JavaScripts and a Form in HTML. Not even sure what's wrong at all.

 

Can someone help? :(

 

Second Example on page: http://www.phpfreaks.com/forums/index.php/topic,209860.0.html

By the way... since you have already given me an example on what to put in Page 1, what am I suppose to put in Page 2, 3 and 4?

 

Mind helping on that as well?

 

Is your code on pageN suppose to be that as well?

 

Thanks a lot for the help. By the way, I'm seriously a noob on this... never programmed in PHP in my life b4. Haha... LOL.

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.