Board index   FAQ   Search  
Register  Login
Board index php forum :: php coding PHP coding => General

Problem with Php redirection..

Ask about general coding issues or problems here.

Moderators: macek, egami, gesf

Problem with Php redirection..

Postby vahn » Thu Oct 17, 2002 12:35 pm

Hi below is very basic simple code that i am testing out for a website im making.

Code: Select all
 <?
if($menu=="shouts"){ include("comments.php");  }

?>
<!doctype html public "-//W3C//DTD HTML 4.0 //EN">
<html>
<head>
       <title></title>
</head>
<body>
         <a href="?menu=shouts"> shout box </a>
</body>
</html>


This code works, the url looks like 'http://localhost/?menu=shouts'
but when i submit the form that i have on the comments.php page,
im taking back to the main index page with the menu.

When i try header("Location: $dir/comments.php"); instead of include, i get some kind of error.

any thoughts?
vahn
New php-forum User
New php-forum User
 
Posts: 5
Joined: Thu Oct 17, 2002 12:25 pm

Postby Jay » Thu Oct 17, 2002 12:51 pm

Errm, call me stupid (and get banned ;)) but what exactly is the problem you're facing?
Jay
 

Postby DoppyNL » Thu Oct 17, 2002 1:09 pm

Code: Select all
<a href="?menu=shouts">
this link will is a relative link to the current site, because you don't tell what domain.
You say that in the browser it will link to localhost, appearantly you called the script at localhost, so the page will link to that one too, you're browser fills in the "current host".

Why do you get you're index? When you don't ask for a specific file on a webserver you will get the index-file of the folder you're requesting.

All in one, you get what should be expected. wich is probably why Jay didn't get it.... I had to think too :)

To go to the domain you want, either run the script from there, or add the domain to you're link.
To go to a specific file (comments.php?) and not the index of a folder, add the filename in the link.



As for you're include/header problem: could be a lot of things, post the error message, that would help A LOT!!!

Greetz Daan
Last edited by DoppyNL on Thu Oct 17, 2002 10:30 pm, edited 1 time in total.
DoppyNL
 

Postby vahn » Thu Oct 17, 2002 1:56 pm

I'm running the server off my own Personal Web Server, thats whyi use 'localhost'.

The problem im facing, is Include, doesnt redirect me to the page i want to go to. It includes the code of the page i want to go to, into the current index.php page.

When it does this, it brings up a form, when i fill out the form, instead of it executing the script, it executes the link again.

Bann me whatever, i'm not comin back if everyone here is gonna be a rude little faggot assed nigger
vahn
New php-forum User
New php-forum User
 
Posts: 5
Joined: Thu Oct 17, 2002 12:25 pm

Postby Jay » Thu Oct 17, 2002 2:12 pm

vahn wrote:Bann me whatever, i'm not comin back if everyone here is gonna be a rude little faggot assed nigger

I was joking, hence the smiley - idiot!

The idea of include is that it's supposed to include the file you're including. That's why it's called include! If you want to redirect you can either use a HTTP header, a meta tag or a bit of Javascript, the choice is yours!
Jay
 

Postby vahn » Thu Oct 17, 2002 7:39 pm

yes i know you where joking. i was reffering to DoppyNL...

I know the include command is messed up, but when i do the http header command it gives me an error.. here.. look.


http://65.34.83.11/index.php



Thats the link to my PWS. The following is the code I have..

Go to the link, and click on the link. It brings up a error, and i cant figure out whats wrong.

What im trying to do. Is make a link that says http://whatever.com/?menu=shouts .

I've seen this at many websites, such as http://www.deviantart.com

I found a simple tutorial on how to do it, but it didnt use the header command, it used include() command.

But when i use the include command, it messes up the script i have for the shout box. It will refresh the index page(where the link is) and just include the shoutbox page code inside, but when i fill out the shout box form and press submit, it just brings me back to the index page.

Sorry, but tahts the best i can describe it, if anyone can help, please let me know
Code: Select all
 <? if($menu=="shouts"){
header("Location: http://65.34.83.11/comments.php"); } else {

?>
<!doctype html public "-//W3C//DTD HTML 4.0 //EN">
<html>
<head>
<title></title>
</head>
<body>
<a href="?menu=shouts"> shout box </a>
</body>
</html>
<? } ?>
[/code]
vahn
New php-forum User
New php-forum User
 
Posts: 5
Joined: Thu Oct 17, 2002 12:25 pm

Postby DoppyNL » Thu Oct 17, 2002 10:30 pm

I visited you're link and got this error:
Warning: Cannot add header information - headers already sent by (output started at c:/program files/abria merlin/apache/htdocs/index.php:1) in c:/program files/abria merlin/apache/htdocs/index.php on line 2


wich gives me the answer, thats why I asked for the error message, didn't mean to be rude or anything.
Anyway, you're sending an header back to the user on line 2, but some output was allready sent on line 1.
This output is probably a space or something, make sure you're script starts with "<?" and nothing is in front of that. Then you will be able to send the header.

Greetz Daan
DoppyNL
 

Postby vahn » Fri Oct 18, 2002 9:32 am

god i feel like a stupid tool. sorry for being an ass, thanks for all your help.

You where right doppy, there was a space=\ its fixed now. thanks a bunch:)
vahn
New php-forum User
New php-forum User
 
Posts: 5
Joined: Thu Oct 17, 2002 12:25 pm


Return to PHP coding => General

Who is online

Users browsing this forum: Google [Bot], landi and 1 guest

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.