Welcome to Dream.In.Code
Become a PHP Expert!

Join 150,175 PHP Programmers for FREE! Get instant access to thousands of PHP experts, tutorials, code snippets, and more! There are 2,217 people online right now. Registration is fast and FREE... Join Now!




Cannot redirect a page!

 
Reply to this topicStart new topic

Cannot redirect a page!

Mcbazzo
30 Aug, 2008 - 02:31 PM
Post #1

New D.I.C Head
*

Joined: 29 Aug, 2008
Posts: 37

Ok so i messed with it and ended up with this:
CODE
<?
session_start();
if(!session_is_registered(myusername)){
header("location:main_login.php");
}
?>

<html>
<body>
Login Successful
</body>
</html>
<?php
"test.php.php"
header("location:test.php.php");
?>

I am trying to get the page to automatically redirt to a page called test.php.php, now im only on for about 7minutes so i may not reply after 11:30, but i will check the post tommoro if theres no reply.
User is offlineProfile CardPM
+Quote Post

chili5
RE: Cannot Redirect A Page!
30 Aug, 2008 - 02:35 PM
Post #2

D.I.C Addict
****

Joined: 28 Dec, 2007
Posts: 763



Thanked: 4 times
My Contributions
The redirect you have at the bottom isn't going to work, because you've printed out all these HTML tags before. Thus the HTTP headers have been sent to the browser already, and you can't send them again. At the top of your page:

php

header("location: test.php.php");


Put that just under the if statement that you have. Also why are you using .php.php? That doesn't make much sense at all.
User is offlineProfile CardPM
+Quote Post

JBrace1990
RE: Cannot Redirect A Page!
30 Aug, 2008 - 03:56 PM
Post #3

D.I.C Regular
Group Icon

Joined: 9 Mar, 2008
Posts: 479



Thanked: 24 times
Dream Kudos: 350
My Contributions
i'd guess it's a php file he named test.php >_>

and what chili said, headers are already sent, and if you try to modify them, you end up with an error...
User is offlineProfile CardPM
+Quote Post

CTphpnwb
RE: Cannot Redirect A Page!
30 Aug, 2008 - 04:00 PM
Post #4

D.I.C Regular
Group Icon

Joined: 8 Aug, 2008
Posts: 481



Thanked: 32 times
My Contributions
You could always use html:

<meta HTTP-EQUIV="REFRESH" content="0; url=somefile.php">


User is offlineProfile CardPM
+Quote Post

chili5
RE: Cannot Redirect A Page!
30 Aug, 2008 - 04:10 PM
Post #5

D.I.C Addict
****

Joined: 28 Dec, 2007
Posts: 763



Thanked: 4 times
My Contributions
You could use that, but I'm sure that there's reasons that the PHP code is better to use. Yeah but why is he naming his files "test.php.php"?
User is offlineProfile CardPM
+Quote Post

JBrace1990
RE: Cannot Redirect A Page!
30 Aug, 2008 - 05:07 PM
Post #6

D.I.C Regular
Group Icon

Joined: 9 Mar, 2008
Posts: 479



Thanked: 24 times
Dream Kudos: 350
My Contributions
the html is a bad way to do it... it's more for if you want something to be seen.... PHP is more for if you DON'T want it to be seen =)
User is offlineProfile CardPM
+Quote Post

brandon99337
RE: Cannot Redirect A Page!
30 Aug, 2008 - 10:46 PM
Post #7

D.I.C Head
**

Joined: 14 Feb, 2008
Posts: 144



Thanked: 2 times
My Contributions
Haha test.php.php. I'd recommend you change it to test.php if you want it work!
User is offlineProfile CardPM
+Quote Post

Mcbazzo
RE: Cannot Redirect A Page!
30 Aug, 2008 - 10:57 PM
Post #8

New D.I.C Head
*

Joined: 29 Aug, 2008
Posts: 37

QUOTE(brandon99337 @ 30 Aug, 2008 - 11:46 PM) *

Haha test.php.php. I'd recommend you change it to test.php if you want it work!

1. If your going on about the name being wrong in the code you are wrong because the file file is called test.php.php therefore in the code it should be tesat.php.php
2. If you mean the file wont work with 2 .php's it can only have 1, your wrong as my last page has the same thing.
3. I'd like to thank all contributors and I will try all you suggestions now (will post if works or doesn't).
User is offlineProfile CardPM
+Quote Post

no2pencil
RE: Cannot Redirect A Page!
30 Aug, 2008 - 11:04 PM
Post #9

My fridge be runnin OH NOEZ!
Group Icon

Joined: 10 May, 2007
Posts: 7,166



Thanked: 78 times
Dream Kudos: 2425
Expert In: Goofing Off

My Contributions
QUOTE(Mcbazzo @ 30 Aug, 2008 - 06:31 PM) *

CODE

<?php
"test.php.php"
header("location:test.php.php");
?>



I believe that the problem with this code is you don't have a command for the text in quotes. You are not telling php what to do with it. Especially since there is no end semi colon, php is going to see this as
"test.php.php" header("...");

& it really isn't going to know wtf to do with it.

It's like me running up to you & saying Car!

An acceptable response would be something like :
Yeah.. what about it?

** Edit **
Almost forgot. To concure with the other responses, once you send text, you will get an error from the header command.

CODE

<?php
header("text.php.php"); // this will load
?>
<html> <!-- Header... -->
<body></body>
</html>
<?php
header("text.php.php"); // this will fail
?>


You can only send the headers once, everything after that is text. You ever seen a website with two headers? I think not!
User is offlineProfile CardPM
+Quote Post

Mcbazzo
RE: Cannot Redirect A Page!
30 Aug, 2008 - 11:07 PM
Post #10

New D.I.C Head
*

Joined: 29 Aug, 2008
Posts: 37

ok i got it working heresthe code
CODE
<html>
<body>
Login Successful
<meta HTTP-EQUIV="REFRESH" content="0; url=test.php.php">
</body>
</html>

Thankyou CTphpn... sorry not good with names lol tongue.gif
User is offlineProfile CardPM
+Quote Post

no2pencil
RE: Cannot Redirect A Page!
30 Aug, 2008 - 11:12 PM
Post #11

My fridge be runnin OH NOEZ!
Group Icon

Joined: 10 May, 2007
Posts: 7,166



Thanked: 78 times
Dream Kudos: 2425
Expert In: Goofing Off

My Contributions
While that solution may work, be warned that it should not an acceptable solution because forwards can be turned off at the browser (as previously pointed out by JBrace1990).

What I would do in this situation is use require_once(), & that will load the php code you want. You have to write the pages accordingly so that if need be, they can share usage.

CODE

<?php
session_start();
if(!session_is_registered(myusername)){
  require_once("main_login.php"); // contains login site
}
else {
  //do what the page is designed to do...
}
?>


User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 1/9/09 03:31AM

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter

Live PHP Help!

PHP Tutorials

Reference Sheets

PHP Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month