Link to home
Create AccountLog in
PHP

PHP

--

Questions

--

Followers

Top Experts

Avatar of wilslm
wilslm

Redirect Pages ...
I am not sure, how to write redirect pages , in Php .. can someone give me illustration

here is my login and password..hp

if (........)
echo "success"'
XXXXXXXXXX
else
echo "wrong password";

basically ,if the user name and password match... Currently i just echo"success"
but what i want is open a new pages called let say main.php ...
Can someone give me illustration about it ?

thanks

Zero AI Policy

We believe in human intelligence. Our moderation policy strictly prohibits the use of LLM content in our Q&A threads.


SOLUTION
Avatar of prady_21prady_21

Link to home
membership
Log in or create a free account to see answer.
Signing up is free and takes 30 seconds. No credit card required.
Create Account

ASKER CERTIFIED SOLUTION
Link to home
membership
Log in or create a free account to see answer.
Signing up is free and takes 30 seconds. No credit card required.

SOLUTION
Link to home
membership
Log in or create a free account to see answer.
Signing up is free and takes 30 seconds. No credit card required.

Avatar of andrew67andrew67

($redirect == "ok")?header('location:main.php'):header('location:nologin.php');

you can also do it with javascript echo "<script>document.location.href='index.php'</script>";
you use that when you want to redirect

...and data is already sent
sorry posted when I wasnt finished yet

Reward 1Reward 2Reward 3Reward 4Reward 5Reward 6

EARN REWARDS FOR ASKING, ANSWERING, AND MORE.

Earn free swag for participating on the platform.


it is not valid if you supply a relitive path. you must to supply the full path. it may work on IE, but it is not compliant with many web standards.

header('location: http://'.$_SERVER['HTTP_HOST'].dirname($_SERVER['PHP_SELF']).'nologin.php');

or make it  a function:

function goto($loaction){
header('location: http://'.$_SERVER['HTTP_HOST'].dirname($_SERVER['PHP_SELF']).'/'.$location);
}

and call it like this:
goto('nologin.php');

Avatar of skullnobrainsskullnobrains

try and output an html redirection
echo"<meta http-equiv=\"refresh\" contents=\"0;URL=URL_OF_PAGE\">";

or call the other page from the original one using <<include('file.php');>>

whenever i try it i always get a Cannot modify header information - headers already sent error

can any1 help me

Free T-shirt

Get a FREE t-shirt when you ask your first question.

We believe in human intelligence. Our moderation policy strictly prohibits the use of LLM content in our Q&A threads.


don't know which way u use, but if u use any function that implies the sending of a header,
the header or setcookie functions for example,
you must not output anything beforehand as this will result in terminating the headers and you'll get this message.

have a look in the manual at the function that causes this message, this is a well-documented issue.

the way out is either don't use that function (hence the meta solution, though cross-compatibility means you have to write it twice), or don't output anything before (even a blank line before the original <? will mess it up), or use buffering.
try ob_start in google and pick any online manual for examples and related functions

//you better redirecting at top on one line of code to main.php
($redirect == "ok")?header('location:main.php'):header('location:nologin.php');

//either you span this
you can also do it with javascript echo "<script>document.location.href='index.php'</script>";
you use that when you want to redirect main.php after no logon availables

Reward 1Reward 2Reward 3Reward 4Reward 5Reward 6

EARN REWARDS FOR ASKING, ANSWERING, AND MORE.

Earn free swag for participating on the platform.


I have an html form that is validated in php and opens a new browser window to a new size. e.g. it stays on top with the form if you forgot to include, say, your addess.

The problem is when the new window opens it echos all of the "...you forgot to(s) rather than just what you forgot to input, name, address etc.

Any clues?
Do I need to unload a buffer or memory or something for this new window page??

Thanks.

nobody can help you without the code, mike.
you probably used something like
foreach($_POST as $var => $val){ // or $_GET or whatever
if(!$val)print ('...');
... }
any string will trigger the error since a string is evalued to numeric 0 alias false usually

the 'good' comparison should be similar to :
if(trim($val)=="")echo 'you must specify a valid input for $var'.

anyway, if the check is not that more thoroughfull, it is rather useless.
let us see what the code is like !

Avatar of EsopoEsopo🇺🇸

If your script has already started output you can't send header information. In such cases, you can also use a javascript redirect:
http://www.netbulge.com/index.php?session=0&action=read&click=open&article=1113900339

Free T-shirt

Get a FREE t-shirt when you ask your first question.

We believe in human intelligence. Our moderation policy strictly prohibits the use of LLM content in our Q&A threads.


Esopo >>
There is a work-around for this problem, and even though I don't support this solution, I'll still mention it.

Use the output-buffer-function:

<?php
ob_start();

// script with screen output

ob_end();
?>

The output-buffer will store the info, and it will work like a charm.

With that said, I still support the idea of coding properly.

Avatar of EsopoEsopo🇺🇸

>>Use the output-buffer-function...<<
I was not aware of that function. Yes, it certainly is not a very good coding practice, but it can get you out of trouble in cases like this.
Thanks for posting that.

You're welcome  :-)

Reward 1Reward 2Reward 3Reward 4Reward 5Reward 6

EARN REWARDS FOR ASKING, ANSWERING, AND MORE.

Earn free swag for participating on the platform.

PHP

PHP

--

Questions

--

Followers

Top Experts

PHP is a widely-used server-side scripting language especially suited for web development, powering tens of millions of sites from Facebook to personal WordPress blogs. PHP is often paired with the MySQL relational database, but includes support for most other mainstream databases. By utilizing different Server APIs, PHP can work on many different web servers as a server-side scripting language.