473,408 Members | 2,032 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,408 software developers and data experts.

Redirection Problem

I'm running PHP on Windows, but that's just the local test... in production
it will be on Apache.

I am not using PHP as a CGI. I want to perform redirection of the user's
browser if the user isn't a valid user. I don't want to use the refresh
meta tag or javascript to do this. I want to do this with some sort of
server command.

Does anyone know how to make this work? Here's my code...
<?php
session_start();
$goal = "";
if (array_key_exists('goal', $_GET)) { $goal = $_GET['goal']; }

if (isset($HTTP_POST_VARS['userid']) && isset($HTTP_POST_VARS['password']))
{
$userid = $HTTP_POST_VARS['userid'];
$password = $HTTP_POST_VARS['password'];
$db_conn = mysql_connect('localhost', 'webauth', 'webauth');
mysql_select_db('auth', $db_conn);
$query = "select * from auth where name='$userid' and
pass=password('$password')";
$result = mysql_query($query, $db_conn);
if (mysql_num_rows($result) > 0) {
$HTTP_SESSION_VARS['valid_user'] = $userid;
}
}
?>
<?
if (isset($HTTP_SESSION_VARS['valid_user'])) {
// redirection code goes here. Re-direct to value current to the value of
$goal which is a html file in the current directory http directory

} else {
if (isset($userid)) {
echo 'Could not log you in';
} else {
echo 'You are not logged in <br/>';
}

echo '<html><body><form method="post" action="authmain.php">';
echo '<table>';
echo '<tr><td>Userid:</td><td><input type="text" name="userid"></td></tr>';
echo '<tr><td>Password:</td><td><input type="password"
name="password"></td></tr>';
echo '<tr><td colspan="2" align="center"><input type="submit" value="Log
In"></td></tr>';
echo '</table></form></body></html>';
}
?>

Jul 16 '05 #1
2 2359
Topspin wrote:
I'm running PHP on Windows, but that's just the local test... in
production it will be on Apache.

I am not using PHP as a CGI. I want to perform redirection of the user's
browser if the user isn't a valid user. I don't want to use the refresh
meta tag or javascript to do this. I want to do this with some sort of
server command.

Does anyone know how to make this work? Here's my code...

Hi Topspin,

just set the http-location-header like so:

header("location: $newurl");

The users browser should then load this new URL.
Make sure -as usual with the call to header- that your script
did not write anything out prior to the function call.
A simple blank somewhere in an included file is sufficient to let your
call fail.

Cheers
Frank
Jul 16 '05 #2
Topspin wrote:
I am not using PHP as a CGI. I want to perform redirection of the user's
browser if the user isn't a valid user. I don't want to use the refresh
meta tag or javascript to do this. I want to do this with some sort of
server command.


Upon finding out that they're not valid:

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

Make sure you write this BEFORE your script produces any output. Even a single
space will cause you grief. Also, be sure to use an absolute URL. Relative
URLs will work in some newer browsers, but cause trouble in others.

Shawn
--
Shawn Wilson
sh***@glassgiant.com
http://www.glassgiant.com
Jul 16 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Rick N. Backer | last post by:
Hello folks, Novice type question here. I'm working with a very simple app here that takes a series of strings from the console. Once the end user has finished inputting the strings they are...
15
by: Taki Jeden | last post by:
Hello everybody Does anybody know why w3c validator can not get pages that use 404 htaccess redirection? I set up two web sites so that clients request non-existent urls, but htaccess redirects...
0
by: Dimitrios Mpougas | last post by:
Hello, I have two asp.net pages. The first is a page (main.aspx) wich has four links on it. The href value of each link is: href="view.aspx?id=1" traget="_blank" href="view.aspx?id=2"...
13
by: souissipro | last post by:
Hi, I have written a C program that does some of the functionalities mentionned in my previous topic posted some days ago. This shell should: 1- execute input commands from standard input,...
2
by: fReDiNi | last post by:
Hi, I have an strange problem with session variables. I have a site hosted in a local server. I have physic access to this server and its configuration.(apache, php,files...). I have external...
4
by: psual | last post by:
hi newbie in web design I got some issue concerning a secure redirection between 2 pages let say I have a page with a grid (the 'master' page) in this grid I can select a record, get its pk...
1
by: Mike Hofer | last post by:
I really need some help, and I'd appreciate any that you folks can provide. The ASP.NET application in question uses version 1.1 of the .NET Framework. All of the pages use a common base class...
3
by: postindex | last post by:
Can I get whole commandline not only argument list. 1. When I command like this $ a.py filename 2. sys.argv is returns only argument list Is there a way to find out 'redirection'...
13
by: Massimo Fabbri | last post by:
Maybe it's a little OT, but I'll give it try anyway.... I was asked to maintain and further develop an already existing small company's web site. I know the golden rule of "eternal" URIs, but...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.