Getting and using current page URL

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • simbarashe
    New Member
    • Nov 2006
    • 7

    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_st art 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="CalendarC ontrol.css" rel="stylesheet " type="text/css"><script src="CalendarCo ntrol.js" language="javas cript"></script>

    <script type="text/javascript" language="javas cript">
    function validate()
    {
    var passMsg = "\n!!!Incor rect password!!!";
    var msg = "You are required to complete the following fields:";
    var status = true;
    var date = document.oldCli ents.todays_dat e.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.setFullY ear(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.old Clients.firstNa me.value == "")
    {
    msg += "\n - First name";
    status = false;
    }

    if(document.old Clients.lastNam e.value == "")
    {
    msg += "\n - Last name";
    status = false;
    }

    if(document.old Clients.clientT itle.value == "")
    {
    msg += "\n - Client Title";
    status = false;
    }

    if(document.old Clients.company _name.value == "")
    {
    msg += "\n - Company Name";
    status = false;
    }

    if(document.old Clients.company _code.value == "")
    {
    msg += "\n - Company code";
    status = false;
    }

    if(document.old Clients.Site_ad dress.value == "")
    {
    msg += "\n - Site Address";
    status = false;
    }

    if(document.old Clients.postal_ address.value == "")
    {
    msg += "\n - Postal Address";
    status = false;
    }

    if(document.old Clients.phone_n umber.value == "")
    {
    msg += "\n - Phone Number";
    status = false;
    }

    if(document.old Clients.email_a ddress.value == "")
    {
    msg += "\n - Email Address";
    status = false;
    }
    if(document.old Clients.website .value == "")
    {
    msg += "\n - Website";
    status = false;
    }


    if(document.old Clients.assigne dStaff.options. selectedIndex == 0)
    {
    msg += "\n - Assigned Staff";
    status = false;
    }

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


    if(document.old Clients.status. options.selecte dIndex == 0)
    {
    msg += "\n - Status";
    status = false;
    }

    if(document.old Clients.title.v alue == "")
    {
    msg += "\n - Job title";
    status = false;
    }

    if(document.old Clients.textare a.value == "")
    {
    msg += "\n - Request";
    status = false;
    }

    if(status != true)
    {

    alert(msg);
    return(0);

    }
    else
    {
    document.oldCli ents.submit();
    }

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

    function curPageURL() {
    //$pageURL = 'http';
    if ($_SERVER["HTTPS"] == "on") {$pageURL .= "s";}
    $pageURL .= "://";
    if ($_SERVER["SERVER_POR T"] != "80") {
    // $pageURL .= $_SERVER["SERVER_NAM E"].":".$_SERVE R["SERVER_POR T"].$_SERVER["REQUEST_UR I"];
    } else {
    $pageURL .=$_SERVER["REQUEST_UR I"];
    $_SESSION['pageURL'] = $pageURL;
    }
    return $pageURL;
    }

    [/php]

    <form name="oldClient s" method="post" action="dbNewCl ientJobsheet.ph p">
    [php]
    dbConnect();

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

    <table width="75%" cellpadding="5" cellspacing="0" class="borderTo p" align="center" height="60%">
    <td colspan="2" bgcolor="#FFCC0 0" 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="formHead er">
    <td width="47%" bgcolor="#FFCC0 0"><strong>Clie nt details</strong>
    <td width="53%" bgcolor="#FFCC0 0"><strong>J ob 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>Clien t Title<td><input type="text" name="clientTit le" class="input"></td>
    <tr><td>Compa ny name<td><input type="text" name="company_n ame" class="input"></td>
    <tr><td>Compa ny code<td><input type="text" name="company_c ode" class="input"></td>
    <tr><td>Site address<td><inp ut name="Site_addr ess" type="text" class="input" /></td>
    <tr><td>Posta l address<td><inp ut name="postal_ad dress" type="text" class="input" /></td>
    <tr><td>Phone number<td><inpu t type="text" name="phone_num ber" class="input"></td>
    <tr><td>E-mail*<td><input type="text" name="email_add ress" 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="assignedS taff">
    <option value="0">Choos e one*</option>
    [php]
    while($staffRow = mysql_fetch_arr ay($staff))
    {
    echo '<option value='.$staffR ow['staffID'].'>'.$staffRow['username'].'</option>';
    }
    [/php]
    </select>

    <tr><td class="formText ">Assigned Date*<td>
    <input name="todays_da te" onFocus="showCa lendarControl(t his);" type="text">

    <tr><td class="formText ">Assigned Time*<td>
    <?php //<input name="assigned_ time" type= "text" id= "assigned_t ime" class="textArea Border">
    ?>
    <select name="postHour" ><option value="1"> 1 </option><option selected="selec ted" 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="postMinut e"><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="selec ted" value="1"> PM </option> </select>

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

    </td>
    </tr>
    <tr><td>Status* <td>
    <select name="status">
    <option value="0">Choos e one</option>
    <?php
    while($row = mysql_fetch_arr ay($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="borderTo p" bgcolor="#FFCC0 0"><span class="formHead er"> <strong>Request </strong></span></td></tr>
    <tr>
    <td colspan="2" align="center" class="borderTo p" bgcolor="#FFCC0 0"><span class="formHead er">
    <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="textArea Border"><?php
    echo "The current page name is ".curPageUR L();
    ?></textarea></td></tr>
    <tr>
    <tr><td colspan="2" align="center" class="borderTo p" bgcolor="#FFCC0 0">
    <input type="button" name="clear" value="Clear" class="button" >
    <input class="button" type="button" value="Submit" onClick="valida te();">

    </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_pconn ect(xxxx,xxxx,x xxxx))
    {
    "Can not connect to the database!";
    exit();
    }
    mysql_select_db ("casiac_gto ");
    }


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

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

    function isEmail($value, $pageURL) {
    $email = trim(stripslash es($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('Locatio n: $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
  • Purple
    Recognized Expert Contributor
    • May 2007
    • 404

    #2
    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_NAM E"]. rtrim(dirname($ _SERVER['PHP_SELF']), '/\\'); // build the URI for redirect to login screen
    header("Locatio n: 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..

    Comment

    Working...