Code Comments

Programming Forum and web based access to our favorite programming groups.
For Programmers: Free Programming Magazines | New: Database administration forum
Registration is free! Edit your profileCalendarFind other membersFrequently Asked QuestionsSearch -> 
Post New Thread











Thread
Author

Redirect
ASP has <%Response.redirect("http://blahblah")%>

What is the equivalent command in php to redirect a user to a new URL in
the same window? Or is there a Javascript command that does this job better?

Thanks,
Purple Haze

Report this thread to moderator Post Follow-up to this message
Old Post
Purple Haze
09-24-04 01:56 AM


Re: Redirect
.oO(Purple Haze)

>ASP has <%Response.redirect("http://blahblah")%>
>
>What is the equivalent command in php to redirect a user to a new URL in
>the same window? Or is there a Javascript command that does this job better?[/color
]

http://www.php.net/header

Micha

Report this thread to moderator Post Follow-up to this message
Old Post
Michael Fesser
09-24-04 01:56 AM


Re: Redirect
Michael Fesser wrote:
>  .oO(Purple Haze)
>
> 
>
>
> http://www.php.net/header
>
> Micha

After using:

header("Location: http://www.example.com/");

Its complaining headers have already been sent, and doesn't redirect.

Report this thread to moderator Post Follow-up to this message
Old Post
Purple Haze
09-24-04 01:56 AM


Re: Redirect
Purple Haze wrote:
> Michael Fesser wrote: 
>
> After using:
>
> header("Location: http://www.example.com/");
>
> Its complaining headers have already been sent, and doesn't redirect.

Read the entire section on the header() function, don't just skip down to
the examples. header() must be called before any output (including
whitespace before <?php) has been sent.



Report this thread to moderator Post Follow-up to this message
Old Post
Agelmar
09-24-04 01:56 AM


Re: Redirect
Agelmar wrote:

> Purple Haze wrote:
> 
>
>
> Read the entire section on the header() function, don't just skip down to
> the examples. header() must be called before any output (including
> whitespace before <?php) has been sent.
>
>

I guess I should have been more specfic, I need a redirect-function that
can be called anytime in the script. In this instance after the script
has determined that a vaild user and pass have been submitted.

Purple Haze

Report this thread to moderator Post Follow-up to this message
Old Post
Purple Haze
09-24-04 01:56 AM


Re: Redirect
.oO(Purple Haze)

>I guess I should have been more specfic, I need a redirect-function that
>can be called anytime in the script. In this instance after the script
>has determined that a vaild user and pass have been submitted.

Of course you can do this with header(), but you either

* have to make sure there's no other output sent to the browser before
(Does the check for a valid user prints anything out?)

or

* have to use output buffering.

Micha

Report this thread to moderator Post Follow-up to this message
Old Post
Michael Fesser
09-24-04 01:56 AM


Re: Redirect
Michael Fesser wrote:

>  .oO(Purple Haze)
>
> 
>
>
> Of course you can do this with header(), but you either
>
> * have to make sure there's no other output sent to the browser before
>   (Does the check for a valid user prints anything out?)
>
> or
>
> * have to use output buffering.
>
> Micha

I am still unclear what your referring to, perhaps a copy of the script
will help...

<center>
<form ACTION="login.php" name="saveform" METHOD="POST" align="center">
<p><input NAME="username"VALUE SIZE="8" MAXLENGTH="16" tabindex="1"></p>
<p><input type="password"name="password" size="8" tabindex="2"
maxlength="8"></p>
<p><input TYPE="button"NAME="FormsButton2" VALUE="Validate"
ONCLICK="submit()" tabindex="3"style="font-family: Verdana; font-size:
12pt">
</form>
</center>

<?php
$mysql_database="login";
$mysql_username="root";
$mysql_password="";
$link = mysql_connect("localhost",$mysql_username,$mysql_password) or
die ("Unable to connect to SQL server");
mysql_select_db($mysql_database,$link) or die ("Unable to select database");
$username = $HTTP_POST_VARS['username'];
$password = $HTTP_POST_VARS['password'];

if (isset($password))
{
$qstr = "SELECT * from members where user ='$username' and pass
='$password'";
$result = mysql_query($qstr);

if (mysql_num_rows($result))
{
echo "<font color=#008000><Center><b>**Successful
Login**</b></Center></font>";
header("Location: http://www.example.com/");
exit;
}
else echo "<font color=#ff0000><Center><b>**Failed
Login**</b></Center></font>";
mysql_close();

}
else echo "<font color=#ff8000><Center><b>**No login
attempted**</b></Center></font>";
?>

Report this thread to moderator Post Follow-up to this message
Old Post
Purple Haze
09-24-04 01:56 AM


Re: Redirect
Purple Haze wrote:

> Michael Fesser wrote:
> 
>
>

Found the answer to my own question :/

I had a feeling javascript was the key here:

echo "<script>window.location=\"login1.php\"</script>";

will do the job

Report this thread to moderator Post Follow-up to this message
Old Post
Purple Haze
09-24-04 01:56 AM


Re: Redirect
Purple Haze <xxx@xxx.com> wrote:
> I had a feeling javascript was the key here:
>
> echo "<script>window.location=\"login1.php\"</script>";
>
> will do the job

What about any client without javascript?

Fix your php code instead...

--

Daniel Tryba


Report this thread to moderator Post Follow-up to this message
Old Post
Daniel Tryba
09-24-04 01:56 AM


Re: Redirect
.oO(Purple Haze)

>Found the answer to my own question :/
>
>I had a feeling javascript was the key here:
>
>echo "<script>window.location=\"login1.php\"</script>";
>
>will do the job

Unreliable.

Try to fix your script instead: First - before anything else - check if
the user is valid, then redirect or print out the form.

Micha

PS: Please don't send me copies of your postings by e-mail. I read the
groups I'm posting to.

Report this thread to moderator Post Follow-up to this message
Old Post
Michael Fesser
09-24-04 01:56 AM


Sponsored Links




Last Thread Next Thread Next
Pages (2): [1] 2 »
Search this forum -> 
Post New Thread

PHP Language archive

Show a Printable Version Send to friend Email This Page to Someone! subscribe to this thread Receive updates to this thread
Computer Consultants
Programming Jobs
Visual Basic Controls
SQL Server Programming
Webservices
Java Security
Visual Studio
C# Programming
Visual J++
Software engineering
Open source Software
Perl Programming
PHP Programming
ASP Programming
ASP .NET Programming
Visual Basic Programming
Windows Scripting Host
Java Programming
Java Help
Java Beans
VBScript
Cobol
MAC Applications
Unix Programming
Forum Jump:
All times are GMT. The time now is 05:24 PM.

 
Free MCSE Braindumps | Real Estate Topics

Programming forum archive

Copyrights CodeComments.com 2004 - 2006

Powered by vBulletin Copyright 2000-2006 Jelsoft Enterprises Limited.