i'm working on a script and I want to make the links such as www.mysite.com/signup. this link for registration. www.mysite.com/user/username and this link for user's profile. the links without any php extension. also when someone request link such as www.mysite.com/signup.php should redirect him to www.mysite.com/signup

what I know is I have to create .htaccess, but what should be the code?

second problem is whith create a user session. in log in form. it works only in localhost but online it doesn't work

here is my signin.php

<?php
session_start();
require 'connect.php';
require_once 'core/classes/user_class.php';
require_once 'core/functions/main.php';
require_once 'core/functions/formfunctions.php';
include 'inc/top.php';
include 'inc/header.php';

// if there is a session
if(isset($_SESSION['username']))
{
    echo '<div class="search_field"><b>you are loged in already</b></div>';
    include 'inc/footer.php';
    exit();
}

$username = $_POST['username'];
$userpass = $_POST['userpass'];

$user = new user();
$user->login($username,$userpass);

//form
?>
<div class="center_body">
    <div class="search_field">
            <form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
                <table border="0" width="100%" cellspacing="0" cellpadding="0">
                    <td align="left">username:</td>
                    <td align="right"><input type="text" name="username" class="search" /></td>
                </tr>
                <tr>
                    <td align="left">userpass:</td>
                    <td align="right"><input type="password" name="userpass" class="search" /></td>
                </tr>
                </table>
                <input type="submit" value="sign in" class="search" /></p>
            </form>
            </tr>

    </div>
</div>


<?php
include 'inc/footer.php';
?>

user_class.php

    public function login($username, $userpass)
{

    $username = security($username);
    $userpass = security(md5($userpass));

    if(empty($_POST) === false)
    {
        if(empty($username) or  empty($userpass))
        {
            echo '<div class="search_field"><b>معلومات الدخول خاطئه</b></div>';
        }else{
            $result = mysql_query("SELECT * FROM users WHERE username='$username' AND userpass='$userpass'");

            while($row = mysql_fetch_assoc($result))
            {
                @$user = @$row['username'];
                @$pass = @$row['userpass'];
            }

            if($username == $user and $pass == $userpass)
            {
                echo '<div class="search_field"><b>تم تسجيل الدخول بنجاح .. الانتقال الى الصفحه الرئيسيه</b></div></ br>';
                echo'<meta http-equiv="REFRESH" content="3;url=index">';
                $_SESSION['username'] = $username;
                $_SESSION['userpass'] = $userpass;

            }else{
                echo '<div class="search_field"><b>لا يوجد عضو بهذا الاسم الرجاء تأكد من معلومات الدخول</b></div>';
            }
        }
    }
}

hope you can help me

thank you

Recommended Answers

All 10 Replies

Member Avatar for LastMitch

@empror9

what I know is I have to create .htaccess, but what should be the code?

I think someone was still helping you with this:

http://www.daniweb.com/web-development/php/threads/435134/links-for-my-script

second problem is whith create a user session. in log in form. it works only in localhost but online it doesn't work

You need to create a db connection on your host server!

Read this about connecting to your database:

http://www.daniweb.com/web-development/php/code/434415/using-phpmysql-with-error-checking

and this

http://www.daniweb.com/web-development/php/code/434480/using-phpmysqli-with-error-checking

thanks lastMitch

for first problem, I have this code

RewriteEngine On
RewriteRule ^/?([a-z]+)$ $1.php [L]

links without .php is working now. but I want the link for user's profile to be www.mysite.com/profile/here_username

what to add to make it work as well?

for second problem, I have imported same database from my localhost into databse in my host. there is no errors or warning message. when I press log in it says I have logged in successfully and then redirect me to home page without saying 'welcome username'. but in local host yes it says welcome username. do you think that my way to create a user session is good? what do you think is the problem?

thanks

Member Avatar for LastMitch

@empror9

for first problem, I have this code

RewriteEngine On
RewriteRule ^/?([a-z]+)$ $1.php [L]
links without .php is working now. but I want the link for user's profile to be www.mysite.com/profile/here_username

what to add to make it work as well?

Someone is helping you already your question is close to be solve:

http://www.daniweb.com/web-development/php/threads/435134/links-for-my-script

for second problem, I have imported same database from my localhost into databse in my host. there is no errors or warning message. when I press log in it says I have logged in successfully and then redirect me to home page without saying 'welcome username'. but in local host yes it says welcome username. do you think that my way to create a user session is good? what do you think is the problem?

You didn't create a session yet? Create one

I know, but no answer about my request.

I have set the session already.

Member Avatar for LastMitch

@empror9

I know, but no answer about my request.

I think that person is in the different time zone than yours. Then it's good to take notice what time that person comes onto DaniWeb.

I have set the session already.

What did you get?

LastMitch please help me if you know how to solve :)

I didn't get error message. please visit this link

http://3rbc.net/adver/signin

it's in Arabic language but the first field is username and the second is password

username: a
password: a

when you click on log in it logged you and redirect you to home page without any session start. becuase if the session is started you should see your name and welcome message

for me I don't know my mistake, but I think maybe my way to set a session is not good. and all my codes is in the post.

Member Avatar for LastMitch

@empror9

Can you post the header code which has the session()

here is file called top.php. this file is to show links for a user

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en" dir="rtl">
<head>
    <meta http-equiv="content-type" content="text/html;charset=utf-8" />
    <link rel="stylesheet" href="/adver/images/style.css" type="text/css" />
    <title>المركز العربي للاعلانات</title>
</head>
<body>

<?php
if(isset($_SESSION['username']))
{
    echo'<div class="search_field">

    &nbsp;&nbsp;&nbsp;أهلاً بك يا&nbsp;<a href="profile/'.$_SESSION['username'].'">'.$_SESSION['username'].'</a><img border="0" src="http://3rbc.net/adver/images/icons/user.png" width="16" height="16">
    &nbsp;|&nbsp;&nbsp;<a href="/adver/signout">تسجيل خروج</a>&nbsp;<img border="0" src="http://3rbc.net/adver/images/icons/door_out.png" width="14" height="14">
    &nbsp;|&nbsp;&nbsp;<a href="/adver/sites">مواقعي</a><img border="0" src="http://3rbc.net/adver/images/icons/world.png" width="14" height="14">
    &nbsp;|&nbsp;&nbsp;<a href="/adver/advertisement">اعلاناتي</a><img border="0" src="http://3rbc.net/adver/images/icons/coins.png" width="14" height="14">
    &nbsp;|&nbsp;&nbsp;<a href="/adver/setting">اعداداتي</a><img border="0" src="http://3rbc.net/adver/images/icons/cog.png" width="14" height="14">
    &nbsp;|&nbsp;&nbsp;<a href="/adver/terms">قواعد الاستخدام</a><img border="0" src="http://3rbc.net/adver/images/icons/information.png" width="14" height="14">
    &nbsp;|&nbsp;&nbsp;<a href="/adver/about">عن المركز</a><img border="0" src="http://3rbc.net/adver/images/icons/ask_and_answer.png" width="14" height="14">
    &nbsp;|&nbsp;&nbsp;<a href="/adver/contact">اتصل بنا</a><img border="0" src="http://3rbc.net/adver/images/icons/help.png" width="14" height="14">

</div>';
}else{

?>
<div class="search_field">

    &nbsp;&nbsp;&nbsp;
    <a href="newuser">حساب جديد</a><img border="0" src="http://3rbc.net/adver/images/icons/user_add.png" width="16" height="16">
    &nbsp;|&nbsp;&nbsp;<a href="signin">تسجيل الدخول</a><img border="0" src="http://3rbc.net/adver/images/icons/user.png" width="16" height="16">
    &nbsp;|&nbsp;&nbsp;<a href="sites">مواقعي</a><img border="0" src="http://3rbc.net/adver/images/icons/world.png" width="14" height="14">
    &nbsp;|&nbsp;&nbsp;<a href="advertisement">اعلاناتي</a><img border="0" src="http://3rbc.net/adver/images/icons/coins.png" width="14" height="14">
    &nbsp;|&nbsp;&nbsp;<a href="setting">اعداداتي</a><img border="0" src="http://3rbc.net/adver/images/icons/cog.png" width="14" height="14">
    &nbsp;|&nbsp;&nbsp;<a href="terms">قواعد الاستخدام</a><img border="0" src="http://3rbc.net/adver/images/icons/information.png" width="14" height="14">
    &nbsp;|&nbsp;&nbsp;<a href="about">عن المركز</a><img border="0" src="http://3rbc.net/adver/images/icons/ask_and_answer.png" width="14" height="14">
    &nbsp;|&nbsp;&nbsp;<a href="contact">اتصل بنا</a><img border="0" src="http://3rbc.net/adver/images/icons/help.png" width="14" height="14">

</div>

<?php } ?>

signin.php

<?php
session_start();
require 'connect.php';
require_once 'core/classes/user_class.php';
require_once 'core/functions/main.php';
require_once 'core/functions/formfunctions.php';
include 'inc/top.php';
include 'inc/header.php';

// if there is a session
if(isset($_SESSION['username']))
{
    echo '<div class="search_field"><b>you are loged in already</b></div>';
    include 'inc/footer.php';
    exit();
}

$username = $_POST['username'];
$userpass = $_POST['userpass'];

$user = new user();
$user->login($username,$userpass);

//form
?>
<div class="center_body">
    <div class="search_field">
            <form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
                <table border="0" width="100%" cellspacing="0" cellpadding="0">
                    <td align="left">username:</td>
                    <td align="right"><input type="text" name="username" class="search" /></td>
                </tr>
                <tr>
                    <td align="left">userpass:</td>
                    <td align="right"><input type="password" name="userpass" class="search" /></td>
                </tr>
                </table>
                <input type="submit" value="sign in" class="search" /></p>
            </form>
            </tr>

    </div>
</div>


<?php
include 'inc/footer.php';
?>

user_class.php

<?php
require 'connect.php';
require_once 'core/functions/main.php';

class user
{
    private $username;
    private $userpass;
    private $useremail;
    private $country;
    private $contact;
    private $registerdate;
    private $rate;

    function user()
    {
        @$this->username = $username;
        @$this->userpass = $userpass;
        @$this->useremail= $useremail;
        @$this->country  = $country;
        @$this->contact  = $contact;
        @$this->registerdate = $registerdate;
        @$this->rate = $rate;
    }

    public function addUser($username, $userpass, $useremail, $country, $contact, $registerdate, $rate)
    {
        if(empty($_POST) === false)
        {
            $username = security($username);
            $userpass = security(md5($userpass));
            $contact  = security($contact);

            $match = @mysql_query("select username,useremail from users where username='$username' or useremail='$useremail'");
            $rows  = @mysql_num_rows($match);

            if(empty($username) or empty($userpass) or empty($useremail) or empty($country)
               or empty($contact) or empty($registerdate))
            {
                echo '<div class="search_field"><b>المعلومات غير كامله ، رجاءا قم بإكمال جميع الحقول</b></div>';
            }elseif(isEmail($useremail)  == false ){
                echo '<div class="search_field"><b>رجاءا قم بإدخال بريد الكتروني صحيح</b></div>';
            }elseif(strlen($username) > 50 or strlen($userpass) > 50 or strlen($useremail) > 50){
                echo '<div class="search_field"><b>لقد ادخلت قيمه كبيره .. رجاء قم بخفضها</b></div>';
                }elseif($rows > 0){
                echo '<div class="search_field"><b>اسم المستخدم او الايميل الالكتروني مسجل لدينا رجاء قم بتغييرها</b></div>';           
            }else{
                $insert = @mysql_query("INSERT INTO users(username,userpass,useremail,country,contact,registerdate,rate)
                        VALUES ('$username','$userpass','$useremail','$country','$contact','$registerdate','$rate')");
                    echo '<div class="search_field"><b>تم تسجيل حساب جديد بإسم '.$username.' .. الانتقال الان الى اضافة موقع جديد</b></div>';
                    echo'<meta http-equiv="REFRESH" content="3;url=newsite">';
                    $_SESSION['username'] = $username;

            }

        }

    }

    public function login($username, $userpass)
    {

        $username = security($username);
        $userpass = security(md5($userpass));

        if(empty($_POST) === false)
        {
            if(empty($username) or  empty($userpass))
            {
                echo '<div class="search_field"><b>معلومات الدخول خاطئه</b></div>';
            }else{
                $result = mysql_query("SELECT * FROM users WHERE username='$username' AND userpass='$userpass'");

                while($row = mysql_fetch_assoc($result))
                {
                    @$user = @$row['username'];
                    @$pass = @$row['userpass'];
                }

                if($username == $user and $pass == $userpass)
                {
                    echo '<div class="search_field"><b>تم تسجيل الدخول بنجاح .. الانتقال الى الصفحه الرئيسيه</b></div></ br>';
                    echo'<meta http-equiv="REFRESH" content="3;url=index">';
                    $_SESSION['username'] = $username;
                    $_SESSION['userpass'] = $userpass;

                }else{
                    echo '<div class="search_field"><b>لا يوجد عضو بهذا الاسم الرجاء تأكد من معلومات الدخول</b></div>';
                }
            }
        }
    }

    public function logout($username)
    {
        if(!isset($_SESSION['username']))
        {
            echo '<div class="search_field"><b>لم تقم بتسجيل دخولك</b></div>';
            header("Location: index");
        }else{
            session_destroy();
            echo '<div class="search_field"><b>تم تسجيل خروجك بنجاح</b></div>';
            echo'<meta http-equiv="REFRESH" content="3;url=index">';
        }
    }
} // end of class

?>
Member Avatar for LastMitch

@empror9

This code the link is wrong "signin" it should be "signin.php"

<a href="signin">تسجيل الدخول</a><img border="0" src="http://3rbc.net/adver/images/icons/user.png" width="16" height="16">

Apparently you are using a PHP Mainframe! You never mention this at the beginning?

This file user_class.php it's in OOP !

I haven't learn OOP yet. I learning Smarty on my own.

It seems like you don't know either if you did know then this issue would have been solve already. I think you need to understand how your PHP Mainframe works and how to modify the code on the MainFrame!

Here is a link if you want to know more about it OOP:

http://php.net/manual/en/language.oop5.php

I don't think I can't help you anymore.

thanks LastMitch,

I'm waiting for someone who is expert to help me

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.