Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9098335
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T00:20:21+00:00 2026-06-17T00:20:21+00:00

I have placed a php code for getting current page URL and now I

  • 0

I have placed a php code for getting current page URL and now I can get current page URL by writing this code

<?php print(selfURL()); ?>

Now, I want to know how can I write this code as the default value of Input field?
Actually I want the Input field to automatically filled up with the current page URL.

When I use <?php print(selfURL()); ?> as value="<?php print(selfURL()); ?>" it simple shows a text and don’t display current url. But when I paste it in other place then its working fine.

Any suggestions?

UpDATE:

Guys, this is the full code of the page, may be it helps!

<?php
function selfURL() { $s = empty($_SERVER["HTTPS"]) ? '' : ($_SERVER["HTTPS"] == "on") ? "s" : ""; $protocol = strleft(strtolower($_SERVER["SERVER_PROTOCOL"]), "/").$s; $port = ($_SERVER["SERVER_PORT"] == "80") ? "" : (":".$_SERVER["SERVER_PORT"]); return $protocol."://".$_SERVER['SERVER_NAME'].$port.$_SERVER['REQUEST_URI']; } function strleft($s1, $s2) { return substr($s1, 0, strpos($s1, $s2)); }
?>
<?php 
// Start YOURLS engine
require_once( dirname(__FILE__).'/includes/load-yourls.php' );
?>
<!DOCTYPE html>
<html>
<head>
<title>YOURLS Public Interface Sample</title>
<style>
body {
    background:#E3F3FF;
    color:#595441;
    font:16px/30px verdana,arial,sans-serif;
}
a, a:visited {color:#2A85B3}
h1 {text-align:center; color:#2A85B3}
h2 {
    border-bottom:1px solid #2A85B3;
    color:#2A85B3;
    margin-left:-10px;
    padding-left:25px;
    width:80%;
}
#container {
    width: 780px;
    margin-left: auto;
    margin-right: auto; 
    background-color: #fff;
    border: 3px solid #2A85B3;
    padding: 10px;
    margin-top: -13px;
    -moz-border-radius:15px;
    -webkit-border-radius:15px;
}
#footer {
    text-align:center;
    margin-top:20px;
}
#footer p {
    padding:5px;
    background:white;
    margin:0 auto;
    width:750px;
    -moz-border-radius:10px;
    border-radius:10px;
    -webkit-border-radius:10px;
    border:1px solid #2A85B3;
    -moz-border-radius-bottomleft:35px;
    -moz-border-radius-bottomright:35px;
    -webkit-border-bottom-left-radius:25px;
    -webkit-border-bottom-right-radius:25px;
}
#footer p a {
    background:#fff url(http://yourls.org/images/favicon.gif) 2px center no-repeat;
    padding-left:20px;
}
div#copybox { width:600px; height:auto;}
div#sharebox {height:auto; width:600px; margin-top:20px;}
</style>
<link rel="stylesheet" href="<?php echo YOURLS_SITE; ?>/css/share.css?v=<?php echo YOURLS_VERSION; ?>" type="text/css" media="screen" />
<script src="<?php echo YOURLS_SITE; ?>/js/jquery-1.6.1.min.js" type="text/javascript"></script>
<script src="<?php echo YOURLS_SITE; ?>/js/ZeroClipboard.js?v=<?php echo YOURLS_VERSION; ?>" type="text/javascript"></script>
<script type="text/javascript">ZeroClipboard.setMoviePath( '<?php echo YOURLS_SITE; ?>/js/ZeroClipboard.swf' );</script>
<script src="<?php echo YOURLS_SITE; ?>/js/share.js?v=<?php echo YOURLS_VERSION; ?>" type="text/javascript"></script>
</head>

<body>
<h1>YOURLS: Your Own URL Shortener</h1>

<div id="container">

    <?php

    // Part to be executed if FORM has been submitted
    if ( isset($_REQUEST['url']) ) {

        $url     = yourls_sanitize_url( $_REQUEST['url'] );

        $return  = yourls_add_new_link( $url );

        $shorturl = isset( $return['shorturl'] ) ? $return['shorturl'] : '';


        echo <<<RESULT
        <h2>URL has been shortened</h2>
        <p>Original URL: <code><a href="$url">$url</a></code></p>
        <p>Short URL: <code><a href="$shorturl">$shorturl</a></code></p>

RESULT;



    // Part to be executed when no form has been submitted
    } else {

        $site = YOURLS_SITE;

        echo <<<HTML
        <h2>Enter a new URL to shorten</h2>
        <form method="post" action="">
        <p><label>URL: <input type="text" name="url" value="<?php echo selfURL(); ?>" size="70" /></label></p>
        <p><label>Optional custom keyword: $site/<input type="text" name="keyword" size="8" /></label></p>
        <p><label>Optional title: <input type="text" name="title" size="57" /></label></p>
        <p><input type="submit" value="Shorten" /></p>
        </form> 
HTML;

    }

    ?>


</div>





<?php print(selfURL()); ?>

</body>
</html>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T00:20:22+00:00Added an answer on June 17, 2026 at 12:20 am

    below is the solution :

    $_SERVER['PHP_SELF'];

    Tested Code is as below

    <input type="text" name="" id="" value="<?php echo $_SERVER['PHP_SELF']; ?>"/>

    your code edit

    $var = $_SERVER['PHP_SELF'];
    OR
    $var = selfURL();
    
    <p><label>URL: <input type="text" name="url" value="$var" size="70" /></label></p>

    You are adding php inside her-doc syntax and that’s the error

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a simple html form. On php page. A simple list is placed
I have placed an image on the master page. I see the image at
I have multiple Node applications (build on Express framework). Now I have placed them
i have copied this code from the FB.init documentation : <script src=http://static.ak.connect.facebook.com/js/api_lib/v0.4/FeatureLoader.js.php/en_US type=text/javascript></script> ...
PHP Uploading issue Getting Error 0 but move_uploaded_file() is returning false. When I print
I have php function, that returns array to JavaScript like this: $data['first'] = 10;
i have one php page with paging option i use follwoing sql statement to
My query outputs this in phpMyAdmin: Code: <?php if ($stmt = $mysqli->prepare("SELECT service_names.id, service_names.name
I have a php application getting x and y position constantly from the server.
I have a php page called template.php and i have a logo and when

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.