WeberDev.com PHP and MySQL Code

LOG IN
BEGINNER GUIDESPHP CLASSESCODE SEARCHARTICLES SEARCHPHP FORUMSPHP MANUALPHP FUNCTIONS LISTWEB SITE TEMPLATES
Start typing to search for PHP and MySQL Code Snippets and Articles Search
Submit a code Example / Snippet Join us on FaceBook
Submit a code Example / Snippet Submit Your Code
Poker Tournaments Poker Tournaments
Poker Guide for Developers Poker Guide for Developers
Search Engine Optimization Monitor SEO Monitor
Web Site UpTime Monitor UpTime Monitor
Your Personal Examples List My Favorite Examples
Your Personal Articles List My Favorite Articles
Edit Account Info Update Your Profile
PHP Code Search
Web Development Forums
Learn MySQL Playing Trivia
PHPBB2 Templates
Web Development Resources
Web Development Content
Internet Security Software
PHPClasses
PHP Editor
PHP Jobs
Vision.To Design
Ajax Tutorials
PHP Programming Help
PHP/MySQL Programming
Webmaster Resources
Webmaster Forum
XML meta language
website builder
פרייסז - הכח לקנות עובר לידיים שלך
Texas Holdem Poker Evangelists

Go Back Add a Comment Send this example to a friend Add this Article to your personal favoritest for easy future access to your favorite Code Examples and Articles. Submit a code example Print this code example.
BACK ADD A COMMENT SEND TO A FRIEND ADD TO MY FAVORITES ADD CODE EXAMPLES PRINT
Title : Current Page's URL using PHP
Categories : PHP, Beginner Guides, Global Variables Click here to Update Your Picture
Vinod Mohan
Date : Dec 07th 2008
Grade : 4 of 5 (graded 2 times)
Viewed : 9141
File : No file for this code example.
Images : No Images for this code example.
Search : More code by Vinod Mohan
Action : Grade This Code Example
Tools : My Examples List

Submit your own code examples  Submit your own code examples 
 

Several times it becomes necessary to find the url of the current page in php. It is not a very big deal to find it, but for a newbie it may take quite some time. So here is a function to do that. The url is stored in a static variable so that it doesn't have to be generated everytime the function is called.

<?php
function getCurrentPageUrl(){
     static
$pageURL = '';
     if(empty(
$pageURL)){
         
$pageURL = 'http';
          if(isset(
$_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on')$pageURL .= 's';
         
$pageURL .= '://';
          if(
$_SERVER['SERVER_PORT'] != '80')$pageURL .= $_SERVER['SERVER_NAME'].':'.$_SERVER['SERVER_PORT'].$_SERVER['REQUEST_URI'];
          else
$pageURL .= $_SERVER['SERVER_NAME'].$_SERVER['REQUEST_URI'];
     }
     return
$pageURL;
}
?>


// In this example we are storing the url of the current page as a hidden form field so that we can return to the previous page after completing an action, say login

example usage
<html>
<head>
<title>Current Page URL</title>
</head>
<body>
<form method="post" action="/users/login.php">
Username : <input type="text" name="username" value=""/><br/>
Password : <input type="password" name="password" value=""/>
<input type="submit" value="Login"/>
<input type="hidden" name="action" value="login"/>
<input type="hidden" name="return_url" value="<?php echo getCurrentPageUrl();?>"/>
</form>
</body>
</html>



Simple image counter
Categories : PHP, Graphics, Filesystem, Beginner Guides
Making a simple Hit-Log using PHP and MySql
Categories : PHP, Log Files, Beginner Guides, Databases, MySQL
Using PHP to show text in random colors
Categories : PHP, Beginner Guides, Strings
Newbie Notes #10 - Generating drop downs
Categories : PHP, MySQL, HTML, Beginner Guides, Databases
Temperature Conversion
Categories : PHP, Math., Beginner Guides
Ensure that a specific value lies within a specific range.
Categories : PHP, Beginner Guides, Data Validation
filter untrusted GET and POST variables and create trusted variable of same name
Categories : PHP, Global Variables, Security
Find if a year is leap.
Categories : PHP, Date Time, Beginner Guides, Data Validation
Count Number Of weeks in Month
Categories : PHP, Date Time, Beginner Guides
How can I know about what Operating System is running on server from PHP?
Categories : PHP, Global Variables
Validating a URL with preg_match
Categories : PHP, Regexps, Beginner Guides, Data Validation
Sending mail to a mailing list and showing progress
Categories : PHP, Mail, Beginner Guides
How to display any array in several rows and columns of a table. Not just in one column or in alternate rows. This example shows a nice color table generated with PHP, but can be used with any array values(e.g. Database)
Categories : Arrays, PHP, Miscellaneous, Beginner Guides, Graphics
Kewl Date Example
Categories : PHP, HTML and PHP, Date Time, CSS, Beginner Guides
Newbie Notes #9 - Hyperlinking a post
Categories : PHP, Java Script, HTML and PHP, Beginner Guides