Results 1 to 6 of 6

Thread: Click Link = Display Text

  1. #1

    Thread Starter
    Hyperactive Member alacritous's Avatar
    Join Date
    Aug 2003
    Posts
    464

    Click Link = Display Text

    Hello,

    In PHP, I'd like to create a page where if you click a link, it will display text in a <div>, <table>, or etc.

    Currently, I have it using Javascript, but Internet Explorer has that security thing which I don't like.

    Thanks in advance

  2. #2
    VBA Nutter visualAd's Avatar
    Join Date
    Apr 2002
    Location
    Ickenham, UK
    Posts
    4,906

    Re: Click Link = Display Text

    Will you be retrieving the text from a server side database?
    PHP || MySql || Apache || Get Firefox || OpenOffice.org || Click || Slap ILMV || 1337 c0d || GotoMyPc For FREE! Part 1, Part 2

    | PHP Session --> Database Handler * Custom Error Handler * Installing PHP * HTML Form Handler * PHP 5 OOP * Using XML * Ajax * Xslt | VB6 Winsock - HTTP POST / GET * Winsock - HTTP File Upload

    Latest quote: crptcblade - VB6 executables can't be decompiled, only disassembled. And the disassembled code is even less useful than I am.

    Random VisualAd: Blog - Latest Post: When the Internet becomes Electricity!!


    Spread happiness and joy. Rate good posts.

  3. #3

    Thread Starter
    Hyperactive Member alacritous's Avatar
    Join Date
    Aug 2003
    Posts
    464

    Re: Click Link = Display Text

    No, it's just a string.

    Well, I kind of solved it. Internet Explorer only displays that issue when it's a local file. Once I uploaded it to my site, it didn't do it. That's good and all, but once again the way I have is it Javascript and I'd like to use PHP.

  4. #4
    Junior Member
    Join Date
    Apr 2004
    Location
    Stockholm, Sweden
    Posts
    29

    Re: Click Link = Display Text

    The link:
    PHP Code:
    <a href="thispage.php?show=1">Show text</a
    Put this inside the table/div/whatever that you wish to show the text in:
    PHP Code:
    <?php
        
    if (isset($_GET['show']))
        {
            if (
    $_GET['show'] == 1)
            {
                echo 
    'The string you want to display';
            }
        }
    ?>
    If there is a way to solve your problems, there is no need to worry; if there is no way to solve your problems, there is no point to worry.

  5. #5
    VBA Nutter visualAd's Avatar
    Join Date
    Apr 2002
    Location
    Ickenham, UK
    Posts
    4,906

    Re: Click Link = Display Text

    I've drawn up a simple example of how to do it in PHP. What you need to do is append a file name to the end of your links. I.e:

    index.php?file=filename.html

    This will display the file with that name insdie a div. You'll need to change the HTML to suit.
    PHP Code:
    <?php
        
    /* directory containing uploaded text */
        
    $dir '.';

        
    /* default file */
        
    $default '';
        
        
    /* check to see if a file name was supplied */
        
    if (isset($_GET['file'])) {
            
    $file get_magic_quotes_gpc()?stripslashes($_GET['file']):$_GET['file'];
        } else {
            
    $file $default;
        }
        
        
    $path $dir DIRECTORY_SEPARATOR $file;
        
        
    $content '';
        
        if (
    strspn($file'/\\') > 0) {
            
    /* check for any invalid characters */
            
    $error 'Invalid File Name';
        } else if (! 
    file_exists($path)) {
            
    /* check the file exists */
            
    $error 'Invalid File Name';
        } else if (
    $file != '') {
            
    /* all is ok so get the file NB: any HTML will be parsed by the browser */
            
    $content = @file_get_contents($path);
        }   
    ?>
    <html>
        <head>
            <title>Text Display</title>
        </head>
        <body>
            <ul>
                <li><a href="<?php echo($_SERVER['PHP_SELF']) ?>?file=file1.html">Link To Div</a></li>
            </ul>
            <p><?php echo(@$error?></p>
            <div>
                <?php echo($content?>
            </div>
        </body>
    </html>
    Last edited by visualAd; Mar 14th, 2005 at 05:03 AM. Reason: Minor code change to avoid security exploits
    PHP || MySql || Apache || Get Firefox || OpenOffice.org || Click || Slap ILMV || 1337 c0d || GotoMyPc For FREE! Part 1, Part 2

    | PHP Session --> Database Handler * Custom Error Handler * Installing PHP * HTML Form Handler * PHP 5 OOP * Using XML * Ajax * Xslt | VB6 Winsock - HTTP POST / GET * Winsock - HTTP File Upload

    Latest quote: crptcblade - VB6 executables can't be decompiled, only disassembled. And the disassembled code is even less useful than I am.

    Random VisualAd: Blog - Latest Post: When the Internet becomes Electricity!!


    Spread happiness and joy. Rate good posts.

  6. #6

    Thread Starter
    Hyperactive Member alacritous's Avatar
    Join Date
    Aug 2003
    Posts
    464

    Re: Click Link = Display Text

    Thanks.

    Yeah, that's exactly what the Javascript does, apends #div to the end, instead of ?div...

    PHP is better, IMO .

    Thanks,

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width