473,396 Members | 1,773 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,396 software developers and data experts.

Getting and using current page URL

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
1 3157
Purple
404 Expert 256MB
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

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

Similar topics

2
by: Leonard Rutkowski | last post by:
I am using a third party product that requires a reference to a page, Me.Page for example. I would like to use this product in a function, in a vb class, that I am writing. I know that I can pass...
4
by: Nick | last post by:
I'm developing an intranet app, and want to get the current user name for logging purposes. I've turned off anonymous access, and turned on windows authentication in the IIS config. The apps...
3
by: Hitesh | last post by:
Hi, I am getting the response from another Website by using the HttpHandler in my current site. I am getting the page but all the images on that page are not appearing only placeholder are...
1
by: Nathan Sokalski | last post by:
I have retrieved data from a database using a SELECT statement that includes an INNER JOIN. The data seems to be retrieved to the DataSet OK, but I am having trouble getting the data from the...
4
by: Pat | last post by:
In my Web.config i have :- <customErrors mode="On" defaultRedirect="genericerror.htm"> <error statusCode="404" redirect="pagenotfound.aspx"/> </customErrors to get page not found error but...
8
by: bryan | last post by:
Is there any way I can get the application path (the one returned by Request.ApplicationPath) in the Application_Start method in Global.asax? Request is not valid there. On a related note, is there...
8
by: BB | last post by:
Hi, I am using FormView Contol, TextBox (Hidden ) and Submit button whose caption is "View Page" in my aspx page. Here is what I am tryin to do.When page loads I generate dynamic url in text box...
3
by: Norman Wooten | last post by:
Ok, I am a nOOb C#/NET coder, so this is probably easy.. heh heh (only been pecking is these languages for a week now, just converted from vbscript and classic asp) But anyways, I have a class...
3
by: tshad | last post by:
I have a file that I converted from VB.Net to C# that works fine in VB.Net when I compile but not in C# using the same libraries. The error I am getting is: PageInit.cs(9,7): error CS0138: A...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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: 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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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,...

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.