By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,454 Members | 3,209 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,454 IT Pros & Developers. It's quick & easy.

Getting and using current page URL

P: 7
Hie

could someone please help me with getting and using the current page url. I have a function that gets the url, I want to use it with header(location : XXX) but it wont work. The code is as follows:

The code below is for the first page:session_start is in line 3

<link href="css/jobSheet.css" rel="stylesheet" type="text/css" />
[php]
session_start();
[/php]

<html>
<style type="text/css">
<!--
a:link {
text-decoration: none;
}
a:visited {
text-decoration: none;
}
a:hover {
text-decoration: underline;
}
a:active {
text-decoration: none;
}
-->
</style><head>
<link href="CalendarControl.css" rel="stylesheet" type="text/css"><script src="CalendarControl.js" language="javascript"></script>

<script type="text/javascript" language="javascript">
function validate()
{
var passMsg = "\n!!!Incorrect password!!!";
var msg = "You are required to complete the following fields:";
var status = true;
var date = document.oldClients.todays_date.value;
var dateArray = date.split("-");
var newDateArray = new Array(3)
var year = dateArray[2];
var day = dateArray[1];
var month = dateArray[0]-1;
newDateArray[0]=year;
newDateArray[1]=day;
newDateArray[2]=month;
var myDate = new Date;
myDate.setDate(day);
myDate.setMonth(month);
myDate.setFullYear(year);

var today = new Date;
/* regDate = /^\d{1,2}\-\d{1,2}\-\d{4}$/;
var regWord =/^[A-Za-z]+$/;
regAlnum = /^[\w ]+$/;
regNum =/^\d+$/;
regEmail =/^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$/;
regWeb =/^(([w]{3})+(\.[_a-z0-9-]+)+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$/
//alert(myDate); */
if(document.oldClients.firstName.value == "")
{
msg += "\n - First name";
status = false;
}

if(document.oldClients.lastName.value == "")
{
msg += "\n - Last name";
status = false;
}

if(document.oldClients.clientTitle.value == "")
{
msg += "\n - Client Title";
status = false;
}

if(document.oldClients.company_name.value == "")
{
msg += "\n - Company Name";
status = false;
}

if(document.oldClients.company_code.value == "")
{
msg += "\n - Company code";
status = false;
}

if(document.oldClients.Site_address.value == "")
{
msg += "\n - Site Address";
status = false;
}

if(document.oldClients.postal_address.value == "")
{
msg += "\n - Postal Address";
status = false;
}

if(document.oldClients.phone_number.value == "")
{
msg += "\n - Phone Number";
status = false;
}

if(document.oldClients.email_address.value == "")
{
msg += "\n - Email Address";
status = false;
}
if(document.oldClients.website.value == "")
{
msg += "\n - Website";
status = false;
}


if(document.oldClients.assignedStaff.options.selec tedIndex == 0)
{
msg += "\n - Assigned Staff";
status = false;
}

if ((myDate < today)||(date==""))
{
msg +="\n -Invalid date";
status = false;
}


if(document.oldClients.status.options.selectedInde x == 0)
{
msg += "\n - Status";
status = false;
}

if(document.oldClients.title.value == "")
{
msg += "\n - Job title";
status = false;
}

if(document.oldClients.textarea.value == "")
{
msg += "\n - Request";
status = false;
}

if(status != true)
{

alert(msg);
return(0);

}
else
{
document.oldClients.submit();
}

}
</script>
</head>
<body>
[php]
require_once('dbFunction.php');

function curPageURL() {
//$pageURL = 'http';
if ($_SERVER["HTTPS"] == "on") {$pageURL .= "s";}
$pageURL .= "://";
if ($_SERVER["SERVER_PORT"] != "80") {
// $pageURL .= $_SERVER["SERVER_NAME"].":".$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"];
} else {
$pageURL .=$_SERVER["REQUEST_URI"];
$_SESSION['pageURL'] = $pageURL;
}
return $pageURL;
}

[/php]

<form name="oldClients" method="post" action="dbNewClientJobsheet.php">
[php]
dbConnect();

$role = mysql_query("SELECT * FROM STATUS_DESC") or die(mysql_error());
$staff = mysql_query("SELECT * FROM STAFF")
[/php]

<table width="75%" cellpadding="5" cellspacing="0" class="borderTop" align="center" height="60%">
<td colspan="2" bgcolor="#FFCC00" align="center"><strong>New Client Jobsheet</strong></td>
<tr>

<td align="left" width="65%" valign="top">
<table align="left" width="100%" cellpadding="5" cellspacing="0">

<tr align="center" class="formHeader">
<td width="47%" bgcolor="#FFCC00"><strong>Client details</strong>
<td width="53%" bgcolor="#FFCC00"><strong>Job sheet details</strong> </td>
</tr>
<tr>
<td valign="top" align="center">

<table cellpadding="4" class="formText">
<tr><td>First name*<td><input name="firstName" type="text" class="input"/></td>
<tr><td>Last name*<td><input name="lastName" type="text" class="input" id="lastName"/></td>
<tr><td>Client Title<td><input type="text" name="clientTitle" class="input"></td>
<tr><td>Company name<td><input type="text" name="company_name" class="input"></td>
<tr><td>Company code<td><input type="text" name="company_code" class="input"></td>
<tr><td>Site address<td><input name="Site_address" type="text" class="input" /></td>
<tr><td>Postal address<td><input name="postal_address" type="text" class="input" /></td>
<tr><td>Phone number<td><input type="text" name="phone_number" class="input"></td>
<tr><td>E-mail*<td><input type="text" name="email_address" class="input"></td>
<tr><td>Website<td><input type="text" name="website" class="input"></td>
</tr>
</table>
<td valign="top" align="center">

<table cellpadding="3">
<tr><td class="formText">Job Sheet Number<td class="formText">
[php]
echo JobIdGen();
[/php]
</td>
<tr><td class="formText">Date<td class="formText"><?php echo date("l, j F Y"); ?></td>
<tr><td class="formText">Assigned to*<td>
<select name="assignedStaff">
<option value="0">Choose one*</option>
[php]
while($staffRow = mysql_fetch_array($staff))
{
echo '<option value='.$staffRow['staffID'].'>'.$staffRow['username'].'</option>';
}
[/php]
</select>

<tr><td class="formText">Assigned Date*<td>
<input name="todays_date" onFocus="showCalendarControl(this);" type="text">

<tr><td class="formText">Assigned Time*<td>
<?php //<input name="assigned_time" type= "text" id= "assigned_time" class="textAreaBorder">
?>
<select name="postHour"><option value="1"> 1 </option><option selected="selected" value ="2"> 2 </option> <option value="3"> 3 </option> <option value="4"> 4 </option> <option value="5"> 5 </option> <option value="6"> 6 </option> <option value="7"> 7 </option> <option value="8"> 8 </option> <option value="9"> 9 </option> <option value="10"> 10 </option> <option value="11"> 11 </option> <option value="12"> 12 </option> </select> : <select name="postMinute"><option value="00"> 00 </option> <option value="15"> 15 </option> <option value="30"> 30 </option> <option value="45"> 45 </option> </select> <select name="postAMPM"> <option value="0"> AM </option> <option selected="selected" value="1"> PM </option> </select>

</td>
<tr><td class="formText">Time Created<td class="formText">
<?php echo strftime("%R",time());
echo ' Hours';
?>

</td>
</tr>
<tr><td>Status*<td>
<select name="status">
<option value="0">Choose one</option>
<?php
while($row = mysql_fetch_array($role))
{
echo '<option value='.$row['status_desc_ID'].'>'.$row['status_type'].'</option>';
}
?>
</select>
</td>
</table>
<tr><td></td></tr>
<tr>
<td colspan="2" align="center" class="borderTop" bgcolor="#FFCC00"><span class="formHeader"> <strong>Request</strong></span></td></tr>
<tr>
<td colspan="2" align="center" class="borderTop" bgcolor="#FFCC00"><span class="formHeader">
<strong>Title* :<input name="title" type="text" class="input"/></strong></span></td></tr>
<tr>
<td colspan="2" align="center"><textarea name="textarea" cols="70" rows="10" class="textAreaBorder"><?php
echo "The current page name is ".curPageURL();
?></textarea></td></tr>
<tr>
<tr><td colspan="2" align="center" class="borderTop" bgcolor="#FFCC00">
<input type="button" name="clear" value="Clear" class="button" >
<input class="button" type="button" value="Submit" onClick="validate();">

</td></tr>
</table>
</td>
</tr>

</table>
</td>
</tr>
</table>

</form>

the second page is where the fuction to redirect is and thats where i am getting things mixed up:

[PHP]
session_start();

function dbConnect()
{
if(!mysql_pconnect(xxxx,xxxx,xxxxx))
{
"Can not connect to the database!";
exit();
}
mysql_select_db("casiac_gto");
}


//check if the variable is numeric
function nukeNum($value,$pageURL) {
$value3 = trim(stripslashes($value));
$num =((strlen($value3) == 0) or (!ereg("^[[:digit:]- ]{1,100}$",$value3)));
if(!$num){
header('Location: $pageURL');
}else{
return $value3;
}
}

//checks if variable contains alpha-numeric characters
function nukeAlphaNum($value,$pageURL) {
$value4 = trim(stripslashes($value));
$num =((strlen($value4) == 0) or (!ereg("^[[:alnum:]/-,. ]{1,100}$",$value4)));
if(!$num){
header('Location: $pageURL');
}else{
return $value4;
}
}

function isEmail($value,$pageURL) {
$email = trim(stripslashes($value));
$num = ((strlen($email) == 0) or (!eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$",$email)));
if(!$num){
header('Location: $pageURL');
}else{
return $value4;
}

};

[/PHP]

I reckon the second piece of code is the most important and code someone please give me a hand

thank you
May 8 '07 #1
Share this Question
Share on Google+
1 Reply


Purple
Expert 100+
P: 404
Hi simbarashe,

I think you are building the uri incorrectly - I haven't tried to recreate it but I offer the following which works for me..

[PHP]$uri = "//" . $_SERVER["SERVER_NAME"]. rtrim(dirname($_SERVER['PHP_SELF']), '/\\'); // build the URI for redirect to login screen
header("Location: http:".$uri."/play.php");[/PHP]

so subsitute play.php for the page you are trying to fire - obviously don't output anything to the screen (including whitespace) before the header redirect..

Hope this helps..
May 8 '07 #2

Post your reply

Sign in to post your reply or Sign up for a free account.