Jump to content

Ignore all is before @domain.com


Edge11

Recommended Posts

Hello everyone 

I have script php and input html which input form let user pass only if writen anything is random before -admin-com for example if user put jfucfbhx3-admin-com or fhcd35-admin-com or anything random before -admin-com will pass to the next page alledite.php but if user writen on the input something that is not before -admin-com won't pass so only let user pass if writen something random before -admin-com here is the script 

<?php
    # for test porpoises
    define('BR','<br />');
    
    if( $_SERVER['REQUEST_METHOD']=='POST' && !empty( $_POST['code'] ) ){
        # set $displayonly=false to actually do the redirection
        $displayonly=false;
        
        
        $code=filter_input(INPUT_POST,'code',FILTER_SANITIZE_STRING);
        $pages=array(
            '-admin-com'            =>  'alledite.php',
            '-moderator-com'        =>  'halfedite.php',
            '-coroot-com'           =>  'edite.php'
        );
        
        foreach( $pages as $str => $redirect ){
            # construct a basic regex pattern from the array key.
            $pttn=sprintf( '@((.*)?%s)@', preg_quote( $str ) );
            
            # for testing
            if( $displayonly )echo $pttn . BR;
            
            # Run the regex and if a match is found use the corresponding
            # value from the above array as the redirection endpoint.
            preg_match( $pttn, $code, $matches );
            if( !empty( $matches ) ){
                $header=sprintf('Location: %s', $redirect );
                exit( $displayonly ? $header : header( $header ) );
            }
        }
    }
?>
<!DOCTYPE html>
<html lang='en'>
    <head>
        <meta charset='utf-8' />
        <title>Match string and redirect</title>
    </head>
    <body>
        <form method='post'>
            <input type='text' name='code' />
            <input type='submit' />
        </form>
    </body>
</html>

So the part of regex is who do this is

@((.*)?%s)@

Its all  working now like charm but what I want is the same idea with different text I want a regex like  @((.*)?%s)@ 

For @admin.com not for -admin-com as shown in code below 

I have showed you guys all my script to understand me deeply please any help I will appreciate it thanks

 

 

 

Edited by Edge11
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.