relative path issue on localhost

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
steve_linn
Forum Newbie
Posts: 20
Joined: Thu Jul 10, 2008 1:10 pm

relative path issue on localhost

Post by steve_linn »

Hello. I'm very new to PHP programming: looking for some assistance

I have a script that goes to the wrong page on the localhost - it uses header (LOCATION: )

here is the url that the code goes to:
http://localhost/wms/library/main.php

here is where I want the code to go:
http://localhost/wms/main.php

here is the code:
<?php
ob_start();
include("db_connect.php");
// Check to See if user is authorized
$result = mysql_query("SELECT * FROM users WHERE username='" . $_GET[$Username] . "' AND password='" . $_GET[$Password] . "'");
$row = mysql_fetch_row($result);
if ($row[1] == $_GET [$Username]){
if ($row[2] == $_GET [$Password]){
//Set Cookie for Login
if (isset($_COOKIE["username"])){
setcookie("username",$_GET['Username'],time()+1209600,"/","localhost",0);
setcookie("password",$_GET['Password'],time()+1209600,"/","localhost",0);
} else{
setcookie("username",$_GET['Username'],time()+1209600,"/","localhost",0);
setcookie("password",$_GET['Password'],time()+1209600,"/","localhost",0);
}
header("Location: main.php");
exit;
}
else{
header("Location:index.php");
exit;
}
}
else{
header("Location:index.php");
exit;
}
mysql_free_result($result);
mysql_close($dbwms);
ob_end_flush();
?>
WebbieDave
Forum Contributor
Posts: 213
Joined: Sun Jul 15, 2007 7:07 am

Re: relative path issue on localhost

Post by WebbieDave »

Instead of a relative URI, try an absolute one:

Code: Select all

header('Location: /wms/main.php');
steve_linn
Forum Newbie
Posts: 20
Joined: Thu Jul 10, 2008 1:10 pm

Re: relative path issue on localhost

Post by steve_linn »

that's the solution!
Post Reply