minitauros 151 Junior Poster Featured Poster

Are you getting any errors or is the data not being inserted without giving you a notice/warning/error?

minitauros 151 Junior Poster Featured Poster

As both posters above are saying, you can use a header to redirect the user to another page. Example:

if($row["emp_username"] == $uname && $row["emp_password"] == $pwd)
{
    // Set the header that will redirect the user to the given page
    // when this page's PHP script is done loading.
    header('Location: mainpage.php');

    // Maybe we want to save some variables in a session. In that case,
    // example:
    $_SESSION['login'] = array(
        'user_id' => $uid, // Replace by the ID of the user you're logging in.
        'username' => $uname
    );

    // (In order for the session to work, you need to have used session_start();
    // before).

    // There is no need to output this message, as the user is being
    // redirected anyway, but I'll lave it in tact for you ;).
    echo "Welcome $uname";
}
else
{
    echo "Username and Password do not match";
}

More info about session_start() on php.net: click.

Oh, and a thing to get you started on password encryption: click. Note that this tutorial is using the md5() function, of which the use is strongly unadvised (as it is seen as deprecated by almost everyone), but it will give you an idea of what password encryption is.

minitauros 151 Junior Poster Featured Poster

Did you check which process is the one with PID 4?

minitauros 151 Junior Poster Featured Poster

Are you sure nothing else is running on those ports? I usually get this kind of problems when I'm running Skype or League of Legends (which uses Punkbuster, which operates on the same port) while starting Apache.

(Looks like a port problem, check this line: 5:18:22 PM [Apache] Port 443 in use by "Unable to open process" with PID 4!. In Windows 8 (and 7?) you can check which process has PID 4 by pressing CTRL + ALT + DEL, going to "Details" and finding the process with PID 4)

minitauros 151 Junior Poster Featured Poster

Just some stuff that I come across often:

  1. Would save me a second of time and effort if the "Username" field would get auto focused on the login page. I know it's a minor improvement, but I like it ^^. Facebook does it, for example - I like the way I can just start slamming on my keyboard as soon as the site is loaded, without having to click the "email" field.

  2. The header gets a "fixed" position as soon as I scroll down anywhere. I find that useful, but in my opinion, something is missing in the fixed header when I'm reading a long post. That is because I often want to go navigate to a specific forum section from that page out (is this correct English?); using the back button and refreshing that page is more work than clicking on the section I want to navigate to and go there straight away. Why not include those section options in the header that are also there when I scroll inside a section's posts overview? :)

minitauros 151 Junior Poster Featured Poster

You could try

<?php  echo number_format($shipping1 + $row_panier['subtotal'], 2, '.', ''); ?>

instead of

    <?php echo ($shipping1 + number_format($row_panier['subtotal'], 2, '.', '')); ?>

as it makes more sense to number format an int instead of number formatting an int to a string and then adding it to another int (as pritaeas says). Of course, both variables need to be set in order to do a sum. If this doesn't work, you could try checking for the presence of a value for both variables, for example:

<?php
echo '<p>The value of $shipping1 is:<br>';
var_dump($shipping1); echo '</p>';

echo '<p>The value of $row_panier[subtotal] is:<br>';
var_dump($row_panier['subtotal']); echo '</p>';
minitauros 151 Junior Poster Featured Poster

Wasn't working because your "WHERE" got glued right onto the name of your table so it seems :).

minitauros 151 Junior Poster Featured Poster

For as far as I know, when you do something like this:

<?php echo $shipping1+number_format ($row_panier['subtotal'], 2, '.', ''); ?>

it is not just an echo that is taking place; rather the script is parsed one by one and $row_panier['subtotal'] is added to $shipping1. I think this can easily be fixed by containing your echo in parentheses, example:

<?php echo ($shipping1 + number_format($row_panier['subtotal'], 2, '.', '')); ?>
minitauros 151 Junior Poster Featured Poster

Are you getting an error? Multiple errors? What seems to be the problem?

minitauros 151 Junior Poster Featured Poster

This one is working for me though:

<?php
$string = 'HBR_EMP_001';
echo $string; // Outputs HBR_EMP_001
$regex = '/^\w+(\d+)$/';
preg_match($regex, $string, $matches);
$last_used_number = $matches[1];
$new_number = $last_used_number + 1;
$new_string = 'HBR_EMP_' . (str_pad($new_number, 3, 0, STR_PAD_LEFT));
echo $new_string; // Outputs HBR_EMP_002

:o

minitauros 151 Junior Poster Featured Poster

Well I guess you could start by Googling for some Flash tutorials? ;)

minitauros 151 Junior Poster Featured Poster

Oh that is because I seem to have made a typo in the for loop construction. It should be for(var i = 0; i < string_length; i++) instead of for(var i = 0; i <= string_length; i++). Hope this helps :)!

PS: I seem to have also made a small mistake in the other PHP script. It should be $new_number = $last_used_number + 1; instead of $new_number = $last_used_number++;.

minitauros 151 Junior Poster Featured Poster

Well, for starters, HBR_EMP_001 doesn't sound pretty random to me ;). If you want to increase a known number-letter combination by one, you could try this code in PHP (and note that this is just an example, working with the idea that your strings will always look like 'HBR_EMP_(number)'):

<?php
$string = 'HBR_EMP_001';
$regex = '/^\w+(\d+)$/';
preg_match($regex, $string, $matches);
$last_used_number = $matches[1];
$new_number = $last_used_number++;
$new_string = 'HBR_EMP_' . (str_pad($new_number, 3, 0, STR_PAD_LEFT));
minitauros 151 Junior Poster Featured Poster

Well with this code, and only this code, I'm getting a bunch of popups with "123" when I scroll:

$(window).scroll(function()
{
    // Let's check the scrollTop just to be sure stuff is working:
    console.log('ScrollTop: ' + $(this).scrollTop());

    if($(this).scrollTop() > 100)
    {
        alert(123);
    }
    else
    {
        alert(321);
    }
});

Have you checked your Firebug to see if any other errors are occurring that may be halting the execution of your script?

minitauros 151 Junior Poster Featured Poster

What is in $faq['slug']? By the way, why aren't you just using PHP to take care of the redirecting process? :) E.g.: redirect everything to index.php, then use $_SERVER['REQUEST_URI'] to find out what needs to be done.

E.g. www.yoursite.com/products/brand/diesel would redirect to index.php, which would then see that the URI is "products/brand/diesel", which information you could then use to PHP-include the appropriate files.

minitauros 151 Junior Poster Featured Poster

Well, it is working for me here, so then I must have falsely assumed you are working with jQuery. If you are working with jQuery, there must be something else going wrong. Did you check your Firebug for Javascript errors?

If you are NOT using jQuery, changing the randomStringToInput() function to this should work:

function randomStringToInput(clicked_element)
{
    var random_string = generateRandomString(10);
    var element = document.getElementsByName('emp')[0];
    element.value = random_string;
    clicked_element.parentNode.removeChild(clicked_element);
}
minitauros 151 Junior Poster Featured Poster

Hmmm I don't know but it seems kind of useless to me to put all this stuff inside a function that doesn't get executed, or does it when you pass it to jQuery? What about trying just:

$(window).scroll(function() {
    // Let's check the scrollTop just to be sure stuff is working:
    console.log('ScrollTop: ' + $(this).scrollTop());

    if ($(this).scrollTop() > 100) {
        alert(123);
    } else {
        alert(321);
    }
});
minitauros 151 Junior Poster Featured Poster

Also take note that it is not recommended to use the mysql_* functions (see the warning in this article, for example, on PHP's official website).

minitauros 151 Junior Poster Featured Poster

This should work:

<script>
function randomStringToInput(clicked_element)
{
    var self = $(clicked_element);
    var random_string = generateRandomString(10);
    $('input[name=emp]').val(random_string);
    self.remove();
}

function generateRandomString(string_length)
{
    var characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
    var string = '';

    for(var i = 0; i <= string_length; i++)
    {
        var rand = Math.round(Math.random() * (characters.length - 1));
        var character = characters.substr(rand, 1);
        string = string + character;
    }

    return string;
}
</script>

<td><input type="text" name="emp" readonly="readonly" value=""></td>
<td><input type="button" value="Generate Employee Id" onclick="randomStringToInput(this)"></td>

What it does is it uses Javascript to generate a random string of X length, and then sets the value of input[name=emp] to be that random string.

minitauros 151 Junior Poster Featured Poster

Wow it should have even worked without those spaces I think :o. But glad it's working right now!

minitauros 151 Junior Poster Featured Poster

Well, have you assigned $dialingCode to a value? In other words, is there some place in some script that says $dialingCode = $_POST['dialingCode'];? :)

You could check the value of $dialingCode by using var_dump($dialingCode);

minitauros 151 Junior Poster Featured Poster

Well I'm not completely sure but I think you cannot declare variables like that in PHP. First of all I think you need to use public, protected or private instead of var. Secondly, you cannot refer to class variables without using "$this->". Also it is recommended that you set these variables in your __constructor() function. Example:

class myClass {

    private $currentDir;
    private $my_xml_file;

    // Create the class constructor
    public function __construct() {
        $this->currentDir = __DIR__;
        $this->my_xml_file = $currentDir."data/my.xml";
    }
}
minitauros 151 Junior Poster Featured Poster

So CURLINFO_HTTP_CODE and CURLINFO_EFFECTIVE_URL are returning the exact same thing?

minitauros 151 Junior Poster Featured Poster

Yes, except that the regex that the topic starter provided and that Atli modified in his first post will not securely check if the length of the string is really between 8 and 15 characters. Therefore you would still have to add a length check. I myself (but that's just my opinion, of course) find the code in Atli's last post the most elegant, because it is clear there which regex has what function.

minitauros 151 Junior Poster Featured Poster

Would it work if you would just retrieve the links to the files from you DB, then check what file type it is, and then display an icon for that file type instead of a preview of the file? For example for a .doc file you display a Microsoft Word icon with the file name next to it, and then when the user clicks it he is prompted with a "download file" window.

minitauros 151 Junior Poster Featured Poster

@Atli
Woops, I misunderstood, you are totally right. You'd be better off using a loop probably, as you show in your example.

minitauros 151 Junior Poster Featured Poster

That really is one of the weirdest regex setups I've ever seen :p. The following does what you asked for, but in a simpler way:

<?php
$is_valid = true;

// To check for allowed characters:
$regex = '/^[a-z0-9!@?#]+$/i';

if(!preg_match($regex, $password))
    $is_valid = false;

// To check the length:
$string_length = strlen($password);

if($string_length < 8 || $string_length > 15)
    $is_valid = false;

Sha1 is also considered insecure nowadays, you should check out the hash() function of PHP, which allows you to use, for example, SHA512 encryption. Example:

<?php
$password = 'hello';
$hashed = hash('sha512', $password);
minitauros 151 Junior Poster Featured Poster

Have you tried adding or die... to your query line? E.g.:

mysql_query(..query..) or die(mysql_error());

minitauros 151 Junior Poster Featured Poster

What happens if you echo your query string? E.g.

echo "INSERT INTO `sikeres` ($fields) VALUES ($data)";
minitauros 151 Junior Poster Featured Poster

What about executing echo '<br>'; in each loop execution?

minitauros 151 Junior Poster Featured Poster

You create the .htaccess file yourself, in your root directory. Then you use PHP to parse the URL. Example with the .htaccess file I provided:

<?php
$uri = $_SERVER['REQUEST_URI'];
$explode = explode('/', $uri);

// Let's see what's in the uri:
echo '<pre>'; print_r($explode); echo '</pre>';

// Let's say your uri looked like /id/1, then:
$id = $explode[1];
// Because $explode would look like this: array([0] => 'id', [1] => 1)

(Sorry, I mentioned $_SERVER['HTTP_REFERER'] before, but I actually meant $_SERVER['REQUEST_URI']).

minitauros 151 Junior Poster Featured Poster

EDIT: My bad wasn't reading correctly. Let me take another look :p.

What is the error you are getting?

minitauros 151 Junior Poster Featured Poster

What are the contents of install_amt?

minitauros 151 Junior Poster Featured Poster

You could try using these .htaccess lines:

RewriteEngine on

Options -Indexes

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.php [L]

Everything will be redirected to index.php. In index.php you can then use PHP to parse the url and take the required actions. E.g. by using $_SERVER['HTTP_REFERER'] to read the uri.

minitauros 151 Junior Poster Featured Poster

What about a for loop?

<?php
for($i = 0; $i < count($array_1); $i++)
{
    $record_1 = &$array_1[$i]; // The & creates a reference instead of copying the value.
    $record_2 = &$array_2[$i];

    if($record1 == $record_2)
    {
        $record_2 = '000';
    }
}
minitauros 151 Junior Poster Featured Poster

Just curious: When you say you have no idea do you mean you have no idea at all? As in: I don't know PHP nor MySQL?

@Myronz
I think you'll need to start your own topic for such a question :).

minitauros 151 Junior Poster Featured Poster

Haha :). You are right in your second post.

function doSomething($value1, $value2 = 'test')
{
    echo $value1 . $value2;
}

// Will output "hellotest"
doSomething('hello');

// Will output "hellohello"
doSomething('hello', 'hello');

However, keep in mind that it is RECOMMENDED to place predefined parameters at the end of your function. I believe you will get a notice in PHP strict if you don't. E.g.:

Don't: function doSomething($value1 = 'abc', $value2, $value3)
Do: function doSomething($value1, $value2, $value3 = 'abc')

mmcdonald commented: Helpful information :D Thank you! +3
minitauros 151 Junior Poster Featured Poster

Do you know any PHP at all? Do you maybehave a start on this? What's the situation? :)

minitauros 151 Junior Poster Featured Poster

I must say I find it prettier if HTML uses the double quotes instead of PHP. E.g. echo '<a href="link">'; instead of echo "<a href='link'>";. But I don't think that's a must.

Your line 11 contains a small error: <imgsrc=.... I would place a space in between the "img" and "src" parts ;).

For the rest, I think that a <button> element in a form acts as a submit button if it's the only button in it. I'm not sure though. I think you could add this line of code to your button: onclick="this.parentNode.submit()" or something like that (not sure if this will work, but hopefully you get the point: use Javascript :)).

minitauros 151 Junior Poster Featured Poster

Well I guess you could try and find out what is happening and why, right? :) I mean if the if() on line 8 is being triggered, that means that $part is not "jocuri" there. So what is it then and should it get added? Are you sure you are using the right setup? Because this line:

if($part==$_SESSION['Username']) {

comes after this line:

else if ($part!='jocuri') {

But what happens if $_SESSION['username'] is not 'jocuri'? It would still trigger the if() statement on line 8 instead of the next.

minitauros 151 Junior Poster Featured Poster

Which of your if() statements is triggered and why?

minitauros 151 Junior Poster Featured Poster

You're welcome! :) Glad to hear that your problem has been solved.

minitauros 151 Junior Poster Featured Poster

Well, you must make sure that your AJAX function is actually sending data to your process_facebook.php page as well. In your example, you are sending the value of your Javascript variable named "myData", which is:

var myData = 'connect=1';

That means that the data you are sending, through either POST or GET (GET in your last example), is only "connect=1". If you want to also send the value of $_GET['erro'], you need to make sure that Javascript receives that value and passes it on to the page that is requested.

minitauros 151 Junior Poster Featured Poster

Well it could be that you're starting a whole new session then. You can check if the session ID is still the same on the page that sends the email. To do so, you can use session_id().

E.g. on both pages put the following at the start of the file:

session_start(); 
$session_id = session_id(); 
echo '<p>Session ID is now: ' . $session_id . '</p>';

The compare both session ID's :).

minitauros 151 Junior Poster Featured Poster

Have you ever heard of Apache's mod_rewrite and of $_SERVER['HTTP_REFERER']? :) That's the golden combo that is usally used to achieve what I think you want to achieve.

Do you have any code yet? Can you be a bit more specific about what your starting point is?

minitauros 151 Junior Poster Featured Poster

Well that is kinda impossible :o. If on page a.php you define your session variables, and if you can verify that they have indeed been set, then they MUST still exist on page b.php, if you haven't unset them in the meanwhile.

In other words, this should work:

a.php:

<?php
session_start();
$_SESSION['test'] = 'TESTER';
?>

<form action="b.php" method="post">
    <input type="text" name="hello" value="Type something">
    <input type="submit">
</form>

b.php:

<?php
session_start();
echo '<p>The value of my session variable is now: ' . $_SESSION['tester'] . '</p>';
echo '<p>Just for extra checking, the $_POST and $_SESSION variables are as follows:</p><pre>';
print_r($_POST); print_r($_SESSION);
echo '</pre>';

Are you sure the variables aren't getting unset somewhere?

minitauros 151 Junior Poster Featured Poster

What happens if on both pages you start with this line? Do you get the same output on both pages?

session_start(); echo '<pre>'; print_r($_SESSION); echo '</pre>';

minitauros 151 Junior Poster Featured Poster

shell_exec() states that

Execute command via shell and return the complete output as a string

That means that the output should be returned as a string. Are you sure the program you are executing isn't printing anything to the screen? Note sure if that's even possible, I don't use this function very often. Just trying to help ^^. Maybe you can use something like $result = shell_exec(...);?

minitauros 151 Junior Poster Featured Poster

Seems like you forgot a session_start(); in the script that sends the email? ;)

By the way, you don't have to use session_register(), you can just type $_SESSION['key'] = 'value'; without registering it first. The session_register() function has even been removed from PHP 5.4.

minitauros 151 Junior Poster Featured Poster

Are you asking how you can scroll little by little instead of a complete section at a time? Or the opposite?