Jump to content

deny access unless called from specific page.


mastubbs

Recommended Posts

Hi there,

 

Im using this code to call one php page into another:

 

<?php

define("INCLUDED", TRUE);  
if (file_exists($_GET['id'] . '.php')) {
  require($_GET['id'] . ".php");
} else {
  echo 'ERROR!! Please contact admin@mysite.com';
}

?>

 

I can call hello.php by typing url mysite.com/frame.php?id=hello

 

However, i dont want the pages being called (hello.php) to be accessible alone. Is there some code i can add to these pages to be redirected unless they are inside frame.php??

 

thanks,

 

Matt

Link to comment
Share on other sites

thought i would show an exapmle seems im bored lol

 

1stpage.php

<?php
session_start();
$_SESSION['letmein'] = true;
?><a href="protected_page.php">Protected area</a>

 

then on our protected_page.php

 

<?php
session_start();
if (!$_SESSION['letmein']) {
    header('Location: 1stpage.php');
    echo 'Go through the <a href="1stpage.php">entry page</a> first.';
    exit();
}

// whatever happens to be at the protected page

 

 

hope this helps :)

Link to comment
Share on other sites

Hey thanks everyone,

 

I'm trying all these suggestions but keep getting different problems. Runnerjp, i keep getting

 

Warning: session_start() [function.session-start]: Cannot send session cookie - headers already sent by (output started at /home/jasperss/public_html/cart3/lingerie/daring/prod/new7.php:5) in /home/jasperss/public_html/cart3/lingerie/daring/prod/new7.php on line 6

 

Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at /home/jasperss/public_html/cart3/lingerie/daring/prod/new7.php:5) in /home/jasperss/public_html/cart3/lingerie/daring/prod/new7.php on line 6

 

when i put

 

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

 

any ideas why?

 

thanks

 

matt

Link to comment
Share on other sites

Hey thanks everyone,

 

I'm trying all these suggestions but keep getting different problems. Runnerjp, i keep getting

 

Warning: session_start() [function.session-start]: Cannot send session cookie - headers already sent by (output started at /home/jasperss/public_html/cart3/lingerie/daring/prod/new7.php:5) in /home/jasperss/public_html/cart3/lingerie/daring/prod/new7.php on line 6

 

Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at /home/jasperss/public_html/cart3/lingerie/daring/prod/new7.php:5) in /home/jasperss/public_html/cart3/lingerie/daring/prod/new7.php on line 6

 

when i put

 

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

 

any ideas why?

 

thanks

 

matt

 

You're getting that error because you are outputting data or whitespace before you are calling the session.

 

If you are starting session in a include file, not the main parent file, it's not going to work.

The main frame file has to be the one starting the session from the top..

 

 

Link to comment
Share on other sites

Hey thanks everyone,

 

I'm trying all these suggestions but keep getting different problems. Runnerjp, i keep getting

 

Warning: session_start() [function.session-start]: Cannot send session cookie - headers already sent by (output started at /home/jasperss/public_html/cart3/lingerie/daring/prod/new7.php:5) in /home/jasperss/public_html/cart3/lingerie/daring/prod/new7.php on line 6

 

Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at /home/jasperss/public_html/cart3/lingerie/daring/prod/new7.php:5) in /home/jasperss/public_html/cart3/lingerie/daring/prod/new7.php on line 6

 

when i put

 

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

 

any ideas why?

 

thanks

 

matt

 

You need to start a session before any other output on the page, including HTML. See here: http://www.phpfreaks.com/forums/index.php/topic,37442.0.html

Link to comment
Share on other sites

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.