PHP - Is There A Function To Check The Name Of The Current Page?
Is there a function to check the name of the current page? Such as login.php or something like that? If not, does anyone have a custom function already created?
Similar Tutorialsi get this error Warning: current() [function.current]: Passed variable is not an array or object.. for this Code: [Select] $lastblock = current( ${"s".$row} ); print_r($lastblock); when i change to this it works.. Code: [Select] $lastblock = current( $s0 ); print_r($lastblock); The problem is i won't know the $row seeing as it is in a while loop. Solution? Hi i am looping through some history data i have collected via soap. i have the data in an array containing lat, lon and timestamp. Code: [Select] foreach($history['data'] as $record) { echo 'add(jQuery(this), number += 1, "' . date("d-m-Y @ h:i:s",$record['timestamp']) . '", "map_post.php?n=' . $name . 'u=' . $history['user'] . '", "' . $history['user'] . '", "' . $record['latitude'] . '", "' . $record['longitude'] . '");'; } i wondered it it would be possible to check if each position is within say 300 metres of the last position and if so dont display it? Hi, I need to insert some code into my current form code which will check to see if a username exist and if so will display an echo message. If it does not exist will post the form (assuming everything else is filled in correctly). I have tried some code in a few places but it doesn't work correctly as I get the username message exist no matter what. I think I am inserting the code into the wrong area, so need assistance as to how to incorporate the username check code. $sql="select * from Profile where username = '$username'; $result = mysql_query( $sql, $conn ) or die( "ERR: SQL 1" ); if(mysql_num_rows($result)!=0) { process form } else { echo "That username already exist!"; } the current code of the form <?PHP //session_start(); require_once "formvalidator.php"; $show_form=true; if (!isset($_POST['Submit'])) { $human_number1 = rand(1, 12); $human_number2 = rand(1, 38); $human_answer = $human_number1 + $human_number2; $_SESSION['check_answer'] = $human_answer; } if(isset($_POST['Submit'])) { if (!isset($_SESSION['check_answer'])) { echo "<p>Error: Answer session not set</p>"; } if($_POST['math'] != $_SESSION['check_answer']) { echo "<p>You did not pass the human check.</p>"; exit(); } $validator = new FormValidator(); $validator->addValidation("FirstName","req","Please fill in FirstName"); $validator->addValidation("LastName","req","Please fill in LastName"); $validator->addValidation("UserName","req","Please fill in UserName"); $validator->addValidation("Password","req","Please fill in a Password"); $validator->addValidation("Password2","req","Please re-enter your password"); $validator->addValidation("Password2","eqelmnt=Password","Your passwords do not match!"); $validator->addValidation("email","email","The input for Email should be a valid email value"); $validator->addValidation("email","req","Please fill in Email"); $validator->addValidation("Zip","req","Please fill in your Zip Code"); $validator->addValidation("Security","req","Please fill in your Security Question"); $validator->addValidation("Security2","req","Please fill in your Security Answer"); if($validator->ValidateForm()) { $con = mysql_connect("localhost","uname","pw") or die('Could not connect: ' . mysql_error()); mysql_select_db("beatthis_beatthis") or die(mysql_error()); $FirstName=mysql_real_escape_string($_POST['FirstName']); //This value has to be the same as in the HTML form file $LastName=mysql_real_escape_string($_POST['LastName']); //This value has to be the same as in the HTML form file $UserName=mysql_real_escape_string($_POST['UserName']); //This value has to be the same as in the HTML form file $Password= md5($_POST['Password']); //This value has to be the same as in the HTML form file $Password2= md5($_POST['Password2']); //This value has to be the same as in the HTML form file $email=mysql_real_escape_string($_POST['email']); //This value has to be the same as in the HTML form file $Zip=mysql_real_escape_string($_POST['Zip']); //This value has to be the same as in the HTML form file $Birthday=mysql_real_escape_string($_POST['Birthday']); //This value has to be the same as in the HTML form file $Security=mysql_real_escape_string($_POST['Security']); //This value has to be the same as in the HTML form file $Security2=mysql_real_escape_string($_POST['Security2']); //This value has to be the same as in the HTML form file $sql="INSERT INTO Profile (`FirstName`,`LastName`,`Username`,`Password`,`Password2`,`email`,`Zip`,`Birthday`,`Security`,`Security2`) VALUES ('$FirstName','$LastName','$UserName','$Password','$Password2','$email','$Zip','$Birthday','$Security','$Security2')"; //echo $sql; if (!mysql_query($sql,$con)) { die('Error: ' . mysql_error()); } else{ mail('email@gmail.com','A profile has been submitted!',$FirstName.' has submitted their profile',$body); echo "<h3>Your profile information has been submitted successfully.</h3>"; } mysql_close($con); $show_form=false; } else { echo "<h3 class='ErrorTitle'>Validation Errors:</h3>"; $error_hash = $validator->GetErrors(); foreach($error_hash as $inpname => $inp_err) { echo "<p class='errors'>$inpname : $inp_err</p>\n"; } } } if(true == $show_form) { ?> is this possibe with php? I am trying to create a script that alters the navigation div depending on the page the user is on. How do I get the current page using PHP? Hi all, I want to get the current page name as displayed in the URL, not neccesarily the name of the PHP script that is running. E.g. I have a PHP file 'home.php' that contains iframes that contain other PHP files such as 'frame1.php'. What I want is a script that can be run from frame1.php but that will return 'home.php' as the current page (as displayed in the URL in the browser). How do I do this? Thanks! Hi guys, I'll try to explain this. I'm doing a quoting system for a building contractor and I have a dynamic purchase order created for every quote that's confirmed and it spits out all the materials they will need for each supplier. The layout of the page is exactly what I need emailed to the supplier so they can ship out the materials listed, it's your basic purchase order. I'm going to put a button on the page that sends the email to the supplier but I need to attach the purchase order displayed on the page. Preferably in PDF but it just needs to be an attached file. I know I can have the user use PRINT.... to save it as PDF and then use Outlook to email it but I'd like to automate it. Thanks. Why this code dont work :S <?php echo ' <ul> <li'; if ($_SERVER['PHP_SELF'] == "kategorije.php") { echo ' id="current"'; } echo '><a href="kategorije.php"><span>Kategorije</span></a></li> </ul>'; ?> Checking if PHP_SELF is "kategorije.php" do not work, why, and what is solution ? Hi, This may be something for JavaScript but I would like to know if and how it's possible to show who is currently active/viewing the page. Users are logged into the system with their own account. The purpose of this is for a CRM where more than one person may be editing the same record, so undesired overwrites might occur which is what I'd like to avoid with this "other user editing this record" notification. i wanting users to be able to update there email address and check to see if the new email already exists. if the email is the same as current email ignore the check. i have no errors showing up but if I enter a email already in the db it still accepts the new email instead of bringing the back the error message. Code: [Select] // email enterd from form // $email=$_POST['email']; $queryuser=mysql_query("SELECT * FROM members WHERE inv='$ivn' ") or die (mysql_error()); while($info = mysql_fetch_array( $queryuser )) { $check=$info['email']; // gets current email // } if($check!=$email){ // if check not equal to $email check the new email address already exists// $queryuser=mysql_query("SELECT * FROM members WHERE email='$email' "); //$result=mysql_query($sql); $checkuser=mysql_num_rows($queryuser); if($checkuser != 0) { $error= "0"; header('LOCATION:../pages/myprofile.php?id='.$error.''); } } cheers I'm feeling a little overwhelmed/burned-out/confused... I have a page "article_index.php" that contains a summary of each article plus a link to it, e.g. Code: [Select] <a href="<?php echo WEB_ROOT; ?>articles/postage-meters-save-you-money"> When you click on a link, it goes to "article.php" and uses a mod_rewrite to transform the "pretty URL" to regular URL that "article.php" can use to query the correct article from my database. ----- Here is what I need help with... When a user is on a given article page, I want to sto - ReturnToPath - ArticleID in the SESSION. I am drawing a blank on how to get the "ArticleID" when a user is on a give page?! Hope you guys follow me?! Debbie Hi Everyone, I have this small bit of PHP that when you are on a certain page it will add a class called selected Code: [Select] <?php $currentPage = basename($_SERVER['SCRIPT_NAME']); ?> <ul id="subnav"> <li><a href="gallery.php?category=Wedding" id="wedding" <?php if ($currentPage == 'gallery.php?category=Wedding') {echo 'class="selected"';} ?>>Wedding Hair</a></li> <li><a href="gallery.php?category=Men" id="mens-styles" <?php if ($currentPage == 'gallery.php?category=Men') {echo 'class="selected"';} ?>>Mens Styles</a></li> <li><a href="gallery.php?category=Women" id="womens-styles" <?php if ($currentPage == 'gallery.php?category=Women') {echo 'class="selected"';} ?>>Women's Styles</a></li> <li><a href="gallery.php?category=Salon" id="salon" <?php if ($currentPage == 'gallery.php?category=Salon') {echo 'class="selected"';} ?>>Salon</a></li> </ul> This is not working I think it's because of the file extenstion 'gallery.php?category=Wedding' is there any way I can get this to work with these extensions Any help would be greatly appreciated Thanks Barry I'm doing a cURL post to a server and it returns "true No_Error Data was accepted 10356546 3770 false 0 " Form --> Method=Post --> submit.php (this is the page that's doing the cURL post and the server returns data that appears on this page). How do I take this and put it into a string? Hello, I got this basic code from a website and it is supposed to highlight the current page on the menu, which it does very well. The problem is that I cannot stylize the font, color or size of the type in the current page menu display. No matter what I do, it always stays as the default font. The other buttons on the menu can be stylized but not the current page. Is there a way to do this? Code: [Select] ## SNIPPET 1 - THE PHP ## // To be saved in the 'includes' directory as "nav_include.php" <?php $menu=file_get_contents("includes/menu.html"); // get the navigation list of pages $base=basename($_SERVER['PHP_SELF']); // get the current page $menu=preg_replace("|<li><a href=\"".$base."\">(.*)</a></li>|U", "<li id=\"current\">$1</li>", $menu); // add an id of 'active' to the link and id of class to the list item for the current page echo $menu; // echo the HTML list with the current page highlighted ?> ## SNIPPET 2 - THE HTML LIST ## To be saved as menu.html <ul id="navlist"> <li><a href="index.php">Home</a></li> <li><a href="products.php">Products</a></li> <li><a href="services.php">Services</a></li> <li><a href="about.php">About Us</a></li> <li><a href="contact.php">Contact Us</a></li> </ul> ## CSS ## for the *.css file #navlist { margin: 0; padding: 30px 0 20px 10px; float: right; width: 60%; } #navlist ul, #navlist li { margin: 0; padding: 0; display: inline; list-style-type: none; } #navlist a:link, #navlist a:visited { float: left; line-height: 14px; font-weight: bold; margin: 0 10px 4px; text-decoration: none; color: #4F4F4F; width: auto; } /* link and visited link styles - the visited state can be styled separately if you wish */ #navlist a:link#current, #navlist a:visited#current, #navlist a:hover { border-bottom: 4px solid #66733f; padding-bottom: 2px; background: transparent; color: #4F4F4F; } /* this line's the style for the current page link */ #navlist a:hover { border-bottom: 4px solid #4F4F4F; color: #4F4F4F; } /* hover state for all the links */ ## TO DISPLAY ON THE PAGE ## <?php include("includes/nav_include.php"); ?> I've looked at loads of other scripts that highlight the page but none of them work on mine . Here's part of my code: $i =1; for ($x=0;$x<$foundnum;$x=$x+$e) { echo " <a href='search.php?search=$search&s=$x'>$i</a> "; $i++; I have an html table that is being populated with links from a specific directory.. I would like the user to be able to click the link and if its a file they will download the file. If its a directory, I woudl like to reload the current page but this time show the contents of the directory. My main issue is that I have a session variable called 'workingdirectory' that I need to update before I reload the page. I have tried setting it and then calling Location('page.php') but I get the 'cannot change header information' error. I realized I was getting this because I had begun to call HTML code before the PHP was finished. Is there a way to just simply update the session variable, and then make the page reload when the user clicks on a link? Hello, I'm having trouble figured out how to do this... Basically I want update.php to run after the user hits the 'update' button, and after update.php runs (which will take about 60 seconds) I want the index.php to reload. How can this be done? thanks! <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head> <title>Server List</title> </head> <body> <?php $mlink = @mysql_connect("localhost","user","pass"); mysql_select_db("dbname", $mlink); $result = mysql_query("SELECT * FROM ServerList"); while($row = mysql_fetch_array($result)){ echo $row['HostName']. " - ". $row['UsedSlots']. " / ". $row['MaxSlots']; echo "<br />"; } ?> <br/> <br/> <form action="update.php" method="post"> <button type="submit">update</button> </form> </center> </body> </html> I have a few PHP files. Currently, if the URL contains page=var, index includes var.php, otherwise it includes home.php. Apparently, this method makes the site easy to hack through Remote File Inclusion. Also, using PHP5 breaks this method entirely, as no matter what you set page to in the URL, it includes home.php. What's the best way to do this without using the URL? Give example code if possible. I've used PHP for a while but haven't really gotten past the beginner level. I'd really appreciate any help. Thanks. Hi everyone, I have this script that identify's the current page in the navigation Code: [Select] <?php $currentPage = basename($_SERVER['SCRIPT_NAME']); ?> <ul id="nav"><!-- Open Nav --> <li><a href="index2.php" <?php if ($currentPage == 'index2.php') {echo 'class="selected"';} ?>>Home</a></li> <li><a href="salon-information.php" <?php if ($currentPage == 'salon-information.php') {echo 'class="selected"';} ?>>Salon Information</a></li> <li><a href="about-us.php" <?php if ($currentPage == 'about-us.php') {echo 'class="selected"';} ?>>About us</a></li> <li><a href="hair-care-advice.php" <?php if ($currentPage == 'hair-care-advice.php') {echo 'class="selected"';} ?>>Hair Care Advice</a></li> </ul><!-- Close Nav --> My problem is that hair-care-advice.php has a number of sub pages. How do I get it so the selected class remains selected for all the sub pages as well as the main page. Any help would be greatly appreciated Thank you Barry hi, i actually got some code working to add an ID dynamically to a website i'm working on (it was a momentous occasion ). here's the code: in the functions.php file: $url = 'tanzaniatravel.za.com'; $page = $_SERVER['PHP_SELF']; $page = str_replace("/","",$page); $page = str_replace(".php","",$page); $page = str_replace("$url", "", "$page"); i call the functions.php file into the index.php file, and add this as the opening body tag: Code: [Select] <body id="<?php echo $page; ?>"> this dynamically adds an ID named after whatever the actual page is named. now, i make use of the following top navigation structu Code: [Select] <ul class="nav-top"> <li <?php echo ($page == '' ? 'class="nav-top-current"' : ''); ?>><a class="nav-top-lineheight" href="index.php" title="Tanzania Travel home">Home</a></li> <li <?php echo ($page == '' ? 'class="nav-top-current"' : ''); ?>><a class="nav-top-lineheight" href="about.php" title="Why use TanzaniaTravel.Za.Com">Why us</a></li> <li <?php echo ($page == '' ? 'class="nav-top-current"' : ''); ?>><a href="" title="">Overview and area map</a></li> <li <?php echo ($page == '' ? 'class="nav-top-current"' : ''); ?>><a href="" title="">Tanzania National Park</a></li> <li <?php echo ($page == '' ? 'class="nav-top-current"' : ''); ?>><a href="" title="">Tanzania Safari Lodges</a></li> <li <?php echo ($page == '' ? 'class="nav-top-current"' : ''); ?>><a href="" title="">Tanzania Tour Itineraries</a></li> <li <?php echo ($page == '' ? 'class="nav-top-current"' : ''); ?>><a href="" title="">Safari Dates & Prices</a></li> <li <?php echo ($page == '' ? 'class="nav-top-current"' : ''); ?>><a href="" title="">Zanzibar Kilimanjaro</a></li> <li class="<?php echo ($page == '' ? 'nav-top-current' : ''); ?> nav-top-last-li"><a class="nav-top-lineheight" href="" title="">Contact Us</a></li> </ul> you'll see that i've left the $page variable empty. i want that variable to call in the current page's ID, so that only the current page's <li> is active. this, of course, will greatly assist with developing the CSS for the navigation. i appreciate your help very much. thank you. |